1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
lib ? import "${(import ../npins).nixpkgs}/lib",
npins ? import ../npins,
...
}:
(
let
# read the current directorys files and pipe the result through a list of functions
machines = builtins.listToAttrs (
lib.pipe (builtins.readDir ./.) [
# convert to a list containing just the attribute names
(builtins.attrNames)
# drop "default.nix" from the list
(builtins.filter (name: name != "default.nix"))
# convert each list-element containing its file-name to an element containing the file's content
(builtins.map (name: {
# remove '.nix' suffix
name = lib.removeSuffix ".nix" name;
value = import ./${name};
}))
]
);
nixosModules = import ../nixosModules { inherit lib; };
overlays = import ../overlays { inherit npins; };
specialArgs = {
inherit npins machines nixosConfigurations;
resources = import ../resources { inherit npins lib; };
sopsSecrets = import ../secrets { inherit npins lib; };
};
nixosConfigurations = lib.flip builtins.mapAttrs machines (
machineName: machineConfig:
let
nixpkgs = if !machineConfig.nixpkgsStable then npins.nixpkgsUnstable else npins.nixpkgs;
in
import "${nixpkgs}/nixos/lib/eval-config.nix" {
system = machineConfig.system;
specialArgs = specialArgs // {
machineConfig = machineConfig // {
inherit machineName;
};
};
modules = lib.flatten [
{ nixpkgs.overlays = overlays.default; }
nixosModules.default
machineConfig.nixosConfiguration
];
}
);
in
nixosConfigurations
)