-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.nix
73 lines (70 loc) · 2.15 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
{ nixpkgs, home-manager }@inputs:
let
lib = inputs.nixpkgs.lib;
mkSystem = {
host
, system
, globalConfig ? {}
, type ? "unknown"
, home-manager ? true
, users ? []
, rootPath ? ./.
, hostsPath ? "${rootPath}/hosts"
, modules ? []
, nixpkgs ? {}
, overlays ? []
, mkOverlays ? _: [], ... }@args: (lib.makeOverridable lib.nixosSystem) (
let
specialArgs = {
inherit
host globalConfig type home-manager users
hostsPath modules nixpkgs overlays mkOverlays;
isHomeManager = false;
};
in {
inherit specialArgs;
modules = modules ++ [
"${rootPath}/device"
"${rootPath}/services"
"${rootPath}/specialized"
"${rootPath}/users"
"${hostsPath}/${host}/configuration.nix"
({ options, ...}: {
networking.hostName = host;
nix.registry.nixpkgs.flake = inputs.nixpkgs;
nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
nixpkgs = lib.attrsets.recursiveUpdate {
overlays = mkOverlays { inherit nixpkgs system overlays; };
} args.nixpkgs;
customUsers =
let
optUsers = builtins.attrNames (removeAttrs options.customUsers [ "extra" ]);
cfgUsers = builtins.filter (x: builtins.elem x optUsers) users;
extra = builtins.filter (x: !(builtins.elem x optUsers)) users;
in
lib.mkIf (users != []) (
lib.mkMerge (
(map (x: { ${x}.enable = true; }) cfgUsers) ++ [ { extra = extra; } ]
)
);
})
] ++ lib.lists.optionals home-manager [
inputs.home-manager.nixosModules.home-manager
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = [
"${rootPath}/device"
"${rootPath}/hm-modules"
"${hostsPath}/${host}/device.nix"
];
extraSpecialArgs = specialArgs // { isHomeManager = true; };
};
}
];
} // removeAttrs args (builtins.attrNames specialArgs));
in
lib // {
inherit mkSystem;
}