Wires the missing piece between the L3 services and the L4 VM:
the firmware does DHCP+TFTP-fetch of an iPXE binary, then iPXE
fetches a static boot.ipxe script over HTTP, which sanboots the
alpine-worker raw image. Without this, the VM has a DHCP lease
but no filename to TFTP-fetch, so the chain stops at the
firmware.
- modules/options.nix: new options.pxe-infra.bootloader
- enable: master switch (default true)
- ipxeBinary: filename under tftpboot/ (default "ipxe.efi",
the universal UEFI binary from pkgs.ipxe; "snp.efi" is a
smaller virtio-net-only alternative)
- modules/pxe-infra/ipxe.nix: new file.
- environment.etc drops pkgs.ipxe's binary under
/etc/static/pxe-infra/tftpboot/<ipxeBinary>, plus a static
boot.ipxe script under /etc/static/pxe-infra/http/.
- The script uses iPXE's own ${boot-url} variable substitution
(escaped with Nix's ''${...}'' so it survives into the
output verbatim) to sanboot http://<bridge.address>/latest/
alpine-worker.raw, with a 5s retry on failure.
- modules/pxe-infra/dhcp.nix: when both pxe-infra.tftp.enable
and pxe-infra.bootloader.enable are on, dnsmasq settings now
include `dhcp-boot=<ipxeBinary>`. The MAC filter (tag:!known)
still drops requests from unknown MACs before they can use the
filename.
- modules/pxe-infra/default.nix: imports ipxe.nix and adds two
`L+` tmpfiles rules that symlink the iPXE binary and the
boot.ipxe script from /etc/static/pxe-infra/... into the
served TFTP/HTTP roots. `L+` (instead of plain `L`) means
systemd-tmpfiles will update the symlink target on every
boot, so pkgs.ipxe upgrades via nixos-rebuild take effect
without redeploying anything.
Refs: docs/ARCHITECTURE.md §L3, §L4.
44 lines
1.7 KiB
Nix
44 lines
1.7 KiB
Nix
# pxe-infra — isolated private network for PXE VM guests (L2/L3 of
|
|
# docs/ARCHITECTURE.md). Provides a Linux bridge, a MAC-filtered
|
|
# DHCP server, a TFTP server (iPXE bootloader), and an HTTP server
|
|
# (kernel/initramfs/rootfs), so a fresh VM can netboot from this
|
|
# host without touching the real LAN.
|
|
#
|
|
# Master toggle: `pxe-infra.enable`. Submodules guard their own
|
|
# config with `lib.mkIf config.pxe-infra.enable`, so importing
|
|
# this umbrella alone has no effect on a host that opts out.
|
|
{
|
|
config,
|
|
lib,
|
|
...
|
|
}:
|
|
{
|
|
imports = [
|
|
./bridge.nix
|
|
./dhcp.nix
|
|
./http.nix
|
|
./ipxe.nix
|
|
./vm.nix
|
|
];
|
|
|
|
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
|
|
# by whatever means (manual copy, deploy step, mkosi output
|
|
# directory — see docs/OPEN-QUESTIONS.md B.9/B.10).
|
|
#
|
|
# The `L+` rules symlink the iPXE binary and boot.ipxe script
|
|
# from /etc/static/pxe-infra/... (where the ipxe.nix module
|
|
# drops them via environment.etc) into the served roots, so
|
|
# `nixos-rebuild` upgrades of pkgs.ipxe are picked up at the
|
|
# next boot without redeploying anything.
|
|
systemd.tmpfiles.rules = [
|
|
"d ${config.pxe-infra.artifacts.root} 0755 root root - -"
|
|
"d ${config.pxe-infra.artifacts.root}/http 0755 root root - -"
|
|
"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"
|
|
];
|
|
};
|
|
}
|