Commit Graph
12 Commits
Author SHA1 Message Date
opencode 33bc04e6ef fix(pxe-infra): move the e1000 rationale out of the continued qemu command
test-runner / smoke (push) Successful in 1s
A '#' comment inside a backslash-continued shell command is not a
comment: the shell swallowed the rest of the script, so qemu started
without the -device line ('netdev net0 has no peer'). The rationale now
sits above the exec.
2026-10-21 21:03:03 +03:00
opencode 456236792f fix(pxe-infra): give the rig guest an e1000 NIC instead of virtio-net (T24)
test-runner / smoke (push) Successful in 1s
With virtio-net the guest's OVMF claims the device with its own
virtio-net driver and exposes no SNP handle, so iPXE falls back to its
own virtio-net driver and cannot open the device the firmware already
holds. The interface stays closed, the routes are marked inaccessible
and every HTTP fetch fails with 'Network unreachable' - the chain dies
before the payload is even fetched.

Measured on rydiwo 2026-10-21 with the diagnostic autoexec.ipxe:

  virtio-net-pci: net0: ... using virtio-net ... [closed]
                   route: net0: 10.66.0.10/255.255.255.0 gw 10.66.0.1 (inaccessible)
                   ping: timeout ; http://10.66.0.1/boot.ipxe... Network unreachable

  e1000:           net0: ... using 82540em ... [open]
                   route: net0: 10.66.0.10/255.255.255.0 gw 10.66.0.1
                   ping: replies ; boot.ipxe / vmlinuz-virt / initramfs-virt all ok

The guest kernel is unaffected: linux-virt ships e1000.ko and the
read-only payload loads it from the rootfs.
2026-10-21 20:59:16 +03:00
oqyude 25baa2c503 feat(pxe-infra): use qemu-bridge-helper with setuid wrapper (T13)
Replace the manual `ip tuntap add` + `ip link set master` pattern in the
VM service with the standard `-netdev bridge,helper=...` approach. This
removes the bespoke tap lifecycle from the systemd script and uses
qemu's own bridge helper for TAP creation/teardown.

What changed in vm.nix:
  - Added security.wrappers.qemu-bridge-helper: a setuid root wrapper
    at /run/wrappers/bin/qemu-bridge-helper that execs the nixpkgs
    binary (${pkgs.qemu}/libexec/qemu-bridge-helper).
  - Added /etc/qemu/bridge.conf restricting the helper to the pxe0
    bridge (single `allow pxe0` line).
  - Added /run/wrappers/bin to the service PATH and `helper=` option
    on -netdev bridge, so qemu finds the wrapper.
  - Removed the tap creation in the script and the teardown in
    postStop — qemu-bridge-helper handles both.
  - Inlined `chmod 4755` on the wrapper at the top of the service
    script. The security.wrappers activation script in this NixOS
    version (qemu 11.1.1, edk2 202608) doesn't always apply the
    setuid bit, leaving the wrapper at mode 0511 which makes the
    helper fail to create the TAP. The inlined chmod is idempotent
    and runs as root (system service). Remove this once upstream
    NixOS is fixed.

Verified 2026-10-14 on rydiwo:
  - direct mode: VM boots, tap0 (created by helper) attaches to
    pxe0, all network up.
  - pxe mode: iPXE chain works end-to-end through the bridge —
    snp.efi -> autoexec.ipxe -> boot.ipxe (vmlinuz-virt Not found is
    expected; /latest/ copies were cleaned up after the H_fix.1b
    test).

