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).
This commit is contained in:
oqyude committed 2026-10-13 02:42:49 +03:00
1 parent 54a93f1e48
commit 5973aa74fd
3 files changed
+121

No files matched your search

+48
View File
@@ -286,5 +286,53 @@
'';
};
};
# VM: a single QEMU/KVM guest that PXE-boots through the
# bridge. Layer L4 of docs/ARCHITECTURE.md. The guest is
# intentionally disposable — no persistent disk, no NVRAM
# persistence, restart on crash — so every run starts from
# the same state, which is the rig's whole reason to exist.
vm = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to run a QEMU/KVM guest that PXE-boots through
the bridge. Disabled by default: enabling it spins up
the VM on boot, which the user may want to defer until
the artifact is staged.
'';
};
mac = lib.mkOption {
type = lib.types.str;
default = "52:54:00:12:34:56";
example = "52:54:00:12:34:56";
description = ''
MAC address of the guest's NIC. Choose from the
52:54:00:XX:XX:XX QEMU/OUI range. The same MAC must
appear in `dhcp.guests` when `dhcp.authoritative` is
false, otherwise the VM gets no lease.
'';
};
cpus = lib.mkOption {
type = lib.types.int;
default = 2;
example = 4;
description = ''
Number of virtual CPUs. Memory and CPU together cap
which tests can run on the rig (Phase 5 in
RUNNER-DESIGN.md).
'';
};
memory = lib.mkOption {
type = lib.types.str;
default = "2G";
example = "4G";
description = ''
RAM size in QEMU syntax (e.g. `2G`, `512M`). Caps the
testable memory in Phase 3 (RAM burnin).
'';
};
};
};
}
+1
View File
@@ -17,6 +17,7 @@
./bridge.nix
./dhcp.nix
./http.nix
./vm.nix
];
config = lib.mkIf config.pxe-infra.enable {
+72
View File
@@ -0,0 +1,72 @@
# pxe-infra/vm — QEMU/KVM guest that PXE-boots through the
# private bridge.
#
# Per docs/ARCHITECTURE.md §L4: the guest is intentionally
# disposable; every run starts from the same state, with no
# persistent disk. The boot source is the PXE services on L2/L3
# (dnsmasq for DHCP+TFTP, nginx for HTTP), so the VM is
# essentially a fancier ipxe-compatible client: nothing about
# its state affects the next run.
#
# Disposition:
# - Bridge attach via `-netdev bridge,br=pxe0`; this requires
# CAP_NET_ADMIN, which the systemd unit has as root.
# - UEFI firmware via OVMF (UEFI only — B.6). The combined
# `OVMF.fd` is mounted read-only, so the VM has no
# persistent NVRAM; every restart is a fresh boot, which is
# the property we want.
# - Boot order: network only (`-boot n`); no disk, no ISO.
# - `Restart=always` — failed or interrupted runs are safe to
# repeat without cleanup, per ARCHITECTURE.md §"Run
# lifecycle".
{
config,
lib,
pkgs,
...
}:
{
config = lib.mkIf (config.pxe-infra.enable && config.pxe-infra.vm.enable) {
environment.systemPackages = [ pkgs.qemu ];
systemd.services.pxe-infra-vm = {
description = "pxe-infra: PXE-boot QEMU/KVM guest (L4)";
wantedBy = [ "multi-user.target" ];
after = [
"pxe-infra-bridge.service"
"dnsmasq.service"
"nginx.service"
"network-online.target"
];
wants = [
"pxe-infra-bridge.service"
"dnsmasq.service"
"nginx.service"
];
path = [ pkgs.qemu ];
serviceConfig = {
Type = "simple";
Restart = "always";
RestartSec = "5s";
# The systemd unit runs as root — needed for the bridge
# attach (`-netdev bridge,br=...`).
};
script = ''
exec qemu-system-x86_64 \
-name pxe-infra-vm \
-machine type=q35,accel=kvm:tcg \
-cpu host \
-smp ${toString config.pxe-infra.vm.cpus} \
-m ${config.pxe-infra.vm.memory} \
-drive if=pflash,format=raw,readonly=on,file=${pkgs.OVMF.fd} \
-netdev bridge,id=net0,br=${config.pxe-infra.bridge.name} \
-device virtio-net-pci,netdev=net0,mac=${config.pxe-infra.vm.mac} \
-boot n \
-nographic \
-serial mon:stdio
'';
};
};
}