feat: Specialize nixpkgs as a function of the system

This commit is contained in:
Tom Hubrecht 2024-05-13 17:04:49 +02:00 committed by Ryan Lahfa
parent 41ca207b41
commit 0a948e6148
5 changed files with 86 additions and 45 deletions

View file

@ -17,12 +17,16 @@ let
}; };
nixpkgs' = import ./meta/nixpkgs.nix; nixpkgs' = import ./meta/nixpkgs.nix;
# All supported nixpkgs versions, instanciated # 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, # Get the configured nixos version for the node,
# defaulting to the one defined in meta/nixpkgs # 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 # Builds a patched version of nixpkgs, only as the source
mkNixpkgs' = mkNixpkgs' =
@ -35,55 +39,62 @@ let
inherit version; inherit version;
}; };
# Instanciates the required nixpkgs version # Instanciate a specialized version of nixpkgs
mkNixpkgs = version: import (mkNixpkgs' version) { }; 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 # Function to create arguments based on the node
# #
mkArgs = node: rec { mkArgs =
lib = import sources.nix-lib { node:
inherit (nixpkgs.${version node}) lib; 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; keysRoot = ./keys;
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.
];
}; };
}
); meta = (import ./meta) lib;
nodeMeta = meta.nodes.${node};
};
in in
{ {
registry = { registry = {
liminix = { 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 = { meta = {
nodeNixpkgs = lib.mapSingleFuse (n: nixpkgs.${version n}) nodes // { nodeNixpkgs = lib.mapSingleFuse (n: nixpkgs.${system n}.${version n}) nodes;
ap01 = apNixpkgs;
};
specialArgs = { specialArgs = {
inherit nixpkgs sources; inherit sources;
}; };
nodeSpecialArgs = lib.mapSingleFuse mkArgs nodes; nodeSpecialArgs = lib.mapSingleFuse mkArgs nodes;

View file

@ -127,9 +127,9 @@ rec {
# wlan0 is the 2.4GHz interface. # wlan0 is the 2.4GHz interface.
services.hostap-1 = mkWifiSta baseParams config.hardware.networkInterfaces.wlan0 secrets-1; services.hostap-1 = mkWifiSta baseParams config.hardware.networkInterfaces.wlan0 secrets-1;
# wlan1 is the 5GHz interface, e.g. AX capable. # wlan1 is the 5GHz interface, e.g. AX capable.
services.hostap-2 = services.hostap-2 = mkWifiSta (
mkWifiSta (baseParams // modernParams) config.hardware.networkInterfaces.wlan1 baseParams // modernParams
secrets-2; ) config.hardware.networkInterfaces.wlan1 secrets-2;
defaultProfile.packages = with pkgs; [ defaultProfile.packages = with pkgs; [
zyxel-bootconfig zyxel-bootconfig

View file

@ -1,10 +1,23 @@
{ {
# Default version of nixpkgs to use versions = {
default = "23.11"; # Default version of nixpkgs to use
default = "23.11";
# Supported nixpkgs versions # Supported nixpkgs versions
supported = [ supported = [
"unstable" "unstable"
"23.11" "23.11"
]; ];
};
systems = {
# Default target system
default = "nixos";
# Supported target systems
supported = [
"nixos"
"zyxel-nwa50ax"
];
};
} }

View file

@ -86,4 +86,11 @@
stateVersion = "23.11"; stateVersion = "23.11";
vm-cluster = "Hyperviseur Luj"; vm-cluster = "Hyperviseur Luj";
}; };
# Access points definition
ap01 = {
site = "unknown";
system = "zyxel-nwa50ax";
};
} }

View file

@ -11,6 +11,7 @@ let
inherit (lib.types) inherit (lib.types)
attrs attrs
attrsOf attrsOf
enum
ints ints
listOf listOf
nullOr nullOr
@ -35,6 +36,7 @@ let
}; };
org = config.organization; org = config.organization;
nixpkgs = import ./nixpkgs.nix;
in in
{ {
@ -124,8 +126,8 @@ in
}; };
nixpkgs = mkOption { nixpkgs = mkOption {
type = str; type = enum nixpkgs.versions.supported;
inherit (import ./nixpkgs.nix) default; inherit (nixpkgs.versions) default;
description = '' description = ''
Version of nixpkgs to use. Version of nixpkgs to use.
''; '';
@ -167,6 +169,14 @@ in
default = null; default = null;
description = "VM cluster where the VM is located"; 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 = { config = {