Compare commits

..

2 commits

3 changed files with 82 additions and 60 deletions

View file

@ -10,58 +10,36 @@
{ ... }@inputs: { ... }@inputs:
{ host, ... }@imports: { host, ... }@imports:
let let
pre-switch-check = host' =
{ pkgs, lib, config, ... }: name: snippets:
{ let
config.system.preSwitchChecks.nvd = ''
nvd_check=y
if [[ -d /run/current-system ]]
then
${lib.getExe pkgs.nvd} --nix-bin-dir ${config.nix.package}/bin diff /run/current-system "''${1}"
if [[ -t 0 ]]; then
printf 'really %s to %s? [y]es/[N]o ' "''${2}" "''${1}"
read -r nvd_check
fi
fi
[[ "''${nvd_check}" == y ]]
'';
};
system = system =
hostname:
{ {
namespace ? "fbs42", namespace ? "fbs42",
nixpkgs ? "nixpkgs", nixpkgs ? "nixpkgs",
classes ? [ hostname ],
}: }:
inputs.${nixpkgs}.lib.nixosSystem { inputs.${nixpkgs}.lib.nixosSystem {
specialArgs = { inherit inputs flake namespace; }; specialArgs = { inherit inputs flake namespace; };
modules = modules =
builtins.concatLists ( builtins.concatLists (
map ( map (
base: builtins.attrValues (flake.lib.scan { base = "${base}/host/${hostname}"; }) base: builtins.attrValues (flake.lib.scan { base = "${base}/host/${name}"; })
) flake.lib.schema.base ) flake.lib.schema.base
) )
++ map (class: { ++ [ { config.networking.hostName = name; } ]
imports = map (input: input.${namespace}.${class} or { }) (builtins.attrValues inputs);
}) classes
++ [ pre-switch-check ]
++ [ { config.networking.hostName = hostname; } ]
++ [ nixosModules.default ] ++ [ nixosModules.default ]
++ inputs.${nixpkgs}.lib.optional (inputs ? home-manager) { ++ [ inputs.home-manager.nixosModules.default ]
imports = [ inputs.home-manager.nixosModules.default ]; ++ [ { config.home-manager.sharedModules = [ hmModules.default ]; } ]
config.home-manager = { ++ [ { config.home-manager.extraSpecialArgs = { inherit flake namespace; }; } ]
sharedModules = [ hmModules.default ];
extraSpecialArgs = { inherit flake namespace; };
};
}
++ builtins.attrValues nixosUsers ++ builtins.attrValues nixosUsers
++ builtins.attrValues nixosGroups; ++ builtins.attrValues nixosGroups;
}; };
cfg =
assert builtins.length snippets == 1;
builtins.head snippets;
in
system cfg;
in in
builtins.mapAttrs ( builtins.mapAttrs host' host
name: value:
assert builtins.length value == 1;
system name (builtins.head value)
) host

50
flake.lock generated
View file

@ -1,23 +1,61 @@
{ {
"nodes": { "nodes": {
"nixpkgs": { "hardware": {
"locked": { "locked": {
"lastModified": 1763966396, "lastModified": 1753122741,
"narHash": "sha256-6eeL1YPcY1MV3DDStIDIdy/zZCDKgHdkCmsrLJFiZf0=", "narHash": "sha256-nFxE8lk9JvGelxClCmwuJYftbHqwnc01dRN4DVLUroM=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixos-hardware",
"rev": "5ae3b07d8d6527c42f17c876e404993199144b6a", "rev": "cc66fddc6cb04ab479a1bb062f4d4da27c936a22",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "nixos",
"ref": "nixos-unstable", "repo": "nixos-hardware",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1757808926,
"narHash": "sha256-K6PEI5PYY94TVMH0mX3MbZNYFme7oNRKml/85BpRRAo=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "f21d9167782c086a33ad53e2311854a8f13c281e",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "release-25.05",
"repo": "home-manager",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1757810152,
"narHash": "sha256-Vp9K5ol6h0J90jG7Rm4RWZsCB3x7v5VPx588TQ1dkfs=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "9a094440e02a699be5c57453a092a8baf569bdad",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-25.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"hardware": "hardware",
"home-manager": "home-manager",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View file

@ -1,6 +1,12 @@
{ {
# only used for nixfmt-tree inputs = {
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
hardware.url = "github:nixos/nixos-hardware";
home-manager = {
url = "github:nix-community/home-manager/release-25.05";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, ... }@inputs: import ./lib/flake.nix inputs ./.; outputs = { self, ... }@inputs: import ./lib/flake.nix inputs ./.;
} }