From c76e92e540522b9fe24254463c25b8d67eebfd84 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 29 Apr 2025 11:47:34 +0200 Subject: ... --- hosts/vidhar/network/dhcp/default.nix | 110 ++++++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 30 deletions(-) (limited to 'hosts/vidhar') 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 @@ -{ flake, config, pkgs, lib, ... }: +{ flake, config, pkgs, lib, sources, ... }: with lib; let nfsrootBaseUrl = "http://nfsroot.vidhar.yggdrasil"; + ipxe = pkgs.ipxe.override { + additionalTargets = { + "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi"; + }; + additionalOptions = [ + "NSLOOKUP_CMD" + "PING_CMD" + "CONSOLE_CMD" + ]; + embedScript = pkgs.writeText "yggdrasil.ipxe" '' + #!ipxe + + set user-class iPXE-yggdrasil + + dhcp + autoboot + ''; + }; in { config = { services.kea = { @@ -25,41 +43,67 @@ in { }; client-classes = [ - { name = "eostre-ipxe"; - test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and option[77].hex == 'iPXE'"; + { name = "ipxe-eostre"; + test = "hexstring(pkt4.mac, ':') == '00:d8:61:79:c5:40' and option[77].hex == 'iPXE-yggdrasil'"; next-server = "10.141.0.1"; boot-file-name = "${nfsrootBaseUrl}/eostre.menu.ipxe"; only-if-required = true; } - { name = "ipxe"; - test = "option[77].hex == 'iPXE'"; + { name = "ipxe-yggdrasil"; + test = "option[77].hex == 'iPXE-yggdrasil'"; next-server = "10.141.0.1"; boot-file-name = "${nfsrootBaseUrl}/installer-x86_64-linux.menu.ipxe"; only-if-required = true; } + + { name = "uefi-http"; + test = "option[client-system].hex == 0x0010"; + option-data = [ + { name = "vendor-class-identifier"; data = "HTTPClient"; } + ]; + boot-file-name = "${nfsrootBaseUrl}/ipxe.efi"; + only-if-required = true; + } + + { name = "ipxe-uefi-64"; + 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')"; + boot-file-name = "${nfsrootBaseUrl}/ipxe.efi"; + only-if-required = true; + } + { name = "ipxe-uefi-32"; + 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')"; + boot-file-name = "${nfsrootBaseUrl}/i386-ipxe.efi"; + only-if-required = true; + } + { name = "ipxe-legacy"; + test = "option[77].hex == 'iPXE' and substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; + boot-file-name = "${nfsrootBaseUrl}/undionly.kpxe"; + only-if-required = true; + } + { name = "uefi-64"; 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'"; - only-if-required = true; option-data = [ { name = "tftp-server-name"; data = "10.141.0.1"; } ]; boot-file-name = "ipxe.efi"; + only-if-required = true; } { name = "uefi-32"; test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00002' or substring(option[60].hex,0,20) == 'PXEClient:Arch:00006'"; - only-if-required = true; option-data = [ { name = "tftp-server-name"; data = "10.141.0.1"; } ]; boot-file-name = "i386-ipxe.efi"; + only-if-required = true; } { name = "legacy"; test = "substring(option[60].hex,0,20) == 'PXEClient:Arch:00000'"; - only-if-required = true; option-data = [ { name = "tftp-server-name"; data = "10.141.0.1"; } ]; boot-file-name = "undionly.kpxe"; + only-if-required = true; } ]; @@ -278,9 +322,15 @@ in { name = "installer-${system}.menu.ipxe"; destination = "/installer-${system}.menu.ipxe"; text = '' + #!ipxe + + cpair --background 9 1 + cpair --background 9 3 + cpair --background 9 6 + :start menu iPXE boot menu for installer-${system} - item installer Boot installer-${system} + item installer installer-${system} item memtest memtest86plus item netboot netboot.xyz item shell iPXE shell @@ -292,27 +342,28 @@ in { goto start :installer - chain ${nfsrootBaseUrl}/installer-${system}/netboot.ipxe + chain installer-${system}/netboot.ipxe goto start :netboot - chain --autofree ${nfsrootBaseUrl}/netboot.xyz.efi + iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn goto start :memtest - chain --autofree ${nfsrootBaseUrl}/memtest.efi + iseq ''${platform} efi && chain --autofree memtest.efi || chain --autofree memtest.bin goto start ''; }) ]; }) ["x86_64-linux"] ) ++ [ - (pkgs.linkFarm "netbootxyz-efi" [ - { name = "netboot.xyz.efi"; path = pkgs.netbootxyz-efi; } - ]) - (pkgs.runCommandLocal "memtest" {} '' + (pkgs.runCommandLocal "utils" {} '' mkdir $out - install -t $out ${pkgs.memtest86plus}/memtest.efi + install -m 0444 -t $out \ + ${ipxe}/ipxe.efi ${ipxe}/i386-ipxe.efi ${ipxe}/undionly.kpxe \ + ${pkgs.memtest86plus}/memtest.efi ${pkgs.memtest86plus}/memtest.bin + install -m 0444 ${sources.netbootxyz-efi.src} $out/netboot.xyz.efi + install -m 0444 ${sources.netbootxyz-lkrn.src} $out/netboot.xyz.lkrn '') (let eostreBuild = (flake.nixosConfigurations.eostre.extendModules { @@ -335,32 +386,39 @@ in { name = "eostre.menu.ipxe"; destination = "/eostre.menu.ipxe"; text = '' + #!ipxe + + cpair --background 9 1 + cpair --background 9 3 + cpair --background 9 6 + set menu-timeout 5000 :start menu iPXE boot menu for eostre - item eostre Boot eostre + item eostre eostre item memtest memtest86plus item netboot netboot.xyz item shell iPXE shell choose --timeout ''${menu-timeout} --default eostre selected || goto shell + set menu-timeout 0 goto ''${selected} :shell - shell set menu-timeout 0 + shell goto start :eostre - chain ${nfsrootBaseUrl}/eostre/netboot.ipxe + chain eostre/netboot.ipxe goto start :netboot - chain --autofree ${nfsrootBaseUrl}/netboot.xyz.efi + iseq ''${platform} efi && chain --autofree netboot.xyz.efi || chain --autofree netboot.xyz.lkrn goto start :memtest - chain --autofree ${nfsrootBaseUrl}/memtest.efi + iseq ''${platform} efi && chain --autofree memtest.efi || chain --autofree memtest.bin goto start ''; }) @@ -374,14 +432,6 @@ in { after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig.ExecStart = let - ipxe = pkgs.ipxe.override { - additionalTargets = { - "bin-i386-efi/ipxe.efi" = "i386-ipxe.efi"; - }; - additionalOptions = [ - "NSLOOKUP_CMD" - ]; - }; tftpRoot = pkgs.runCommandLocal "netboot" {} '' mkdir -p $out install -m 0444 -t $out \ -- cgit v1.2.3