diff options
Diffstat (limited to 'hosts')
| -rw-r--r-- | hosts/vidhar/network/dhcp/default.nix | 110 |
1 files changed, 80 insertions, 30 deletions
diff --git a/hosts/vidhar/network/dhcp/default.nix b/hosts/vidhar/network/dhcp/default.nix index 38dd9ae8..bd13b972 100644 --- a/hosts/vidhar/network/dhcp/default.nix +++ b/hosts/vidhar/network/dhcp/default.nix | |||
| @@ -1,9 +1,27 @@ | |||
| 1 | { flake, config, pkgs, lib, ... }: | 1 | { flake, config, pkgs, lib, sources, ... }: |
| 2 | 2 | ||
| 3 | with lib; | 3 | with lib; |
| 4 | 4 | ||
| 5 | let | 5 | let |
| 6 | nfsrootBaseUrl = "http://nfsroot.vidhar.yggdrasil"; | 6 | nfsrootBaseUrl = "http://nfsroot.vidhar.yggdrasil"; |
| 7 | ipxe = pkgs.ipxe.override { | ||
| 8 | additionalTargets = { | ||
| 9 | "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi"; | ||
| 10 | }; | ||
| 11 | additionalOptions = [ | ||
| 12 | "NSLOOKUP_CMD" | ||
| 13 | "PING_CMD" | ||
| 14 | "CONSOLE_CMD" | ||
| 15 | ]; | ||
| 16 | embedScript = pkgs.writeText "yggdrasil.ipxe" '' | ||
| 17 | #!ipxe | ||
| 18 | |||
| 19 | set user-class iPXE-yggdrasil | ||
| 20 | |||
| 21 | dhcp | ||
| 22 | autoboot | ||
| 23 | ''; | ||
| 24 | }; | ||
| 7 | in { | 25 | in { |
| 8 | config = { | 26 | config = { |
| 9 | services.kea = { | 27 | services.kea = { |
| @@ -25,41 +43,67 @@ in { | |||
| 25 | }; | 43 | }; |
| 26 | 44 | ||
| 27 | client-classes = [ | 45 | client-classes = [ |
| 28 | { name = "eostre-ipxe"; | 46 | { name = "ipxe-eostre"; |
| 29 | test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and option[77].hex == 'iPXE'"; | 47 | test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and option[77].hex == 'iPXE-yggdrasil'"; |
| 30 | next-server = "10.141.0.1"; | 48 | next-server = "10.141.0.1"; |
| 31 | boot-file-name = "${nfsrootBaseUrl}/eostre.menu.ipxe"; | 49 | boot-file-name = "${nfsrootBaseUrl}/eostre.menu.ipxe"; |
| 32 | only-if-required = true; | 50 | only-if-required = true; |
| 33 | } | 51 | } |
| 34 | { name = "ipxe"; | 52 | { name = "ipxe-yggdrasil"; |
| 35 | test = "option[77].hex == 'iPXE'"; | 53 | test = "option[77].hex == 'iPXE-yggdrasil'"; |
| 36 | next-server = "10.141.0.1"; | 54 | next-server = "10.141.0.1"; |
| 37 | boot-file-name = "${nfsrootBaseUrl}/installer-x86_64-linux.menu.ipxe"; | 55 | boot-file-name = "${nfsrootBaseUrl}/installer-x86_64-linux.menu.ipxe"; |
| 38 | only-if-required = true; | 56 | only-if-required = true; |
| 39 | } | 57 | } |
| 58 | |||
| 59 | { name = "uefi-http"; | ||
| 60 | test = "option[client-system].hex == 0x0010"; | ||
| 61 | option-data = [ | ||
| 62 | { name = "vendor-class-identifier"; data = "HTTPClient"; } | ||
| 63 | ]; | ||
| 64 | boot-file-name = "${nfsrootBaseUrl}/ipxe.efi"; | ||
| 65 | only-if-required = true; | ||
| 66 | } | ||
| 67 | |||
| 68 | { name = "ipxe-uefi-64"; | ||
| 69 | 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')"; | ||
| 70 | boot-file-name = "${nfsrootBaseUrl}/ipxe.efi"; | ||
| 71 | only-if-required = true; | ||
| 72 | } | ||
| 73 | { name = "ipxe-uefi-32"; | ||
| 74 | 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')"; | ||
| 75 | boot-file-name = "${nfsrootBaseUrl}/i386-ipxe.efi"; | ||
| 76 | only-if-required = true; | ||
| 77 | } | ||
| 78 | { name = "ipxe-legacy"; | ||
| 79 | test = "option[77].hex == 'iPXE' and substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; | ||
| 80 | boot-file-name = "${nfsrootBaseUrl}/undionly.kpxe"; | ||
| 81 | only-if-required = true; | ||
| 82 | } | ||
| 83 | |||
| 40 | { name = "uefi-64"; | 84 | { name = "uefi-64"; |
| 41 | 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'"; | 85 | 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'"; |
| 42 | only-if-required = true; | ||
| 43 | option-data = [ | 86 | option-data = [ |
| 44 | { name = "tftp-server-name"; data = "10.141.0.1"; } | 87 | { name = "tftp-server-name"; data = "10.141.0.1"; } |
| 45 | ]; | 88 | ]; |
| 46 | boot-file-name = "ipxe.efi"; | 89 | boot-file-name = "ipxe.efi"; |
| 90 | only-if-required = true; | ||
| 47 | } | 91 | } |
| 48 | { name = "uefi-32"; | 92 | { name = "uefi-32"; |
| 49 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006'"; | 93 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006'"; |
| 50 | only-if-required = true; | ||
| 51 | option-data = [ | 94 | option-data = [ |
| 52 | { name = "tftp-server-name"; data = "10.141.0.1"; } | 95 | { name = "tftp-server-name"; data = "10.141.0.1"; } |
| 53 | ]; | 96 | ]; |
| 54 | boot-file-name = "i386-ipxe.efi"; | 97 | boot-file-name = "i386-ipxe.efi"; |
| 98 | only-if-required = true; | ||
| 55 | } | 99 | } |
| 56 | { name = "legacy"; | 100 | { name = "legacy"; |
| 57 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; | 101 | test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; |
| 58 | only-if-required = true; | ||
| 59 | option-data = [ | 102 | option-data = [ |
| 60 | { name = "tftp-server-name"; data = "10.141.0.1"; } | 103 | { name = "tftp-server-name"; data = "10.141.0.1"; } |
| 61 | ]; | 104 | ]; |
| 62 | boot-file-name = "undionly.kpxe"; | 105 | boot-file-name = "undionly.kpxe"; |
| 106 | only-if-required = true; | ||
| 63 | } | 107 | } |
| 64 | ]; | 108 | ]; |
| 65 | 109 | ||
| @@ -278,9 +322,15 @@ in { | |||
| 278 | name = "installer-${system}.menu.ipxe"; | 322 | name = "installer-${system}.menu.ipxe"; |
| 279 | destination = "/installer-${system}.menu.ipxe"; | 323 | destination = "/installer-${system}.menu.ipxe"; |
| 280 | text = '' | 324 | text = '' |
| 325 | #!ipxe | ||
| 326 | |||
| 327 | cpair --background 9 1 | ||
| 328 | cpair --background 9 3 | ||
| 329 | cpair --background 9 6 | ||
| 330 | |||
| 281 | :start | 331 | :start |
| 282 | menu iPXE boot menu for installer-${system} | 332 | menu iPXE boot menu for installer-${system} |
| 283 | item installer Boot installer-${system} | 333 | item installer installer-${system} |
| 284 | item memtest memtest86plus | 334 | item memtest memtest86plus |
| 285 | item netboot netboot.xyz | 335 | item netboot netboot.xyz |
| 286 | item shell iPXE shell | 336 | item shell iPXE shell |
| @@ -292,27 +342,28 @@ in { | |||
| 292 | goto start | 342 | goto start |
| 293 | 343 | ||
| 294 | :installer | 344 | :installer |
| 295 | chain ${nfsrootBaseUrl}/installer-${system}/netboot.ipxe | 345 | chain installer-${system}/netboot.ipxe |
| 296 | goto start | 346 | goto start |
| 297 | 347 | ||
| 298 | :netboot | 348 | :netboot |
| 299 | chain --autofree ${nfsrootBaseUrl}/netboot.xyz.efi | 349 | iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn |
| 300 | goto start | 350 | goto start |
| 301 | 351 | ||
| 302 | :memtest | 352 | :memtest |
| 303 | chain --autofree ${nfsrootBaseUrl}/memtest.efi | 353 | iseq ''${platform} efi && chain --autofree memtest.efi || chain --autofree memtest.bin |
| 304 | goto start | 354 | goto start |
| 305 | ''; | 355 | ''; |
| 306 | }) | 356 | }) |
| 307 | ]; | 357 | ]; |
| 308 | }) ["x86_64-linux"] | 358 | }) ["x86_64-linux"] |
| 309 | ) ++ [ | 359 | ) ++ [ |
| 310 | (pkgs.linkFarm "netbootxyz-efi" [ | 360 | (pkgs.runCommandLocal "utils" {} '' |
| 311 | { name = "netboot.xyz.efi"; path = pkgs.netbootxyz-efi; } | ||
| 312 | ]) | ||
| 313 | (pkgs.runCommandLocal "memtest" {} '' | ||
| 314 | mkdir $out | 361 | mkdir $out |
| 315 | install -t $out ${pkgs.memtest86plus}/memtest.efi | 362 | install -m 0444 -t $out \ |
| 363 | ${ipxe}/ipxe.efi ${ipxe}/i386-ipxe.efi ${ipxe}/undionly.kpxe \ | ||
| 364 | ${pkgs.memtest86plus}/memtest.efi ${pkgs.memtest86plus}/memtest.bin | ||
| 365 | install -m 0444 ${sources.netbootxyz-efi.src} $out/netboot.xyz.efi | ||
| 366 | install -m 0444 ${sources.netbootxyz-lkrn.src} $out/netboot.xyz.lkrn | ||
| 316 | '') | 367 | '') |
| 317 | (let | 368 | (let |
| 318 | eostreBuild = (flake.nixosConfigurations.eostre.extendModules { | 369 | eostreBuild = (flake.nixosConfigurations.eostre.extendModules { |
| @@ -335,32 +386,39 @@ in { | |||
| 335 | name = "eostre.menu.ipxe"; | 386 | name = "eostre.menu.ipxe"; |
| 336 | destination = "/eostre.menu.ipxe"; | 387 | destination = "/eostre.menu.ipxe"; |
| 337 | text = '' | 388 | text = '' |
| 389 | #!ipxe | ||
| 390 | |||
| 391 | cpair --background 9 1 | ||
| 392 | cpair --background 9 3 | ||
| 393 | cpair --background 9 6 | ||
| 394 | |||
| 338 | set menu-timeout 5000 | 395 | set menu-timeout 5000 |
| 339 | 396 | ||
| 340 | :start | 397 | :start |
| 341 | menu iPXE boot menu for eostre | 398 | menu iPXE boot menu for eostre |
| 342 | item eostre Boot eostre | 399 | item eostre eostre |
| 343 | item memtest memtest86plus | 400 | item memtest memtest86plus |
| 344 | item netboot netboot.xyz | 401 | item netboot netboot.xyz |
| 345 | item shell iPXE shell | 402 | item shell iPXE shell |
| 346 | choose --timeout ''${menu-timeout} --default eostre selected || goto shell | 403 | choose --timeout ''${menu-timeout} --default eostre selected || goto shell |
| 404 | set menu-timeout 0 | ||
| 347 | goto ''${selected} | 405 | goto ''${selected} |
| 348 | 406 | ||
| 349 | :shell | 407 | :shell |
| 350 | shell | ||
| 351 | set menu-timeout 0 | 408 | set menu-timeout 0 |
| 409 | shell | ||
| 352 | goto start | 410 | goto start |
| 353 | 411 | ||
| 354 | :eostre | 412 | :eostre |
| 355 | chain ${nfsrootBaseUrl}/eostre/netboot.ipxe | 413 | chain eostre/netboot.ipxe |
| 356 | goto start | 414 | goto start |
| 357 | 415 | ||
| 358 | :netboot | 416 | :netboot |
| 359 | chain --autofree ${nfsrootBaseUrl}/netboot.xyz.efi | 417 | iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn |
| 360 | goto start | 418 | goto start |
| 361 | 419 | ||
| 362 | :memtest | 420 | :memtest |
| 363 | chain --autofree ${nfsrootBaseUrl}/memtest.efi | 421 | iseq ''${platform} efi && chain --autofree memtest.efi || chain --autofree memtest.bin |
| 364 | goto start | 422 | goto start |
| 365 | ''; | 423 | ''; |
| 366 | }) | 424 | }) |
| @@ -374,14 +432,6 @@ in { | |||
| 374 | after = [ "network.target" ]; | 432 | after = [ "network.target" ]; |
| 375 | wantedBy = [ "multi-user.target" ]; | 433 | wantedBy = [ "multi-user.target" ]; |
| 376 | serviceConfig.ExecStart = let | 434 | serviceConfig.ExecStart = let |
| 377 | ipxe = pkgs.ipxe.override { | ||
| 378 | additionalTargets = { | ||
| 379 | "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi"; | ||
| 380 | }; | ||
| 381 | additionalOptions = [ | ||
| 382 | "NSLOOKUP_CMD" | ||
| 383 | ]; | ||
| 384 | }; | ||
| 385 | tftpRoot = pkgs.runCommandLocal "netboot" {} '' | 435 | tftpRoot = pkgs.runCommandLocal "netboot" {} '' |
| 386 | mkdir -p $out | 436 | mkdir -p $out |
| 387 | install -m 0444 -t $out \ | 437 | install -m 0444 -t $out \ |
