From 0a948e6148f9add3dfefb288752c9daf870648e9 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 13 May 2024 17:04:49 +0200 Subject: [PATCH] feat: Specialize nixpkgs as a function of the system --- hive.nix | 77 ++++++++++++++++++++--------------- machines/ap/configuration.nix | 6 +-- meta/nixpkgs.nix | 27 ++++++++---- meta/nodes.nix | 7 ++++ meta/options.nix | 14 ++++++- 5 files changed, 86 insertions(+), 45 deletions(-) diff --git a/hive.nix b/hive.nix index 85968cd..70f10d1 100644 --- a/hive.nix +++ b/hive.nix @@ -17,12 +17,16 @@ let }; nixpkgs' = import ./meta/nixpkgs.nix; + # All supported nixpkgs versions, instanciated - nixpkgs = lib.mapSingleFuse mkNixpkgs nixpkgs'.supported; + nixpkgs = lib.mapSingleFuse ( + s: lib.mapSingleFuse (mkSystemNixpkgs s) nixpkgs'.versions.supported + ) nixpkgs'.systems.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; + version = node: nodes'.${node}.nixpkgs or nixpkgs'.versions.default; + system = node: nodes'.${node}.system or nixpkgs'.systems.default; # Builds a patched version of nixpkgs, only as the source mkNixpkgs' = @@ -35,55 +39,62 @@ let inherit version; }; - # Instanciates the required nixpkgs version - mkNixpkgs = version: import (mkNixpkgs' version) { }; + # Instanciate a specialized version of nixpkgs + mkSystemNixpkgs = + system: version: + let + args = + if system == "nixos" then + { } + else + (import "${sources.liminix}/devices/${system}").system + // { + overlays = [ (import "${sources.liminix}/overlay.nix") ]; + config = { + allowUnsupportedSystem = true; # mipsel + permittedInsecurePackages = [ + "python-2.7.18.8" # Python < 3 is needed for kernel backports. + ]; + }; + }; + in + import (mkNixpkgs' version) args; ### # Function to create arguments based on the node # - mkArgs = node: rec { - lib = import sources.nix-lib { - inherit (nixpkgs.${version node}) lib; + mkArgs = + node: + let + pkgs = nixpkgs.${system node}; + in + rec { + lib = import sources.nix-lib { + inherit (pkgs.${version node}) lib; - keysRoot = ./keys; - }; + nixpkgs = pkgs; - meta = (import ./meta) lib; - - nodeMeta = meta.nodes.${node}; - }; - - apDevice = import "${sources.liminix}/devices/zyxel-nwa50ax"; - apOverlay = import "${sources.liminix}/overlay.nix"; - - apNixpkgs = import (mkNixpkgs' "unstable") ( - apDevice.system - // { - overlays = [ apOverlay ]; - config = { - allowUnsupportedSystem = true; # mipsel - permittedInsecurePackages = [ - "python-2.7.18.8" # Python < 3 is needed for kernel backports. - ]; + keysRoot = ./keys; }; - } - ); + + meta = (import ./meta) lib; + + nodeMeta = meta.nodes.${node}; + }; in { registry = { liminix = { - evalConfig = import "${sources.liminix}/lib/eval-config.nix" { inherit (sources) nixpkgs; }; + evalConfig = import "${sources.liminix}/lib/eval-config.nix" { nixpkgs = sources.nixos-unstable; }; }; }; meta = { - nodeNixpkgs = lib.mapSingleFuse (n: nixpkgs.${version n}) nodes // { - ap01 = apNixpkgs; - }; + nodeNixpkgs = lib.mapSingleFuse (n: nixpkgs.${system n}.${version n}) nodes; specialArgs = { - inherit nixpkgs sources; + inherit sources; }; nodeSpecialArgs = lib.mapSingleFuse mkArgs nodes; diff --git a/machines/ap/configuration.nix b/machines/ap/configuration.nix index a98a93c..716256d 100644 --- a/machines/ap/configuration.nix +++ b/machines/ap/configuration.nix @@ -127,9 +127,9 @@ rec { # wlan0 is the 2.4GHz interface. services.hostap-1 = mkWifiSta baseParams config.hardware.networkInterfaces.wlan0 secrets-1; # wlan1 is the 5GHz interface, e.g. AX capable. - services.hostap-2 = - mkWifiSta (baseParams // modernParams) config.hardware.networkInterfaces.wlan1 - secrets-2; + services.hostap-2 = mkWifiSta ( + baseParams // modernParams + ) config.hardware.networkInterfaces.wlan1 secrets-2; defaultProfile.packages = with pkgs; [ zyxel-bootconfig diff --git a/meta/nixpkgs.nix b/meta/nixpkgs.nix index b8c6b43..106f46c 100644 --- a/meta/nixpkgs.nix +++ b/meta/nixpkgs.nix @@ -1,10 +1,23 @@ { - # Default version of nixpkgs to use - default = "23.11"; + versions = { + # Default version of nixpkgs to use + default = "23.11"; - # Supported nixpkgs versions - supported = [ - "unstable" - "23.11" - ]; + # Supported nixpkgs versions + supported = [ + "unstable" + "23.11" + ]; + }; + + systems = { + # Default target system + default = "nixos"; + + # Supported target systems + supported = [ + "nixos" + "zyxel-nwa50ax" + ]; + }; } diff --git a/meta/nodes.nix b/meta/nodes.nix index ba634f6..2773af3 100644 --- a/meta/nodes.nix +++ b/meta/nodes.nix @@ -86,4 +86,11 @@ stateVersion = "23.11"; vm-cluster = "Hyperviseur Luj"; }; + + # Access points definition + ap01 = { + site = "unknown"; + + system = "zyxel-nwa50ax"; + }; } diff --git a/meta/options.nix b/meta/options.nix index 7bae727..0cc6e9f 100644 --- a/meta/options.nix +++ b/meta/options.nix @@ -11,6 +11,7 @@ let inherit (lib.types) attrs attrsOf + enum ints listOf nullOr @@ -35,6 +36,7 @@ let }; org = config.organization; + nixpkgs = import ./nixpkgs.nix; in { @@ -124,8 +126,8 @@ in }; nixpkgs = mkOption { - type = str; - inherit (import ./nixpkgs.nix) default; + type = enum nixpkgs.versions.supported; + inherit (nixpkgs.versions) default; description = '' Version of nixpkgs to use. ''; @@ -167,6 +169,14 @@ in default = null; description = "VM cluster where the VM is located"; }; + + system = mkOption { + type = enum nixpkgs.systems.supported; + inherit (nixpkgs.systems) default; + description = '' + Type of system for the node, will impact how it is evaluated and deployed. + ''; + }; }; config = {