From 1d91e328ed1fb9d2ce77fde7b584f5a3176170f9 Mon Sep 17 00:00:00 2001 From: oqyude Date: Fri, 16 Oct 2026 00:42:55 +0300 Subject: [PATCH] feat(pxe-infra): split boot.ipxe (sanboot) from boot-bypass.ipxe (regression baseline) The former single boot.ipxe writeText block in modules/pxe-infra/ipxe.nix has been split into two static scripts under artifacts.root/http/: - boot.ipxe \u2014 production sanboot path. Chains to the alpine-worker raw image; OVMF walks the ESP, systemd-boot reads loader/entries/alpine.conf. - boot-bypass.ipxe \u2014 H_fix.1b regression baseline. kernel+initrd path; preserved byte-identical to the pre-split boot.ipxe content (matches the T10-h-fix-1b log shape on rydiwo 2026-10-14). autoexec.ipxe now selects the chain target via a new option: pxe-infra.bootloader.bypassFallback.enable (lib.types.bool, default false) When true, autoexec.ipxe chains to boot-bypass.ipxe; when false (default), to boot.ipxe. Both scripts are always staged (no mkIf gate) so the chain target flips with a config change + rebuild, no redeploy. In modules/pxe-infra/default.nix a new systemd-tmpfiles L+ rule mirrors the existing boot.ipxe rule for boot-bypass.ipxe. This unblocks H_fix.2 (real sanboot + POST end-to-end verification on rydiwo). The bypass path is the regression baseline \u2014 S4 in .agent/notes/H_fix.2-scenarios.md validates it still reaches the Alpine Init shell when the option is flipped. --- modules/pxe-infra/default.nix | 53 ++++++++++++++++++++-- modules/pxe-infra/ipxe.nix | 85 +++++++++++++++++++++++++++++++---- 2 files changed, 126 insertions(+), 12 deletions(-) diff --git a/modules/pxe-infra/default.nix b/modules/pxe-infra/default.nix index f0ee83c..ecce092 100644 --- a/modules/pxe-infra/default.nix +++ b/modules/pxe-infra/default.nix @@ -22,6 +22,42 @@ ./vm.nix ]; + # H_fix.2: chain-target option for autoexec.ipxe. + # + # Declared here (not in `modules/options.nix`) because this + # task's scope is `modules/pxe-infra/` only — `modules/options.nix` + # is outside that directory. NixOS modules merge option + # declarations across files, so adding a new sub-attr + # `bootloader.bypassFallback.enable` from this module is safe + # alongside the `bootloader.enable` / `bootloader.ipxeBinary` + # options already declared in `modules/options.nix`. + # + # H_fix.2-1+2: when `false` (default), autoexec.ipxe chains to + # `boot.ipxe` (production sanboot). When `true`, autoexec.ipxe + # chains to `boot-bypass.ipxe` (the H_fix.1b regression baseline: + # kernel+initrd, no sanboot). Both scripts are always staged + # (see ipxe.nix) — this option only flips the chain target. + options.pxe-infra.bootloader.bypassFallback = { + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + When true, `autoexec.ipxe` chains to `boot-bypass.ipxe` + (the H_fix.1b regression baseline — kernel+initrd, no + sanboot) instead of `boot.ipxe` (the production sanboot + path). Both scripts are always staged under + `artifacts.root/http/`; this option only flips the + chain target inside `autoexec.ipxe`. Set true to + reproduce the H_fix.1b regression shape with a single + config flip + rebuild, without touching `ipxe.nix`. + Defaults to false: operators who don't set it see no + behavior change beyond iPXE now running the sanboot + chain (which is the production path the rig was + designed for). + ''; + }; + }; + config = lib.mkIf config.pxe-infra.enable { # Create the artifact directory tree at boot. TFTP and HTTP # both serve from here; the actual artifacts land in this tree @@ -39,10 +75,19 @@ "d ${config.pxe-infra.artifacts.root}/tftpboot 0755 root root - -" "L+ ${config.pxe-infra.artifacts.root}/tftpboot/${config.pxe-infra.bootloader.ipxeBinary} - - - - /etc/static/pxe-infra/tftpboot/${config.pxe-infra.bootloader.ipxeBinary}" "L+ ${config.pxe-infra.artifacts.root}/http/boot.ipxe - - - - /etc/static/pxe-infra/http/boot.ipxe" - # autoexec.ipxe — chains to the HTTP-served boot.ipxe. iPXE - # in UEFI mode looks for `autoexec.ipxe` on the same TFTP - # server it was loaded from. The actual file is produced by - # ipxe.nix via pkgs.writeText and dropped under + # H_fix.2-1+2: boot-bypass.ipxe — the H_fix.1b regression + # baseline (kernel+initrd path). Mirrors the boot.ipxe rule + # above. Both scripts are always staged so the chain target + # can be flipped via `pxe-infra.bootloader.bypassFallback.enable` + # without re-deploying artifacts. See ipxe.nix for the + # writeText bodies and H_fix.2-9 for the regression scenario. + "L+ ${config.pxe-infra.artifacts.root}/http/boot-bypass.ipxe - - - - /etc/static/pxe-infra/http/boot-bypass.ipxe" + # autoexec.ipxe — chains to the HTTP-served chain target + # (boot.ipxe by default, boot-bypass.ipxe when + # `pxe-infra.bootloader.bypassFallback.enable = true`). + # iPXE in UEFI mode looks for `autoexec.ipxe` on the same + # TFTP server it was loaded from. The actual file is produced + # by ipxe.nix via pkgs.writeText and dropped under # /etc/static/pxe-infra/tftpboot/; this rule symlinks it into # the served root. See ipxe.nix and # .agent/notes/T10-diagnostic-2026-10-14.md. diff --git a/modules/pxe-infra/ipxe.nix b/modules/pxe-infra/ipxe.nix index 4e69867..877f21b 100644 --- a/modules/pxe-infra/ipxe.nix +++ b/modules/pxe-infra/ipxe.nix @@ -1,18 +1,26 @@ # pxe-infra/ipxe — stage the iPXE EFI binary into the TFTP root -# and write a static boot.ipxe script into the HTTP root. +# and write static boot scripts into the HTTP root. # # Together with the `dhcp-boot` option configured in dhcp.nix, # this completes the boot chain: # UEFI firmware # → TFTP: artifacts.root/tftpboot/ # → runs iPXE -# → HTTP: http:///boot.ipxe +# → HTTP: http:/// # → iPXE script sanboots the alpine-worker raw disk image +# (production path: boot.ipxe; regression path: boot-bypass.ipxe) +# +# Two static scripts are staged under artifacts.root/http/: +# - boot.ipxe — the production sanboot chain +# - boot-bypass.ipxe — the H_fix.1b regression baseline +# (kernel+initrd, no sanboot) +# Which one autoexec.ipxe chains to is controlled by +# `pxe-infra.bootloader.bypassFallback.enable` (see default.nix). # # The artifact itself is produced by build/mkosi/ in the # pxe-infra-automation repo and rsynced into # artifacts.root/http//. A `latest/` symlink points at the -# newest , which the static boot.ipxe references. +# newest , which boot.ipxe references. { config, lib, @@ -28,15 +36,68 @@ environment.etc."pxe-infra/tftpboot/${config.pxe-infra.bootloader.ipxeBinary}".source = "${pkgs.ipxe}/${config.pxe-infra.bootloader.ipxeBinary}"; - # Static iPXE script, served by the L3 HTTP server. iPXE - # fetches it via HTTP after the initial TFTP-boot of the - # binary itself. + # Static iPXE script — PRODUCTION SANBOOT PATH. + # + # This is the script autoexec.ipxe chains to by default + # (`pxe-infra.bootloader.bypassFallback.enable = false`). + # It sanboots the alpine-worker raw disk image and lets + # OVMF re-enter boot services so the image's ESP-resident + # systemd-boot (`BOOTX64.EFI` + `loader/loader.conf`) + # finishes the chain. The image is already sanboot-ready + # — verified by H_fix.2-3 against + # `build/alpine-worker/build.sh:135-185`. + # + # The companion `boot-bypass.ipxe` (staged below) is the + # H_fix.1b regression baseline: it bypasses sanboot + # entirely and uses the kernel+initrd path, which we know + # reaches the Alpine Init shell (T10). It is kept reachable + # behind `bypassFallback.enable` so a future regression + # in the sanboot chain can be reproduced with a single + # config flip + rebuild, without touching this file. + # autoexec.ipxe (further down) selects which of the two + # scripts to chain to based on that option. # # `''${...}''` is Nix's escape for a literal `${...}` in a # multi-line string; iPXE uses `${boot-url}` as its own # variable substitution, which must survive into the output # verbatim. environment.etc."pxe-infra/http/boot.ipxe".source = pkgs.writeText "boot.ipxe" '' + #!ipxe + set boot-url http://${config.pxe-infra.bridge.address}/latest + sanboot ''${boot-url}/alpine-worker.raw || goto retry_alpine + :retry_alpine + echo sanboot failed, retrying in 5s + sleep 5 + sanboot ''${boot-url}/alpine-worker.raw || goto shell + :shell + shell + ''; + + # Static iPXE script — H_fix.1b REGRESSION BASELINE. + # + # This is the original kernel+initrd bypass path, preserved + # byte-identical to the pre-split boot.ipxe content (the + # body matches `.agent/notes/T10-diagnostic-2026-10-14.md` + # lines 130-142 and + # `.agent/notes/T10-h-fix-1b-pxe-with-autoexec-2026-10-14.log` + # regression shape). It bypasses sanboot entirely; the + # kernel panics on rootfs (no /dev/sda* in this build), + # but the journal shows kernel boot output — enough to + # confirm iPXE's chain works end-to-end and rule out + # iPXE's HTTP/sanboot code as the source of any persistent + # #GP. + # + # autoexec.ipxe chains to this script when + # `pxe-infra.bootloader.bypassFallback.enable = true`. + # Both scripts are always staged (no mkIf gate) so the + # chain target can be swapped with a config flip + rebuild + # without re-deploying artifacts. + # + # `''${...}''` is Nix's escape for a literal `${...}` in a + # multi-line string; iPXE uses `${boot-url}` as its own + # variable substitution, which must survive into the output + # verbatim. + environment.etc."pxe-infra/http/boot-bypass.ipxe".source = pkgs.writeText "boot-bypass.ipxe" '' #!ipxe set boot-url http://${config.pxe-infra.bridge.address}/latest # Test path: bypass sanboot entirely. Load the Alpine @@ -56,12 +117,20 @@ initrd ''${boot-url}/initramfs-virt boot ''; + # autoexec.ipxe — iPXE on UEFI looks for `autoexec.ipxe` on the # same TFTP server it was loaded from, and runs it as the boot # script. Without it, the iPXE instance that replaced the # firmware PXE ROM has nothing to chain to and ends up in # "No more network devices" -> #GP (T10). This is a one-liner - # that bridges to the HTTP-served boot.ipxe. + # that bridges to the HTTP-served chain target. + # + # Chain target depends on + # `pxe-infra.bootloader.bypassFallback.enable`: + # false (default) → boot.ipxe + # (production sanboot path) + # true → boot-bypass.ipxe + # (H_fix.1b regression baseline) # # Discovered 2026-10-14 via the H1 reproduction in # .agent/notes/T10-diagnostic-2026-10-14.md (pxe-infra-automation @@ -70,7 +139,7 @@ # before even reaching boot.ipxe. environment.etc."pxe-infra/tftpboot/autoexec.ipxe".source = pkgs.writeText "autoexec.ipxe" ''#!ipxe -chain http://${config.pxe-infra.bridge.address}/boot.ipxe +chain http://${config.pxe-infra.bridge.address}/${if config.pxe-infra.bootloader.bypassFallback.enable then "boot-bypass.ipxe" else "boot.ipxe"} ''; }; }