-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake-module.nix
150 lines (130 loc) · 3.57 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
lib,
inputs,
config,
withSystem,
...
}:
let
inherit (lib.options) mkOption literalExpression;
inherit (lib) types;
inherit (import ./lib.nix { inherit lib inputs withSystem; })
constructSystem
mkHosts
buildHosts
;
cfg = config.easyHosts;
# we really expect a list of paths but i want to accept lists of lists of lists and so on
# since they will be flattened in the final function that applies the settings
modulesType = types.listOf types.anything;
specialArgsType = types.lazyAttrsOf types.raw;
in
{
options = {
easyHosts = {
autoConstruct = lib.mkEnableOption "Automatically construct hosts";
path = mkOption {
type = types.nullOr types.path;
default = null;
example = literalExpression "./hosts";
};
onlySystem = mkOption {
type = types.nullOr types.str;
default = null;
example = literalExpression "aarch64-darwin";
};
shared = {
modules = mkOption {
type = modulesType;
default = [ ];
};
specialArgs = mkOption {
type = specialArgsType;
default = { };
};
};
perClass = mkOption {
default = _: {
modules = [ ];
specialArgs = { };
};
type = types.functionTo (
types.submodule {
options = {
modules = mkOption {
type = modulesType;
default = [ ];
};
specialArgs = mkOption {
type = specialArgsType;
default = { };
};
};
}
);
};
additionalClasses = mkOption {
default = { };
type = types.attrsOf types.str;
description = "Additional classes and thier rescpective mappings to already existing classes";
example = lib.literalExpression ''
{
wsl = "nixos";
rpi = "nixos";
macos = "darwin";
}
'';
};
hosts = mkOption {
default = { };
type = types.attrsOf (
types.submodule (
{ name, ... }:
let
self = cfg.hosts.${name};
in
{
options = {
arch = mkOption {
type = types.str;
default = "x86_64";
};
class = mkOption {
type = types.str;
default = "nixos";
};
system = mkOption {
type = types.str;
default = constructSystem cfg self.class self.arch;
};
path = mkOption {
type = types.nullOr types.path;
default = null;
example = literalExpression "./hosts/myhost";
};
deployable = mkOption {
type = types.bool;
default = false;
};
modules = mkOption {
type = modulesType;
default = [ ];
};
specialArgs = mkOption {
type = specialArgsType;
default = { };
};
};
}
)
);
};
};
};
config = {
# if the user has made it such that they want the hosts to be constructed automatically
# i.e. from the file paths then we will do that
easyHosts.hosts = lib.mkIf cfg.autoConstruct (buildHosts cfg);
flake = mkHosts cfg;
};
}