diff options
Diffstat (limited to 'hosts/vidhar/network/dhcp')
| -rw-r--r-- | hosts/vidhar/network/dhcp/default.nix | 221 |
1 files changed, 170 insertions, 51 deletions
diff --git a/hosts/vidhar/network/dhcp/default.nix b/hosts/vidhar/network/dhcp/default.nix index 07a83351..eda27663 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 | ||
| 3 | with lib; | 3 | with lib; |
| 4 | 4 | ||
| 5 | { | 5 | let |
| 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 | }; | ||
| 30 | in { | ||
| 6 | config = { | 31 | config = { |
| 7 | services.kea = { | 32 | services.kea = { |
| 8 | dhcp4 = { | 33 | dhcp4 = { |
| @@ -23,41 +48,67 @@ with lib; | |||
| 23 | }; | 48 | }; |
| 24 | 49 | ||
| 25 | client-classes = [ | 50 | client-classes = [ |
| 26 | { name = "eostre-ipxe"; | 51 | { name = "ipxe-eostre"; |
| 27 | test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and option[77].hex == 'iPXE'"; | 52 | test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and 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}/eostre.menu.ipxe"; |
| 55 | only-if-required = true; | ||
| 56 | } | ||
| 57 | { name = "ipxe-yggdrasil"; | ||
| 58 | test = "option[77].hex == 'iPXE-yggdrasil'"; | ||
| 59 | next-server = tftpIp; | ||
| 60 | boot-file-name = "${nfsrootBaseUrl}/installer-x86_64-linux.menu.ipxe"; | ||
| 61 | only-if-required = true; | ||
| 62 | } | ||
| 63 | |||
| 64 | { name = "uefi-http"; | ||
| 65 | test = "option[client-system].hex == 0x0010"; | ||
| 66 | option-data = [ | ||
| 67 | { name = "vendor-class-identifier"; data = "HTTPClient"; } | ||
| 68 | ]; | ||
| 69 | boot-file-name = "${nfsrootBaseUrl}/ipxe.efi"; | ||
| 70 | only-if-required = true; | ||
| 71 | } | ||
| 72 | |||
| 73 | { name = "ipxe-uefi-64"; | ||
| 74 | 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')"; | ||
| 75 | boot-file-name = "${nfsrootBaseUrl}/ipxe.efi"; | ||
| 76 | only-if-required = true; | ||
| 77 | } | ||
| 78 | { name = "ipxe-uefi-32"; | ||
| 79 | 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')"; | ||
| 80 | boot-file-name = "${nfsrootBaseUrl}/i386-ipxe.efi"; | ||
| 30 | only-if-required = true; | 81 | only-if-required = true; |
| 31 | } | 82 | } |
| 32 | { name = "ipxe"; | 83 | { name = "ipxe-legacy"; |
| 33 | test = "option[77].hex == 'iPXE'"; | 84 | test = "option[77].hex == 'iPXE' and substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; |
| 34 | next-server = "10.141.0.1"; | 85 | boot-file-name = "${nfsrootBaseUrl}/ipxe.lkrn"; |
| 35 | boot-file-name = "http://nfsroot.vidhar.yggdrasil/installer-x86_64-linux/netboot.ipxe"; | ||
| 36 | only-if-required = true; | 86 | only-if-required = true; |
| 37 | } | 87 | } |
| 88 | |||
| 38 | { name = "uefi-64"; | 89 | { 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'"; | 90 | 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 = [ | 91 | option-data = [ |
| 42 | { name = "tftp-server-name"; data = "10.141.0.1"; } | 92 | { name = "tftp-server-name"; data = tftpIp; } |
| 43 | ]; | 93 | ]; |
| 44 | boot-file-name = "ipxe.efi"; | 94 | boot-file-name = "ipxe.efi"; |
| 95 | only-if-required = true; | ||
| 45 | } | 96 | } |
| 46 | { name = "uefi-32"; | 97 | { name = "uefi-32"; |
| 47 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006'"; | 98 | 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 = [ | 99 | option-data = [ |
| 50 | { name = "tftp-server-name"; data = "10.141.0.1"; } | 100 | { name = "tftp-server-name"; data = tftpIp; } |
| 51 | ]; | 101 | ]; |
| 52 | boot-file-name = "i386-ipxe.efi"; | 102 | boot-file-name = "i386-ipxe.efi"; |
| 103 | only-if-required = true; | ||
| 53 | } | 104 | } |
| 54 | { name = "legacy"; | 105 | { name = "legacy"; |
| 55 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; | 106 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; |
| 56 | only-if-required = true; | ||
| 57 | option-data = [ | 107 | option-data = [ |
| 58 | { name = "tftp-server-name"; data = "10.141.0.1"; } | 108 | { name = "tftp-server-name"; data = tftpIp; } |
| 59 | ]; | 109 | ]; |
| 60 | boot-file-name = "undionly.kpxe"; | 110 | boot-file-name = "ipxe.lkrn"; |
| 111 | only-if-required = true; | ||
| 61 | } | 112 | } |
| 62 | ]; | 113 | ]; |
| 63 | 114 | ||
| @@ -252,34 +303,78 @@ with lib; | |||
| 252 | name = "nfsroot.vidhar.yggdrasil"; | 303 | name = "nfsroot.vidhar.yggdrasil"; |
| 253 | paths = | 304 | paths = |
| 254 | (map (system: | 305 | (map (system: |
| 255 | let | 306 | pkgs.symlinkJoin { |
| 256 | installerBuild = (flake.nixosConfigurations.${"installer-${system}-nfsroot"}.extendModules { | 307 | name = "installer-${system}"; |
| 257 | modules = [ | 308 | paths = [ |
| 258 | ({ ... }: { | 309 | (builtins.addErrorContext "while evaluating installer-${system}-nfsroot" (let |
| 259 | config.nfsroot.storeDevice = "10.141.0.1:nix-store"; | 310 | installerBuild' = (flake.nixosConfigurations.${"installer-${system}-nfsroot"}.extendModules { |
| 260 | config.nfsroot.registrationUrl = "http://nfsroot.vidhar.yggdrasil/installer-${system}/registration"; | 311 | modules = [ |
| 261 | }) | 312 | ({ ... }: { |
| 262 | ]; | 313 | config.nfsroot.storeDevice = "${nfsIp}:nix-store"; |
| 263 | }).config.system.build; | 314 | config.nfsroot.registrationUrl = "${nfsrootBaseUrl}/installer-${system}/registration"; |
| 264 | in builtins.toPath (pkgs.runCommandLocal "install-${system}" {} '' | 315 | config.system.nixos.label = "installer-${system}"; |
| 265 | mkdir -p $out/installer-${system} | 316 | }) |
| 266 | install -m 0444 -t $out/installer-${system} \ | 317 | ]; |
| 267 | ${installerBuild.initialRamdisk}/initrd \ | 318 | }); |
| 268 | ${installerBuild.kernel}/bzImage \ | 319 | installerBuild = installerBuild'.config.system.build; |
| 269 | ${installerBuild.netbootIpxeScript}/netboot.ipxe \ | 320 | in builtins.toPath (pkgs.runCommandLocal "installer-${system}" {} '' |
| 270 | ${pkgs.closureInfo { rootPaths = installerBuild.storeContents; }}/registration | 321 | mkdir -p $out/installer-${system} |
| 271 | '') | 322 | install -m 0444 -t $out/installer-${system} \ |
| 272 | ) ["x86_64-linux"] | 323 | ${installerBuild.initialRamdisk}/initrd \ |
| 324 | ${installerBuild.kernel}/bzImage \ | ||
| 325 | ${installerBuild.netbootIpxeScript}/netboot.ipxe \ | ||
| 326 | ${pkgs.closureInfo { rootPaths = installerBuild.storeContents; }}/registration | ||
| 327 | install -m 0444 ${pkgs.writeText "installer-${system}.menu.ipxe" '' | ||
| 328 | #!ipxe | ||
| 329 | |||
| 330 | :start | ||
| 331 | menu iPXE boot menu for installer-${system} | ||
| 332 | item installer ${with installerBuild'; "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})"} | ||
| 333 | item memtest memtest86plus | ||
| 334 | item netboot netboot.xyz | ||
| 335 | item shell iPXE shell | ||
| 336 | choose --timeout 0 --default installer selected || goto shell | ||
| 337 | goto ''${selected} | ||
| 338 | |||
| 339 | :shell | ||
| 340 | shell | ||
| 341 | goto start | ||
| 342 | |||
| 343 | :installer | ||
| 344 | chain installer-${system}/netboot.ipxe | ||
| 345 | goto start | ||
| 346 | |||
| 347 | :netboot | ||
| 348 | iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn | ||
| 349 | goto start | ||
| 350 | |||
| 351 | :memtest | ||
| 352 | chain --autofree mt86plus.efi | ||
| 353 | goto start | ||
| 354 | ''} $out/installer-${system}.menu.ipxe | ||
| 355 | ''))) | ||
| 356 | ]; | ||
| 357 | }) ["x86_64-linux"] | ||
| 273 | ) ++ [ | 358 | ) ++ [ |
| 274 | (let | 359 | (pkgs.runCommandLocal "utils" {} '' |
| 275 | eostreBuild = (flake.nixosConfigurations.eostre.extendModules { | 360 | mkdir $out |
| 361 | install -m 0444 -t $out \ | ||
| 362 | ${ipxe}/{ipxe.efi,i386-ipxe.efi,ipxe.lkrn} \ | ||
| 363 | ${pkgs.memtest86plus}/mt86plus.efi | ||
| 364 | install -m 0444 ${sources.netbootxyz-efi.src} $out/netboot.xyz.efi | ||
| 365 | install -m 0444 ${sources.netbootxyz-lkrn.src} $out/netboot.xyz.lkrn | ||
| 366 | '') | ||
| 367 | (builtins.addErrorContext "while evaluating eostre" (let | ||
| 368 | eostreBuild' = (flake.nixosConfigurations.eostre.extendModules { | ||
| 276 | modules = [ | 369 | modules = [ |
| 277 | ({ ... }: { | 370 | ({ ... }: { |
| 278 | config.nfsroot.storeDevice = "10.141.0.1:nix-store"; | 371 | config.nfsroot.storeDevice = "${nfsIp}:nix-store"; |
| 279 | config.nfsroot.registrationUrl = "http://nfsroot.vidhar.yggdrasil/eostre/registration"; | 372 | config.nfsroot.registrationUrl = "${nfsrootBaseUrl}/eostre/registration"; |
| 373 | config.system.nixos.label = "eostre"; | ||
| 280 | }) | 374 | }) |
| 281 | ]; | 375 | ]; |
| 282 | }).config.system.build; | 376 | }); |
| 377 | eostreBuild = eostreBuild'.config.system.build; | ||
| 283 | in builtins.toPath (pkgs.runCommandLocal "eostre" {} '' | 378 | in builtins.toPath (pkgs.runCommandLocal "eostre" {} '' |
| 284 | mkdir -p $out/eostre | 379 | mkdir -p $out/eostre |
| 285 | install -m 0444 -t $out/eostre \ | 380 | install -m 0444 -t $out/eostre \ |
| @@ -287,7 +382,39 @@ with lib; | |||
| 287 | ${eostreBuild.kernel}/bzImage \ | 382 | ${eostreBuild.kernel}/bzImage \ |
| 288 | ${eostreBuild.netbootIpxeScript}/netboot.ipxe \ | 383 | ${eostreBuild.netbootIpxeScript}/netboot.ipxe \ |
| 289 | ${pkgs.closureInfo { rootPaths = eostreBuild.storeContents; }}/registration | 384 | ${pkgs.closureInfo { rootPaths = eostreBuild.storeContents; }}/registration |
| 290 | '')) | 385 | install -m 0444 ${pkgs.writeText "eostre.menu.ipxe" '' |
| 386 | #!ipxe | ||
| 387 | |||
| 388 | set menu-timeout 5000 | ||
| 389 | |||
| 390 | :start | ||
| 391 | menu iPXE boot menu for eostre | ||
| 392 | item eostre ${with eostreBuild'; "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} (Linux ${config.boot.kernelPackages.kernel.modDirVersion})"} | ||
| 393 | item memtest memtest86plus | ||
| 394 | item netboot netboot.xyz | ||
| 395 | item shell iPXE shell | ||
| 396 | choose --timeout ''${menu-timeout} --default eostre selected || goto shell | ||
| 397 | set menu-timeout 0 | ||
| 398 | goto ''${selected} | ||
| 399 | |||
| 400 | :shell | ||
| 401 | set menu-timeout 0 | ||
| 402 | shell | ||
| 403 | goto start | ||
| 404 | |||
| 405 | :eostre | ||
| 406 | chain eostre/netboot.ipxe | ||
| 407 | goto start | ||
| 408 | |||
| 409 | :netboot | ||
| 410 | iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn | ||
| 411 | goto start | ||
| 412 | |||
| 413 | :memtest | ||
| 414 | chain --autofree mt86plus.efi | ||
| 415 | goto start | ||
| 416 | ''} $out/eostre.menu.ipxe | ||
| 417 | ''))) | ||
| 291 | ]; | 418 | ]; |
| 292 | }; | 419 | }; |
| 293 | }; | 420 | }; |
| @@ -298,20 +425,12 @@ with lib; | |||
| 298 | after = [ "network.target" ]; | 425 | after = [ "network.target" ]; |
| 299 | wantedBy = [ "multi-user.target" ]; | 426 | wantedBy = [ "multi-user.target" ]; |
| 300 | serviceConfig.ExecStart = let | 427 | 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" {} '' | 428 | tftpRoot = pkgs.runCommandLocal "netboot" {} '' |
| 310 | mkdir -p $out | 429 | mkdir -p $out |
| 311 | install -m 0444 -t $out \ | 430 | install -m 0444 -t $out \ |
| 312 | ${ipxe}/ipxe.efi ${ipxe}/i386-ipxe.efi ${ipxe}/undionly.kpxe | 431 | ${ipxe}/{ipxe.efi,i386-ipxe.efi,ipxe.lkrn} |
| 313 | ''; | 432 | ''; |
| 314 | in "${pkgs.atftp}/sbin/atftpd --daemon --no-fork --bind-address=10.141.0.1 ${tftpRoot}"; | 433 | in "${pkgs.atftp}/sbin/atftpd --daemon --no-fork --bind-address=${tftpIp} ${tftpRoot}"; |
| 315 | }; | 434 | }; |
| 316 | }; | 435 | }; |
| 317 | } | 436 | } |
