summaryrefslogtreecommitdiff
path: root/hosts/vidhar/network/dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'hosts/vidhar/network/dhcp')
-rw-r--r--hosts/vidhar/network/dhcp/default.nix220
-rw-r--r--hosts/vidhar/network/dhcp/knot-tsig (renamed from hosts/vidhar/network/dhcp/knot-tsig.json.frag)18
2 files changed, 143 insertions, 95 deletions
diff --git a/hosts/vidhar/network/dhcp/default.nix b/hosts/vidhar/network/dhcp/default.nix
index 07a83351..2efabd23 100644
--- a/hosts/vidhar/network/dhcp/default.nix
+++ b/hosts/vidhar/network/dhcp/default.nix
@@ -1,8 +1,33 @@
1{ flake, config, pkgs, lib, ... }: 1{ flake, config, pkgs, lib, sources, ... }:
2 2
3with lib; 3with lib;
4 4
5{ 5let
6 nfsrootBaseUrl = "http://nfsroot.vidhar.yggdrasil";
7 tftpIp = "10.141.0.1";
8 nfsIp = tftpIp;
9 ipxe = pkgs.ipxe.override {
10 additionalTargets = {
11 "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi";
12 };
13 additionalOptions = [
14 "NSLOOKUP_CMD"
15 "PING_CMD"
16 "CONSOLE_CMD"
17 ];
18 embedScript = pkgs.writeText "yggdrasil.ipxe" ''
19 #!ipxe
20
21 cpair --background 9 1
22 cpair --background 9 3
23 cpair --background 9 6
24
25 set user-class iPXE-yggdrasil
26
27 autoboot
28 '';
29 };
30in {
6 config = { 31 config = {
7 services.kea = { 32 services.kea = {
8 dhcp4 = { 33 dhcp4 = {
@@ -23,41 +48,61 @@ with lib;
23 }; 48 };
24 49
25 client-classes = [ 50 client-classes = [
26 { name = "eostre-ipxe"; 51 { name = "ipxe-yggdrasil";
27 test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and option[77].hex == 'iPXE'"; 52 test = "option[77].hex == 'iPXE-yggdrasil'";
28 next-server = "10.141.0.1"; 53 next-server = tftpIp;
29 boot-file-name = "http://nfsroot.vidhar.yggdrasil/eostre/netboot.ipxe"; 54 boot-file-name = "${nfsrootBaseUrl}/installer-x86_64-linux.menu.ipxe";
55 only-if-required = true;
56 }
57
58 { name = "uefi-http";
59 test = "option[client-system].hex == 0x0010";
60 option-data = [
61 { name = "vendor-class-identifier"; data = "HTTPClient"; }
62 ];
63 boot-file-name = "${nfsrootBaseUrl}/ipxe.efi";
30 only-if-required = true; 64 only-if-required = true;
31 } 65 }
32 { name = "ipxe"; 66
33 test = "option[77].hex == 'iPXE'"; 67 { name = "ipxe-uefi-64";
34 next-server = "10.141.0.1"; 68 test = "option[77].hex == 'iPXE' and (substring(option[60].hex,0,20) == 'PXEClient:Arch:00007' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00008' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00009')";
35 boot-file-name = "http://nfsroot.vidhar.yggdrasil/installer-x86_64-linux/netboot.ipxe"; 69 boot-file-name = "${nfsrootBaseUrl}/ipxe.efi";
70 only-if-required = true;
71 }
72 { name = "ipxe-uefi-32";
73 test = "option[77].hex == 'iPXE' and (substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006')";
74 boot-file-name = "${nfsrootBaseUrl}/i386-ipxe.efi";
75 only-if-required = true;
76 }
77 { name = "ipxe-legacy";
78 test = "option[77].hex == 'iPXE' and substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'";
79 boot-file-name = "${nfsrootBaseUrl}/ipxe.lkrn";
36 only-if-required = true; 80 only-if-required = true;
37 } 81 }
82
38 { name = "uefi-64"; 83 { name = "uefi-64";
39 test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00007' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00008' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00009'"; 84 test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00007' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00008' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00009'";
40 only-if-required = true;
41 option-data = [ 85 option-data = [
42 { name = "tftp-server-name"; data = "10.141.0.1"; } 86 { name = "tftp-server-name"; data = tftpIp; }
43 ]; 87 ];
44 boot-file-name = "ipxe.efi"; 88 boot-file-name = "ipxe.efi";
89 only-if-required = true;
45 } 90 }
46 { name = "uefi-32"; 91 { name = "uefi-32";
47 test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006'"; 92 test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006'";
48 only-if-required = true;
49 option-data = [ 93 option-data = [
50 { name = "tftp-server-name"; data = "10.141.0.1"; } 94 { name = "tftp-server-name"; data = tftpIp; }
51 ]; 95 ];
52 boot-file-name = "i386-ipxe.efi"; 96 boot-file-name = "i386-ipxe.efi";
97 only-if-required = true;
53 } 98 }
54 { name = "legacy"; 99 { name = "legacy";
55 test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; 100 test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'";
56 only-if-required = true;
57 option-data = [ 101 option-data = [
58 { name = "tftp-server-name"; data = "10.141.0.1"; } 102 { name = "tftp-server-name"; data = tftpIp; }
59 ]; 103 ];
60 boot-file-name = "undionly.kpxe"; 104 boot-file-name = "ipxe.lkrn";
105 only-if-required = true;
61 } 106 }
62 ]; 107 ];
63 108
@@ -205,40 +250,27 @@ with lib;
205 } 250 }
206 ]; 251 ];
207 }; 252 };
253 tsig-keys = [
254 { name = "local_key";
255 algorithm = "HMAC-SHA256";
256 secret-file = "/run/credentials/kea-dhcp-ddns-server.service/local_key";
257 }
258 ];
208 }; 259 };
209 }; 260 };
210 }; 261 };
211 262
212 systemd.services.kea-dhcp-ddns-server = { 263 systemd.services.kea-dhcp-ddns-server = {
213 preStart = let
214 configLines = [
215 "<?include \"\${CREDENTIALS_DIRECTORY}/knot-tsig.json.frag\"?>"
216 ] ++ mapAttrsToList (k: v:
217 "\"${k}\": ${builtins.toJSON v}"
218 ) config.services.kea.dhcp-ddns.settings;
219
220 config-template = pkgs.writeText "dhcp-ddns.conf" ''
221 {"DhcpDdns": {
222 ${concatStringsSep ",\n " configLines}
223 }}
224 '';
225 in ''
226 ${pkgs.envsubst}/bin/envsubst -i "${config-template}" -o "''${RUNTIME_DIRECTORY}/dhcp-ddns.conf"
227 '';
228
229 serviceConfig = { 264 serviceConfig = {
230 ExecStart = mkForce ''
231 ${pkgs.kea}/bin/kea-dhcp-ddns -c "''${RUNTIME_DIRECTORY}/dhcp-ddns.conf" ${escapeShellArgs config.services.kea.dhcp-ddns.extraArgs}
232 '';
233 LoadCredential = [ 265 LoadCredential = [
234 "knot-tsig.json.frag:${config.sops.secrets."kea-knot-tsig.json.frag".path}" 266 "local_key:${config.sops.secrets."kea-knot-tsig".path}"
235 ]; 267 ];
236 }; 268 };
237 }; 269 };
238 270
239 sops.secrets."kea-knot-tsig.json.frag" = { 271 sops.secrets."kea-knot-tsig" = {
240 format = "binary"; 272 format = "binary";
241 sopsFile = ./knot-tsig.json.frag; 273 sopsFile = ./knot-tsig;
242 }; 274 };
243 275
244 services.nginx.virtualHosts."nfsroot.vidhar.yggdrasil" = { 276 services.nginx.virtualHosts."nfsroot.vidhar.yggdrasil" = {
@@ -252,42 +284,70 @@ with lib;
252 name = "nfsroot.vidhar.yggdrasil"; 284 name = "nfsroot.vidhar.yggdrasil";
253 paths = 285 paths =
254 (map (system: 286 (map (system:
255 let 287 pkgs.symlinkJoin {
256 installerBuild = (flake.nixosConfigurations.${"installer-${system}-nfsroot"}.extendModules { 288 name = "installer-${system}";
257 modules = [ 289 paths = [
258 ({ ... }: { 290 (builtins.addErrorContext "while evaluating installer-${system}-nfsroot" (let
259 config.nfsroot.storeDevice = "10.141.0.1:nix-store"; 291 # installerBuild' = (flake.nixosConfigurations.${"installer-${system}-nfsroot"}.extendModules {
260 config.nfsroot.registrationUrl = "http://nfsroot.vidhar.yggdrasil/installer-${system}/registration"; 292 # modules = [
261 }) 293 # ({ ... }: {
262 ]; 294 # config.nfsroot.storeDevice = "${nfsIp}:nix-store";
263 }).config.system.build; 295 # config.nfsroot.registrationUrl = "${nfsrootBaseUrl}/installer-${system}/registration";
264 in builtins.toPath (pkgs.runCommandLocal "install-${system}" {} '' 296 # config.system.nixos.label = "installer-${system}";
265 mkdir -p $out/installer-${system} 297 # })
266 install -m 0444 -t $out/installer-${system} \ 298 # ];
267 ${installerBuild.initialRamdisk}/initrd \ 299 # });
268 ${installerBuild.kernel}/bzImage \ 300 # installerBuild = installerBuild'.config.system.build;
269 ${installerBuild.netbootIpxeScript}/netboot.ipxe \ 301
270 ${pkgs.closureInfo { rootPaths = installerBuild.storeContents; }}/registration 302 # install -m 0444 -t $out/installer-${system} \
271 '') 303 # ${installerBuild.initialRamdisk}/initrd \
272 ) ["x86_64-linux"] 304 # ${installerBuild.kernel}/bzImage \
305 # ${installerBuild.netbootIpxeScript}/netboot.ipxe \
306 # ${pkgs.closureInfo { rootPaths = installerBuild.storeContents; }}/registration
307
308 # item installer ${with installerBuild'; "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})"}
309
310 # :installer
311 # chain installer-${system}/netboot.ipxe
312 # goto start
313
314 in builtins.toPath (pkgs.runCommandLocal "installer-${system}" {} ''
315 mkdir -p $out/installer-${system}
316 install -m 0444 ${pkgs.writeText "installer-${system}.menu.ipxe" ''
317 #!ipxe
318
319 :start
320 menu iPXE boot menu for installer-${system}
321 item memtest memtest86plus
322 item netboot netboot.xyz
323 item shell iPXE shell
324 choose --timeout 0 --default netboot selected || goto shell
325 goto ''${selected}
326
327 :shell
328 shell
329 goto start
330
331 :netboot
332 iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn
333 goto start
334
335 :memtest
336 chain --autofree mt86plus.efi
337 goto start
338 ''} $out/installer-${system}.menu.ipxe
339 '')))
340 ];
341 }) ["x86_64-linux"]
273 ) ++ [ 342 ) ++ [
274 (let 343 (pkgs.runCommandLocal "utils" {} ''
275 eostreBuild = (flake.nixosConfigurations.eostre.extendModules { 344 mkdir $out
276 modules = [ 345 install -m 0444 -t $out \
277 ({ ... }: { 346 ${ipxe}/{ipxe.efi,i386-ipxe.efi,ipxe.lkrn} \
278 config.nfsroot.storeDevice = "10.141.0.1:nix-store"; 347 ${pkgs.memtest86plus}/mt86plus.efi
279 config.nfsroot.registrationUrl = "http://nfsroot.vidhar.yggdrasil/eostre/registration"; 348 install -m 0444 ${sources.netbootxyz-efi.src} $out/netboot.xyz.efi
280 }) 349 install -m 0444 ${sources.netbootxyz-lkrn.src} $out/netboot.xyz.lkrn
281 ]; 350 '')
282 }).config.system.build;
283 in builtins.toPath (pkgs.runCommandLocal "eostre" {} ''
284 mkdir -p $out/eostre
285 install -m 0444 -t $out/eostre \
286 ${eostreBuild.initialRamdisk}/initrd \
287 ${eostreBuild.kernel}/bzImage \
288 ${eostreBuild.netbootIpxeScript}/netboot.ipxe \
289 ${pkgs.closureInfo { rootPaths = eostreBuild.storeContents; }}/registration
290 ''))
291 ]; 351 ];
292 }; 352 };
293 }; 353 };
@@ -298,20 +358,12 @@ with lib;
298 after = [ "network.target" ]; 358 after = [ "network.target" ];
299 wantedBy = [ "multi-user.target" ]; 359 wantedBy = [ "multi-user.target" ];
300 serviceConfig.ExecStart = let 360 serviceConfig.ExecStart = let
301 ipxe = pkgs.ipxe.override {
302 additionalTargets = {
303 "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi";
304 };
305 additionalOptions = [
306 "NSLOOKUP_CMD"
307 ];
308 };
309 tftpRoot = pkgs.runCommandLocal "netboot" {} '' 361 tftpRoot = pkgs.runCommandLocal "netboot" {} ''
310 mkdir -p $out 362 mkdir -p $out
311 install -m 0444 -t $out \ 363 install -m 0444 -t $out \
312 ${ipxe}/ipxe.efi ${ipxe}/i386-ipxe.efi ${ipxe}/undionly.kpxe 364 ${ipxe}/{ipxe.efi,i386-ipxe.efi,ipxe.lkrn}
313 ''; 365 '';
314 in "${pkgs.atftp}/sbin/atftpd --daemon --no-fork --bind-address=10.141.0.1 ${tftpRoot}"; 366 in "${pkgs.atftp}/sbin/atftpd --daemon --no-fork --bind-address=${tftpIp} ${tftpRoot}";
315 }; 367 };
316 }; 368 };
317} 369}
diff --git a/hosts/vidhar/network/dhcp/knot-tsig.json.frag b/hosts/vidhar/network/dhcp/knot-tsig
index c10115cf..73a8f11d 100644
--- a/hosts/vidhar/network/dhcp/knot-tsig.json.frag
+++ b/hosts/vidhar/network/dhcp/knot-tsig
@@ -1,18 +1,14 @@
1{ 1{
2 "data": "ENC[AES256_GCM,data:cGcoqYZ341xQOFukDm4J5KDfG6+NaNbk2U2k4YGneRsAoPJZe/8KDmVr8TBWFCXXbuzeCGbiuXRVBmtYSEIqbqTN4u00RdQgpeL72cB3ZFd2c7cideEQV5z802pqFfXSlmLBC01OPG3TwAgk6xhQYSn5IcBTIL6fRF235Y9Q8k/X96rhfwPRVq84,iv:UoweWBcVuQIXeWFFl/WNUHLXG8nEri1UuTskC2I26hU=,tag:TJldVr2LDTmKA3ozZoX+cQ==,type:str]", 2 "data": "ENC[AES256_GCM,data:ZjPqKfUCRYD4iD7yC7qObZhBAMll0DXNzImZ43TM0D8SXRtANqG6YnfwQuJ7,iv:GXD5LutgEz6ktGEtpI9z41IJLLzIMj6OvPADQlZcvwk=,tag:v9ISQFDubtLWcb2mVHa4zA==,type:str]",
3 "sops": { 3 "sops": {
4 "kms": null,
5 "gcp_kms": null,
6 "azure_kv": null,
7 "hc_vault": null,
8 "age": [ 4 "age": [
9 { 5 {
10 "recipient": "age1qffdqvy9arld9zd5a5cylt0n98xhcns5shxhrhwjq5g4qa844ejselaa4l", 6 "enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBCYk5tM1lPRXc0MGpHZENQ\ndDU2M2VKY2t2VGFrcTUvd0NrU3VMZGQ3NHlNClNTaWVjdDNTQXh6WDFmMDk3SWtn\ncjJjRzUxODFFL25Ic0dabyt1ZW5xRE0KLS0tIDJlT0NTVDlXNWphQ1B0VTQ1U0NH\nNktRNlIrQzdhRjZ0SjR0T3oyRkZiWXMKX28S4SySQguT1cgMZpDY4o/OKY6IvjT9\n1oUzwx/BzBbC2JbpGYvQQgp/qfiM2k0oXmQlfdTv8kD/MoOqPO8E1Q==\n-----END AGE ENCRYPTED FILE-----\n",
11 "enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBCYk5tM1lPRXc0MGpHZENQ\ndDU2M2VKY2t2VGFrcTUvd0NrU3VMZGQ3NHlNClNTaWVjdDNTQXh6WDFmMDk3SWtn\ncjJjRzUxODFFL25Ic0dabyt1ZW5xRE0KLS0tIDJlT0NTVDlXNWphQ1B0VTQ1U0NH\nNktRNlIrQzdhRjZ0SjR0T3oyRkZiWXMKX28S4SySQguT1cgMZpDY4o/OKY6IvjT9\n1oUzwx/BzBbC2JbpGYvQQgp/qfiM2k0oXmQlfdTv8kD/MoOqPO8E1Q==\n-----END AGE ENCRYPTED FILE-----\n" 7 "recipient": "age1qffdqvy9arld9zd5a5cylt0n98xhcns5shxhrhwjq5g4qa844ejselaa4l"
12 } 8 }
13 ], 9 ],
14 "lastmodified": "2022-03-15T13:52:17Z", 10 "lastmodified": "2026-07-29T06:39:18Z",
15 "mac": "ENC[AES256_GCM,data:rTelaGx5S2E2oYPNGfctFbgDKdyRX8tpVTqLtpcCAJ8MS5ppFTjnSwYi4yQHvTicfAPNz7hGJYAnTdyC2QDTciJgkS6KC3CCXWCimkTybBdVW4Azwz9iBZCpWu+rB1vcQhSLlLCaKmKskkqDZZ5+mfuaXc+TT2uwTA0SDtZWvnM=,iv:ANCZ1fHy6w/svEE53o7rWsp5qU15qoriqyVMzClH6J0=,tag:H92RM5GuLIl9/kslq4tzkQ==,type:str]", 11 "mac": "ENC[AES256_GCM,data:hj/YR0N8NhGHQEcCOjt/r+rfM8plkaUZoee9sI25evvEvOlfX69YRxUv1vyd6Sqd9wPEgCsF5STnMXFQhq3zgGjoTFcdHU+olRVmRq9rkYQo/ButZ/NEIQ7uc5b4FRPdPwOGF14aSpgI67F35oRavv1vtk10zGme+X0I1VXTIqE=,iv:rMUL+CyTLhQBJrsQJQPhN75FjCf5uGFh1z6KAXKDeB8=,tag:bpeQZ3UPZ10tCrgveoDklg==,type:str]",
16 "pgp": [ 12 "pgp": [
17 { 13 {
18 "created_at": "2023-01-30T11:00:34Z", 14 "created_at": "2023-01-30T11:00:34Z",
@@ -21,6 +17,6 @@
21 } 17 }
22 ], 18 ],
23 "unencrypted_suffix": "_unencrypted", 19 "unencrypted_suffix": "_unencrypted",
24 "version": "3.7.1" 20 "version": "3.13.2"
25 } 21 }
26} \ No newline at end of file 22}