Repository navigation
Expand file tree
/
Copy pathflake-module.nix
More file actions
128 lines (117 loc) · 3.22 KB
/
Copy pathflake-module.nix
File metadata and controls
128 lines (117 loc) · 3.22 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
{
inputs,
lib,
config,
mkPkgs,
...
}:
let
inherit (builtins) pathExists;
inherit (lib)
filter
foldl'
mapAttrsToList
mkOption
optionalAttrs
optionals
recursiveUpdate
types
;
getDefaultPlatform = system: if lib.hasSuffix "-linux" system then "nixos" else "darwin";
maybePath = path: if pathExists path then path else null;
systemConfigurations =
platform: hostname: attrs:
if platform == "nixos" then
{ nixosConfigurations.${hostname} = inputs.nixpkgs.lib.nixosSystem attrs; }
else if platform == "darwin" then
{ darwinConfigurations.${hostname} = inputs.nix-darwin.lib.darwinSystem attrs; }
else
{ nixOnDroidConfigurations.${hostname} = inputs.nix-on-droid.lib.nixOnDroidConfiguration attrs; };
mkSystemConfiguration =
name: cfg:
systemConfigurations cfg.platform name (
{
modules =
filter (x: x != null) [
(maybePath ./systems/${cfg.platform}/${name})
(maybePath ./homes/${cfg.platform}/${name})
]
++ cfg.modules
++ optionals (cfg.platform != "android") [
{ nixpkgs.pkgs = mkPkgs cfg.system; }
];
}
// optionalAttrs (cfg.platform != "android") {
inherit (cfg) system;
specialArgs = {
inherit inputs;
inherit (cfg) username;
}
// cfg.specialArgs;
}
// optionalAttrs (cfg.platform == "android") {
extraSpecialArgs = {
inherit inputs;
inherit (cfg) username;
}
// cfg.specialArgs;
pkgs = import inputs.nixpkgs {
inherit (cfg) system;
overlays = [ inputs.nix-on-droid.overlays.default ];
};
home-manager-path = inputs.home-manager.outPath;
}
);
in
{
options.hosts = mkOption {
default = { };
type = types.attrsOf (
types.submodule (
{ name, config, ... }:
{
options = {
system = mkOption {
default = "x86_64-linux";
type = types.str;
};
platform = mkOption {
default = getDefaultPlatform config.system;
type = types.enum [
"nixos"
"darwin"
"android"
];
};
modules = mkOption {
default = [ ];
type = types.listOf types.unspecified;
};
username = mkOption {
default = "yuta";
type = types.str;
};
specialArgs = mkOption {
default = { };
type = types.attrs;
};
};
}
)
);
};
config = rec {
flake = foldl' recursiveUpdate { } (mapAttrsToList mkSystemConfiguration config.hosts);
perSystem =
{ lib, system, ... }:
{
checks =
let
currentSystemConfigurations = lib.filterAttrs (
_name: value: value.pkgs.stdenv.hostPlatform.system == system
) ((flake.nixosConfigurations or { }) // (flake.darwinConfigurations or { }));
in
builtins.mapAttrs (_name: value: value.config.system.build.toplevel) currentSystemConfigurations;
};
};
}