-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
382 lines (344 loc) · 13.8 KB
/
flake.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
{
description = "Flake for building Raspberry Pi based SD images and machines";
inputs = {
# Nixpkgs and unstable
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# nix-community hardware quirks
# https://github.com/nix-community
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
# nur
nur.url = "github:nix-community/NUR";
# sops-nix - secrets with mozilla sops
# https://github.com/Mic92/sops-nix
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# # VSCode community extensions
# # https://github.com/nix-community/nix-vscode-extensions
# nix-vscode-extensions = {
# url = "github:nix-community/nix-vscode-extensions";
# inputs.nixpkgs.follows = "nixpkgs";
# };
# nixos-rk3588 for Orange Pi 5 + machines
# nixos-rk3588.url = "github:ryan4yin/nixos-rk3588";
};
outputs = { self, nixpkgs, nixpkgs-unstable, sops-nix, ... }@inputs:
let
inherit (self) outputs;
in
rec {
# extend lib with my custom functions
lib = nixpkgs.lib.extend (
final: prev: {
inherit inputs;
myLib = import ./nixos/lib { inherit inputs; lib = final; };
}
);
nixosConfigurations =
with self.lib;
let
specialArgs = {
inherit inputs outputs;
};
# Import overlays for building nixosconfig with them.
overlays = import ./nixos/overlays { inherit inputs; };
# generate a base nixos configuration with the
# specified overlays, hardware modules, and any extraModules applied
mkNixosConfig =
{ hostname
, system ? "x86_64-linux"
, nixpkgs ? inputs.nixpkgs
, hardwareModules ? [ ]
# basemodules is the base of the entire machine building
# here we import all the modules and setup home-manager
, baseModules ? [
sops-nix.nixosModules.sops
./nixos/profiles/global.nix # all machines get a global profile
./nixos/modules/nixos # all machines get nixos modules
./nixos/hosts/${hostname} # load this host's config folder for machine-specific config
]
, profileModules ? [ ]
}:
nixpkgs.lib.nixosSystem {
inherit system lib;
modules = baseModules ++ hardwareModules ++ profileModules;
specialArgs = { inherit self inputs nixpkgs; };
# Add our overlays
pkgs = import nixpkgs {
inherit system;
overlays = builtins.attrValues overlays;
config = {
allowUnfree = true;
allowUnfreePredicate = _: true;
};
};
};
in
rec {
# genpi4 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# ./nixos/personalities/base
# ./nixos/personalities/users
# ];
# };
eagle = mkNixosConfig {
hostname = "eagle";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
];
};
mysecrets = mkNixosConfig {
hostname = "mysecrets";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
];
};
possum = mkNixosConfig {
hostname = "possum";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
];
};
### CLUSTER k3s
## Cluster Raccoon controller nodes : raspberry pi 4
raccoon00 = mkNixosConfig {
hostname = "raccoon00";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-controller.nix
];
};
raccoon01 = mkNixosConfig {
hostname = "raccoon01";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-controller.nix
];
};
raccoon02 = mkNixosConfig {
hostname = "raccoon02";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-controller.nix
];
};
## Cluster Raccoon worker nodes : raspberry pi 4
raccoon03 = mkNixosConfig {
hostname = "raccoon03";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-worker.nix
];
};
raccoon04 = mkNixosConfig {
hostname = "raccoon04";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-worker.nix
];
};
raccoon05 = mkNixosConfig {
hostname = "raccoon05";
system = "aarch64-linux";
hardwareModules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
./nixos/profiles/hw-rpi4.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-worker.nix
];
};
## Cluster Sparrow worker nodes : raspberry pi 3
# sparrow01 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# (_: {
# networking.hostName = "sparrow01";
# # For RTL-SDR
# boot.kernelParams = [ "modprobe.blacklist=dvb_usb_rtl28xxu" ];
# })
# ./nixos/hosts/k3s-rasp3-worker
# sops-nix.nixosModules.sops
# ];
# };
# sparrow02 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# (_: { networking.hostName = "sparrow02"; })
# ./nixos/hosts/k3s-rasp3-worker
# sops-nix.nixosModules.sops
# ];
# };
# sparrow03 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# (_: { networking.hostName = "sparrow03"; })
# ./nixos/hosts/k3s-rasp3-worker
# sops-nix.nixosModules.sops
# ];
# };
# sparrow04 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# (_: { networking.hostName = "sparrow04"; })
# ./nixos/hosts/k3s-rasp3-worker
# sops-nix.nixosModules.sops
# ];
# };
# sparrow05 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# (_: {
# networking.hostName = "sparrow05";
# services.k3s.extraFlags = toString [
# "--node-label svccontroller.k3s.cattle.io/enablelb=true"
# "--node-label svccontroller.k3s.cattle.io/lbpool=external"
# ];
# })
# ./nixos/hosts/k3s-rasp3-worker
# sops-nix.nixosModules.sops
# ];
# };
## Decommissioned for now ...
# sparrow06 = nixpkgs.lib.nixosSystem {
# inherit system;
# modules = [
# # Overlays-module makes "pkgs.unstable" available in configuration.nix
# ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# (_: { networking.hostName = "sparrow06"; })
# ./nixos/hosts/k3s-rasp3-worker
# sops-nix.nixosModules.sops
# ];
# };
opi01 = mkNixosConfig {
hostname = "opi01";
system = "aarch64-linux";
hardwareModules = [
./nixos/profiles/hw-orangepi5plus.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-worker.nix
];
};
opi02 = mkNixosConfig {
hostname = "opi02";
system = "aarch64-linux";
hardwareModules = [
./nixos/profiles/hw-orangepi5plus.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-worker.nix
];
};
opi03 = mkNixosConfig {
hostname = "opi03";
system = "aarch64-linux";
hardwareModules = [
./nixos/profiles/hw-orangepi5plus.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
./nixos/profiles/role-k3s-worker.nix
];
};
###
beacon = mkNixosConfig {
hostname = "beacon";
system = "x86_64-linux";
hardwareModules = [
./nixos/profiles/hw-acer-minipc.nix
];
profileModules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
./nixos/profiles/role-server.nix
];
};
};
# Convenience output that aggregates the outputs for home, nixos.
# Also used in ci to build targets generally.
top =
let
nixtop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.nixosConfigurations)
(attr: inputs.self.nixosConfigurations.${attr}.config.system.build.toplevel);
in
nixtop;
};
}