-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix-roleplay.nix
100 lines (91 loc) · 2.81 KB
/
nix-roleplay.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{
self,
src ? ./.,
nix-roleplay-dir ? "nix-rp",
nixOptions ? [],
default_role ? {
func_mods = [
# personal_module
(name: import (src + "/${nix-roleplay-dir}/machines/${name}/nixos/module-list.nix"))
# nixinate_module
(name: [
{
_module.args.nixinate = {
host = "${name}-root";
sshUser = "root";
buildOn = "local";
substituteOnTarget = false;
hermetic = false;
nixOptions = nixOptions;
};
}
])
];
}
}:
rec {
# default role is always included but overwriteable
inherit default_role;
nixpkgs = self.inputs.nixpkgs;
modules = import (src + "/${nix-roleplay-dir}/modules/modules.nix") {
inherit self;
};
roles = import (src + "/${nix-roleplay-dir}/roles.nix") {
inherit self;
inherit modules;
inherit mod_categories;
};
machines = import (src + "/${nix-roleplay-dir}/machines/machines.nix") {
inherit self;
inherit modules;
inherit roles;
};
mod_categories = import (src + "/${nix-roleplay-dir}/mod-categories.nix") {
inherit modules;
};
nixosConfigurations = (func.create_nixos_configurations machines);
func = {
create_nixos_configurations = machines: let
translate_configuration = prevNixConf: curNixConf @ {name, roles ? {}, ... }: let
mergedAttrs = ((curNixConf.roles or {}) // curNixConf);
merged_flattened_modules = ((curNixConf.roles.func_mods or [])
++ (merge_modules_in_baseRoles curNixConf)
### always included
++ (default_role.func_mods));
merge_modules_in_baseRoles = args @ { roles ? {}, ... }: (if (builtins.hasAttr "mod_categories" (args.roles or {})) then
builtins.foldl'
(old: new:
(new.func_mods) ++ old
)
[]
(args.roles.mod_categories)
else
[]);
in
{
"${curNixConf.name}" = nixpkgs.lib.nixosSystem { # replace * after '=' with '{' for debugging
system = mergedAttrs.system;
specialArgs = mergedAttrs.specialArgs;
pkgs = mergedAttrs.pkgs;
modules = nixpkgs.lib.lists.unique
((nixpkgs.lib.lists.flatten (curNixConf.extra_modules or []))
++ (apply_name_to_modules {
name = curNixConf.name;
modules = merged_flattened_modules;
}));
};
} // prevNixConf;
apply_name_to_modules = (args @ { name, modules, ... }: builtins.foldl'
(a: b: let
result = (if (builtins.typeOf b) == "lambda" then
(b args.name)
else
b);
in
result ++ a)
[]
args.modules);
in
builtins.foldl' translate_configuration {} machines;
};
}