From a9cc40d2e1a36796faddae358836b515814a6a84 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 3 Apr 2024 21:21:04 +0200 Subject: [PATCH] feat(infra): Rework nixpkgs version management --- hive.nix | 32 +++++++++++++++++--------- machines/compute01/kanidm/default.nix | 4 ++-- machines/storage01/forgejo-runners.nix | 4 ++-- machines/web01/netbox.nix | 4 ++-- meta/nixpkgs.nix | 12 ++++++++-- meta/options.nix | 2 +- modules/dgn-netbox-agent/default.nix | 1 - 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/hive.nix b/hive.nix index e778504..84bd7b4 100644 --- a/hive.nix +++ b/hive.nix @@ -16,23 +16,34 @@ let ]; }; - mkPatchedNixpkgs = - version: + nixpkgs' = import ./meta/nixpkgs.nix; + # All supported nixpkgs versions, instanciated + nixpkgs = lib.mapSingleFuse mkNixpkgs nixpkgs'.supported; + + # Get the configured nixos version for the node, + # defaulting to the one defined in meta/nixpkgs + version = node: nodes'.${node}.nixpkgs or nixpkgs'.default; + + # Builds a patched version of nixpkgs, only as the source + mkNixpkgs' = + v: + let + version = "nixos-${v}"; + in patch.mkNixpkgsSrc { src = sources.${version}; inherit version; }; - mkNixpkgs = version: import (mkPatchedNixpkgs version) { }; - - mkNixpkgsVersion = node: "nixos-${nodes'.${node}.nixpkgs or (import ./meta/nixpkgs.nix)}"; + # Instanciates the required nixpkgs version + mkNixpkgs = version: import (mkNixpkgs' version) { }; ### # Function to create arguments based on the node # mkArgs = node: rec { lib = import sources.nix-lib { - inherit (mkNixpkgs (mkNixpkgsVersion node)) lib; + inherit (nixpkgs.${version node}) lib; keysRoot = ./keys; }; @@ -40,14 +51,13 @@ let meta = (import ./meta) lib; }; in -# nodes = builtins.attrNames metadata.nodes; + { meta = { - nodeNixpkgs = lib.mapSingleFuse (n: mkNixpkgs (mkNixpkgsVersion n)) nodes; + nodeNixpkgs = lib.mapSingleFuse (n: nixpkgs.${version n}) nodes; specialArgs = { - inherit sources; - inherit mkNixpkgs; + inherit nixpkgs sources; }; nodeSpecialArgs = lib.mapSingleFuse mkArgs nodes; @@ -66,7 +76,7 @@ in inherit (meta.nodes.${name}) deployment; # Set NIX_PATH to the patched version of nixpkgs - nix.nixPath = [ "nixpkgs=${mkPatchedNixpkgs (mkNixpkgsVersion name)}" ]; + nix.nixPath = [ "nixpkgs=${mkNixpkgs' (version name)}" ]; nix.optimise.automatic = true; # Allow unfree packages diff --git a/machines/compute01/kanidm/default.nix b/machines/compute01/kanidm/default.nix index d66c06f..162345f 100644 --- a/machines/compute01/kanidm/default.nix +++ b/machines/compute01/kanidm/default.nix @@ -1,4 +1,4 @@ -{ config, sources, ... }: +{ config, nixpkgs, ... }: let domain = "sso.dgnum.eu"; @@ -18,7 +18,7 @@ in services.kanidm = { enableServer = true; - package = (import sources.nixos-unstable { }).kanidm; + package = nixpkgs.unstable.kanidm; serverSettings = { inherit domain; diff --git a/machines/storage01/forgejo-runners.nix b/machines/storage01/forgejo-runners.nix index b2e017f..a04772d 100644 --- a/machines/storage01/forgejo-runners.nix +++ b/machines/storage01/forgejo-runners.nix @@ -1,7 +1,7 @@ { config, pkgs, - sources, + nixpkgs, ... }: @@ -43,7 +43,7 @@ in pkgs.colmena pkgs.npins pkgs.tea - (import sources.nixpkgs { }).nixfmt-rfc-style + nixpkgs.unstable.nixfmt-rfc-style ]; containerOptions = [ "--cpus=4" ]; diff --git a/machines/web01/netbox.nix b/machines/web01/netbox.nix index 971661d..6d8bb82 100644 --- a/machines/web01/netbox.nix +++ b/machines/web01/netbox.nix @@ -1,7 +1,7 @@ { config, lib, - mkNixpkgs, + nixpkgs, ... }: @@ -13,7 +13,7 @@ in services = { netbox = { enable = true; - package = (mkNixpkgs "nixos-unstable").netbox_3_7; + package = nixpkgs.unstable.netbox_3_7; secretKeyFile = "/dev/null"; listenAddress = "127.0.0.1"; plugins = p: [ p.netbox-qrcode ]; diff --git a/meta/nixpkgs.nix b/meta/nixpkgs.nix index 9e641df..b8c6b43 100644 --- a/meta/nixpkgs.nix +++ b/meta/nixpkgs.nix @@ -1,2 +1,10 @@ -# Default version of nixpkgs to use -"23.11" +{ + # Default version of nixpkgs to use + default = "23.11"; + + # Supported nixpkgs versions + supported = [ + "unstable" + "23.11" + ]; +} diff --git a/meta/options.nix b/meta/options.nix index 9a8f843..1b722d6 100644 --- a/meta/options.nix +++ b/meta/options.nix @@ -89,7 +89,7 @@ in nixpkgs = mkOption { type = str; - default = import ./nixpkgs.nix; + inherit (import ./nixpkgs.nix) default; description = '' Version of nixpkgs to use. ''; diff --git a/modules/dgn-netbox-agent/default.nix b/modules/dgn-netbox-agent/default.nix index d0fefdb..93c6ea3 100644 --- a/modules/dgn-netbox-agent/default.nix +++ b/modules/dgn-netbox-agent/default.nix @@ -6,7 +6,6 @@ ... }: let - inherit (config.deployment) tags; inherit (config.networking) hostName domain; in {