-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.nix
73 lines (72 loc) · 2.04 KB
/
lib.nix
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
lib: rec {
parseAllFiles = folder:
lib.mapAttrs' (fileName: _: let
parsed = import (folder + "/${fileName}");
in {
name = builtins.head (lib.splitString "." fileName);
value = parsed;
})
(builtins.readDir
folder);
getRoles = folder:
lib.mapAttrs' (
nodeName: nodeType: let
c =
if nodeType == "regular"
then builtins.map (x: x) [(folder + "/${nodeName}")]
else builtins.map (name: (folder + "/${nodeName}/${name}")) (builtins.attrNames (builtins.readDir "${folder}/${nodeName}"));
in {
name = builtins.head (lib.splitString "." nodeName);
value = c;
}
) (builtins.readDir folder);
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
roleActive = role: selected: builtins.all (r: builtins.elem r selected) (lib.splitString "+" role);
filterRoles = availableRoles: roles:
lib.attrsets.filterAttrs (
name: _: roleActive name roles
)
availableRoles;
mkmkSystem = {
baseMods,
specialArgs,
availableRoles,
}: {
name,
description,
target,
edition,
roles,
extraModules,
includeBaseMods,
pkgs,
}:
lib.nixosSystem {
inherit pkgs;
system = target;
specialArgs = {inherit edition target;} // specialArgs;
modules =
[
specialArgs.inputs.hm.nixosModules.default
specialArgs.inputs.nix-index-db.nixosModules.nix-index
{
networking.hostName = name;
environment.variables."HOSTNAME" = name;
environment.etc."flake-src".source = specialArgs.inputs.self;
home-manager.extraSpecialArgs = specialArgs;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
system.stateVersion = edition;
}
]
++ (
if includeBaseMods
then baseMods
else []
)
++ lib.flatten (builtins.attrValues (
filterRoles availableRoles roles
))
++ extraModules;
};
}