+218
lib.nix
+218
lib.nix
···
25
25
mergeAttrs
26
26
;
27
27
28
+
/**
29
+
classToOS
30
+
31
+
# Arguments
32
+
33
+
- [class]: The class of the system. This is usually one of `nixos`, `darwin`, or `iso`.
34
+
35
+
# Type
36
+
37
+
```
38
+
classToOS :: String -> String
39
+
```
40
+
41
+
# Example
42
+
43
+
```nix
44
+
classToOS "darwin"
45
+
=> "darwin"
46
+
```
47
+
48
+
```nix
49
+
classToOS "nixos"
50
+
=> "linux"
51
+
```
52
+
*/
28
53
classToOS = class: if (class == "darwin") then "darwin" else "linux";
54
+
55
+
/**
56
+
classToND
57
+
58
+
# Arguments
59
+
60
+
- [class]: The class of the system. This is usually one of `nixos`, `darwin`, or `iso`.
61
+
62
+
# Type
63
+
64
+
```
65
+
classToND :: String -> String
66
+
```
67
+
68
+
# Example
69
+
70
+
```nix
71
+
classToND "darwin"
72
+
=> "darwin"
73
+
```
74
+
75
+
```nix
76
+
classToND "iso"
77
+
=> "nixos"
78
+
```
79
+
*/
29
80
classToND = class: if (class == "darwin") then "darwin" else "nixos";
30
81
82
+
/**
83
+
redefineClass
84
+
85
+
# Arguments
86
+
87
+
- [additionalClasses]: A set of additional classes to be used for the system.
88
+
- [class]: The class of the system. This is usually one of `nixos`, `darwin`, or `iso`.
89
+
90
+
# Type
91
+
92
+
```
93
+
redefineClass :: AttrSet -> String -> String
94
+
```
95
+
96
+
# Example
97
+
98
+
```nix
99
+
redefineClass { rpi = "nixos"; } "linux"
100
+
=> "nixos"
101
+
```
102
+
103
+
```nix
104
+
redefineClass { rpi = "nixos"; } "rpi"
105
+
=> "nixos"
106
+
```
107
+
*/
31
108
redefineClass =
32
109
additionalClasses: class: ({ linux = "nixos"; } // additionalClasses).${class} or class;
33
110
111
+
/**
112
+
constructSystem
113
+
114
+
# Arguments
115
+
116
+
- [additionalClasses]: A set of additional classes to be used for the system.
117
+
- [arch]: The architecture of the system. This is usually one of `x86_64`, `aarch64`, or `armv7l`.
118
+
- [class]: The class of the system. This is usually one of `nixos`, `darwin`, or `iso`.
119
+
120
+
# Type
121
+
122
+
```
123
+
constructSystem :: AttrSet -> String -> String -> String
124
+
```
125
+
126
+
# Example
127
+
128
+
```nix
129
+
constructSystem { rpi = "nixos"; } "x86_64" "rpi"
130
+
=> "x86_64-linux"
131
+
```
132
+
133
+
```nix
134
+
constructSystem { rpi = "nixos"; } "x86_64" "linux"
135
+
=> "x86_64-linux"
136
+
```
137
+
*/
34
138
constructSystem =
35
139
additionalClasses: arch: class:
36
140
let
···
39
143
in
40
144
"${arch}-${os}";
41
145
146
+
/**
147
+
splitSystem
148
+
149
+
# Arguments
150
+
151
+
- [system]: The system to be split. This is usually one of `x86_64-linux`, `aarch64-darwin`, or `armv7l-linux`.
152
+
153
+
# Type
154
+
155
+
```
156
+
splitSystem :: String -> AttrSet
157
+
```
158
+
159
+
# Example
160
+
161
+
```nix
162
+
splitSystem "x86_64-linux"
163
+
=> { arch = "x86_64"; class = "linux"; }
164
+
```
165
+
166
+
```nix
167
+
splitSystem "aarch64-darwin"
168
+
=> { arch = "aarch64"; class = "darwin"; }
169
+
```
170
+
*/
42
171
splitSystem =
43
172
system:
44
173
let
···
173
302
];
174
303
};
175
304
305
+
/**
306
+
toHostOutput
307
+
308
+
# Arguments
309
+
310
+
- [name]: The name of the host.
311
+
- [class]: The class of the host. This is usually one of `nixos`, `darwin`, or `iso`.
312
+
- [output]: The output of the host.
313
+
314
+
# Type
315
+
316
+
```
317
+
toHostOutput :: AttrSet -> AttrSet
318
+
```
319
+
320
+
# Example
321
+
322
+
```nix
323
+
toHostOutput {
324
+
name = "myhost";
325
+
class = "nixos";
326
+
output = { };
327
+
}
328
+
=> { nixosConfigurations.myhost = { }; }
329
+
```
330
+
*/
176
331
toHostOutput =
177
332
{
178
333
name,
···
186
341
187
342
foldAttrsMerge = foldAttrs mergeAttrs { };
188
343
344
+
/**
345
+
mkHosts is a function that takes a set of hosts and returns a set of host outputs.
346
+
347
+
# Arguments
348
+
349
+
- [easyHostsConfig]: The easy-hosts configuration.
350
+
351
+
# Type
352
+
353
+
```
354
+
mkHosts :: AttrSet -> AttrSet
355
+
```
356
+
*/
189
357
mkHosts =
190
358
easyHostsConfig:
191
359
pipe easyHostsConfig.hosts [
···
228
396
foldAttrsMerge
229
397
];
230
398
399
+
/**
400
+
normaliseHost
401
+
402
+
# Arguments
403
+
404
+
- [additionalClasses]: A set of additional classes to be used for the system.
405
+
- [system]: The system to be normalised. This is usually one of `x86_64-linux`, `aarch64-darwin`, or `armv7l-linux`.
406
+
- [path]: The path to the host.
407
+
408
+
# Type
409
+
410
+
```
411
+
normaliseHost :: AttrSet -> String -> String -> AttrSet
412
+
```
413
+
414
+
# Example
415
+
416
+
```nix
417
+
normaliseHost { rpi = "nixos"; } "x86_64-linux" "/path/to/host"
418
+
=> { arch = "x86_64"; class = "linux"; path = "/path/to/host"; system = "x86_64-linux"; }
419
+
```
420
+
*/
231
421
normaliseHost =
232
422
additionalClasses: system: path:
233
423
let
···
238
428
system = constructSystem additionalClasses arch class;
239
429
};
240
430
431
+
/**
432
+
normaliseHosts is a function that takes a set of hosts and returns a set of normalised hosts.
433
+
434
+
# Arguments
435
+
436
+
- [cfg]: The easy-hosts configuration.
437
+
- [hosts]: The hosts to be normalised.
438
+
439
+
# Type
440
+
441
+
```
442
+
normaliseHosts :: AttrSet -> AttrSet -> AttrSet
443
+
```
444
+
*/
241
445
normaliseHosts =
242
446
cfg: hosts:
243
447
if (cfg.onlySystem == null) then
···
253
457
else
254
458
mapAttrs (name: _: normaliseHost cfg.additionalClasses cfg.onlySystem "${cfg.path}/${name}") hosts;
255
459
460
+
/**
461
+
buildHosts is a function that takes a configuration and returns a set of hosts.
462
+
It is used to build the hosts for the system.
463
+
464
+
# Arguments
465
+
466
+
- [cfg]: The easy-hosts configuration.
467
+
468
+
# Type
469
+
470
+
```
471
+
buildHosts :: AttrSet -> AttrSet
472
+
```
473
+
*/
256
474
buildHosts =
257
475
cfg:
258
476
let