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;
# 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,15 +39,40 @@ 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 {
mkArgs =
node:
let
pkgs = nixpkgs.${system node};
in
rec {
lib = import sources.nix-lib {
inherit (nixpkgs.${version node}) lib;
inherit (pkgs.${version node}) lib;
nixpkgs = pkgs;
keysRoot = ./keys;
};
@ -52,38 +81,20 @@ let
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.
];
};
}
);
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;

View file

@ -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

View file

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

View file

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

View file

@ -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 = {