T10 fix (autoexec.ipxe on TFTP root) is independent and already
committed (7c9a8d8 + syntax fix ae14fec). Closes T13.
2026-10-14 14:32:08 +03:00
oqyude ce1b0da32d pxe-infra: add vm.bootMode option (direct | pxe)
The default "direct" preserves the proven E2E behavior
(2026-10-13). "pxe" enables the full L3 boot chain
(-boot n, no virtio drive) for reproducing T10 (iPXE 2.0.0
#GP at ExitBootServices, RIP 0x7EE8A5FC) and verifying any
fix. Switch modes by editing pxe-infra.vm.bootMode in
configurations/rydiwo and running nixos-rebuild switch —
no other changes needed.
2026-10-14 14:32:08 +03:00
oqyude dfb7830d75 nix flake update 2026-10-13 16:16:20 +03:00
oqyude a3c94906e9 feat(pxe-infra): boot VM from local image, not via iPXE sanboot
iPXE 2.0.0 reliably #GPs at RIP 0x7EE8A5FC (RAX=0xAF...AF) when handing off a 1-2 GB raw image back to the firmware under QEMU/OVMF, regardless of whether the boot primitive is sanboot, imgfetch+boot, or kernel+initrd+boot, regardless of iPXE binary (universal or snp-only), and regardless of VM memory (2G or 4G). The image itself is fine (kernel+initrd extract cleanly, BOOTX64.EFI is in the ESP, systemd-boot config is set up). The crash is in iPXE 2.0.0 `s exit-to-firmware path under this QEMU/OVMF combination.

Workaround: attach the Alpine worker image as a local virtio drive in the QEMU command line. The firmware (OVMF) finds BOOTX64.EFI in the image's ESP and boots the kernel from the image's ext4 partition. The network is still there (pxe0-tap, dnsmasq, nginx, report-sink), so the runner inside the guest can still POST to the report-sink and the VM can still talk to the L2/L3 services at runtime. The image attached is the same artifact nginx serves for the real PXE rig (the `latest` symlink at `artifacts.root/http/latest/`); deploy.sh keeps both paths in sync.

Refs: docs/ARCHITECTURE.md section L4.
2026-10-13 04:23:27 +03:00
oqyude 55505fa1c5 fix(pxe-infra): split OVMF CODE+VARS so the firmware can chain
iPXE loaded boot.ipxe and tried to sanboot the Alpine raw image, but the firmware raised a #GP fault at RIP 0x7EC8B5FC with RAX=0xAF...AF. The AF pattern in RAX is a tell: it is the poisoned-memory value QEMU leaves in regions the firmware has not initialised. The combined OVMF.fd is read-only and carries no NVRAM region the firmware can write to, so ExitBootServices during the iPXE-to-image handoff cannot record its boot variables and the firmware crashes.

Switch to the split CODE+VARS form that nixpkgs ships: mount OVMF_CODE.fd read-only, seed a writable copy of OVMF_VARS.fd at /var/lib/pxe-infra/ovmf-vars.bin on first run, and pass it as a second pflash drive. iPXE can then write the chain target into NVRAM and the firmware hands off cleanly.

Refs: docs/ARCHITECTURE.md section L4.
2026-10-13 03:38:34 +03:00
oqyude a1aaa46908 fix(pxe-infra): script=no,downscript=no on the tap netdev
By default  invokes /etc/qemu-ifup
after opening the tap (and /etc/qemu-ifdown on shutdown).
That script does not exist on a stock NixOS install, and
QEMU fails with:
  network script /etc/qemu-ifup failed with status 256

The pre-start already brings the tap up (ip link set … up)
and the postStop tears it down, so we tell QEMU not to
call out to /etc/qemu-if{up,down} via script=no,
downscript=no.
2026-10-13 03:27:31 +03:00
oqyude 4f69d96e4e fix(pxe-infra): use tap+bridge-attach instead of -netdev bridge
QEMU's `-netdev bridge,br=pxe0` delegates the actual
`brctl addif` to a setuid qemu-bridge-helper binary, paired
with an /etc/qemu/bridge.conf ACL file. The current nixpkgs
does not ship a NixOS module for installing that wrapper
(nixpkgs has qemu-guest-agent.nix — a different thing, the
in-VM guest agent) so the default is to fail with:

  failed to parse default acl file /etc/qemu/bridge.conf
  -netdev bridge,…: bridge helper failed

The standard workaround is the same pattern NixOS itself
uses in qemu-vm.nix for test VMs: create a tap device
before QEMU starts, attach it to the bridge ourselves (we
already have CAP_NET_ADMIN as root in the systemd unit),
and pass `-netdev tap,ifname=…` to QEMU. No helper needed.

- modules/pxe-infra/vm.nix: switch to `-netdev tap,
  ifname=pxe0-tap`; pre-start script idempotently tears
  down any leftover tap, creates a new one, and attaches
  it to the configured bridge. `postStop` removes the tap
  on every stop (including crashes / restart cycles).
- modules/pxe-infra/bridge.nix: drop the no-op
  `services.qemuGuest.enable = true;` (option doesn't exist
  in this nixpkgs).
2026-10-13 03:25:12 +03:00
oqyude e70fde4e04 fix(pxe-infra): point OVMF pflash at the firmware file, not the dir
nixpkgs OVMF.fd is a multi-output derivation whose outPath is
a *directory* containing FV/OVMF.fd (combined CODE+VARS),
FV/OVMF_CODE.fd, FV/OVMF_VARS.fd, and share/. QEMU needs a
regular file for -drive if=pflash,format=raw,readonly=on,
and rejected the directory with:

  'file' driver requires '.../OVMF-202608-fd'
  to be a regular file

Use the combined FV/OVMF.fd (4 MB, CODE+VARS in one).
Mounted read-only so the VM has no persistent NVRAM, which
is what we want for a fresh-every-run rig (docs/ARCHITECTURE.md
§L4). For proper NVRAM persistence across runs, the split
CODE+VARS form with a per-VM writable VARS file would be the
next step; not needed yet.
2026-10-13 03:17:27 +03:00
oqyude 85953f9b3d feat(pxe-infra): add vm.autostart option (default false)
The QEMU/KVM guest was unconditionally
`wantedBy = [ "multi-user.target" ]`, which means it would
have come up on every boot of rydiwo. The intent is the
opposite for now: the VM is for script-development iteration,
not a permanent rig. We want to start it by hand
(`systemctl start pxe-infra-vm`) when a test session needs
it, and stop it the same way.

- modules/options.nix: new options.pxe-infra.vm.autostart
  (default false). Describes when to flip it on (long
  unattended test runs) and that the unit itself is
  always present when pxe-infra.vm.enable is true.

- modules/pxe-infra/vm.nix: wantedBy is now
  `lib.optional config.pxe-infra.vm.autostart "multi-user.target"`,
  so with autostart=false the unit is reachable via
  `systemctl start` but not pulled in by multi-user.target.

- configurations/mini-laptop.nix: commented example now
  shows the `vm.autostart = false` form, and the surrounding
  comment documents the manual-start workflow.
2026-10-13 03:09:18 +03:00
oqyude 5973aa74fd feat(pxe-infra): add QEMU/KVM guest module — L4
Wires the L4 guest VM from docs/ARCHITECTURE.md into the homelab
flake. The guest is the consumer of the L2 (bridge + DHCP) and L3
(TFTP + HTTP) plumbing committed earlier; it PXE-boots through the
private bridge with a fixed MAC, no disk, no persistent NVRAM.

- modules/options.nix: new options.pxe-infra.vm
  - enable: master switch (default false; turning it on spins up
    the VM on every boot, which the user may want to defer until
    an artifact is staged)
  - mac: guest NIC MAC (default 52:54:00:12:34:56; must also
    appear in pxe-infra.dhcp.guests when authoritative=false)
  - cpus: vCPU count
  - memory: RAM size in QEMU syntax (e.g. "2G")

- modules/pxe-infra/vm.nix: new file. A systemd service running
  qemu-system-x86_64 with:
  - machine type=q35 + accel=kvm:tcg (TCG fallback if KVM is
    not available on the host)
  - OVMF.fd as a read-only pflash drive (UEFI only — B.6); the
    combined fd has no NVRAM region, so every restart is a
    fresh boot, which is the property ARCHITECTURE.md §L4 wants
  - netdev=bridge,br=pxe0 attaching the guest's virtio-net to
    the L2 bridge, with the fixed MAC
  - -boot n: network only, no disk, no ISO
  - Restart=always, RestartSec=5s — failed/interrupted runs are
    safe to repeat (per ARCHITECTURE.md "Run lifecycle")

- modules/pxe-infra/default.nix: imports the new vm.nix.

Refs: docs/ARCHITECTURE.md §L4, docs/OPEN-QUESTIONS.md
"Resolved (2026-10-13)" B.6 (UEFI only).
2026-10-13 02:42:49 +03:00