-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake-module.nix
116 lines (112 loc) · 3.17 KB
/
flake-module.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{
self,
inputs,
lib,
config,
...
}:
let
inherit (builtins) attrValues pathExists;
inherit (lib)
filter
last
mapAttrs
mkOption
splitString
types
;
getDefaultPlatform =
system: if (last (splitString "-" system)) == "linux" then "nixos" else "darwin";
systemConfigurations =
platform: hostname: attrs:
if platform == "nixos" then
{ nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem attrs; }
else if platform == "darwin" then
{ darwinConfigurations."${hostname}" = inputs.darwin.lib.darwinSystem attrs; }
else
{ nixOnDroidConfigurations.default = inputs.nix-on-droid.lib.nixOnDroidConfiguration attrs; };
maybePath = path: if pathExists path then path else null;
in
{
options.hosts = mkOption {
default = { };
type = types.attrsOf (
types.submodule (
{ name, ... }:
{
options = {
system = mkOption {
default = "x86_64-linux";
type = types.str;
};
platform = mkOption {
default = getDefaultPlatform config.hosts.${name}.system;
type = types.str;
};
modules = mkOption {
default = [ ];
type = types.listOf types.path;
};
username = mkOption {
default = "natsukium";
type = types.str;
};
specialArgs = mkOption {
default = { };
type = types.attrs;
};
};
}
)
);
};
config = rec {
flake = lib.foldAttrs (host: acc: host // acc) { } (
attrValues (
mapAttrs (
name: cfg:
systemConfigurations cfg.platform name (
{
modules =
filter (x: x != null) [
(maybePath ./systems/${cfg.platform}/${name})
(maybePath ./homes/${cfg.platform}/${name})
]
++ lib.optionals (cfg.platform == "android") [
./systems/nix-on-droid
./homes/nix-on-droid
]
++ cfg.modules;
"${if (cfg.platform == "android") then "extraS" else "s"}pecialArgs" = {
inherit self inputs;
inherit (cfg) username;
} // cfg.specialArgs;
}
// lib.optionalAttrs (cfg.platform != "android") { inherit (cfg) system; }
// lib.optionalAttrs (cfg.platform == "android") {
pkgs = import inputs.nixpkgs {
inherit (cfg) system;
inherit (inputs.self.outputs.nixosConfigurations.kilimanjaro.config.nixpkgs) overlays;
};
}
)
) config.hosts
)
);
perSystem =
{
lib,
system,
...
}:
{
checks =
let
currentSystemConfigurations = lib.filterAttrs (k: v: v.pkgs.system == system) (
flake.nixosConfigurations // flake.darwinConfigurations
);
in
builtins.mapAttrs (k: v: v.config.system.build.toplevel) currentSystemConfigurations;
};
};
}