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 0f1cee70e1
commit ae130a47dc
5 changed files with 87 additions and 40 deletions

View file

@ -18,12 +18,16 @@ let
};
nixpkgs' = import ./meta/nixpkgs.nix;
# All supported nixpkgs versions, instanciated
nixpkgs = nix-lib.mapSingleFuse mkNixpkgs nixpkgs'.supported;
nixpkgs = nix-lib.mapSingleFuse (
s: nix-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' =
@ -33,43 +37,56 @@ let
name = "nixos-${v}";
};
# 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 = nixpkgs.${version node}.lib // {
extra = nix-lib;
};
mkArgs =
node:
let
pkgs = nixpkgs.${system node};
in
rec {
lib = import sources.nix-lib {
inherit (pkgs.${version node}) lib;
meta = (import ./meta) lib;
nixpkgs = pkgs;
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;
} // {
extra = nix-lib;
};
}
);
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; };
};
};

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,11 +1,24 @@
{
# Default version of nixpkgs to use
default = "24.05";
versions = {
# Default version of nixpkgs to use
default = "24.05";
# Supported nixpkgs versions
supported = [
"unstable"
"23.11"
"24.05"
];
# Supported nixpkgs versions
supported = [
"unstable"
"23.11"
"24.05"
];
};
systems = {
# Default target system
default = "nixos";
# Supported target systems
supported = [
"nixos"
"zyxel-nwa50ax"
];
};
}

View file

@ -136,4 +136,11 @@
nixpkgs = "unstable";
vm-cluster = "Hyperviseur NPS";
};
# 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
{
@ -138,8 +140,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.
'';
@ -188,6 +190,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 = {