feat(pxe-infra): stage iPXE EFI + boot.ipxe — completes the boot chain
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.
This commit is contained in:
1 parent
5973aa74fd
commit
d7e46a4e89
4 files changed
+95
-1
No files matched your search
@@ -334,5 +334,33 @@
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# iPXE bootloader staging. Bridges the UEFI firmware (which
|
||||
# speaks TFTP only) to the L3 HTTP server (which serves the
|
||||
# actual image). Without this, the L4 VM gets a DHCP lease
|
||||
# but has no filename to TFTP-fetch, so the chain stops there.
|
||||
bootloader = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to stage the iPXE EFI binary into the TFTP root
|
||||
and write the static boot.ipxe script into the HTTP
|
||||
root. Off disables the entire L4 boot chain.
|
||||
'';
|
||||
};
|
||||
ipxeBinary = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "ipxe.efi";
|
||||
description = ''
|
||||
Filename of the iPXE EFI binary under the TFTP root.
|
||||
The actual binary is taken from `pkgs.ipxe`; this only
|
||||
controls the served filename and the `filename` DHCP
|
||||
option handed to UEFI firmware. Defaults to the
|
||||
universal UEFI binary; `snp.efi` is a smaller variant
|
||||
that works on virtio-net only.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
./bridge.nix
|
||||
./dhcp.nix
|
||||
./http.nix
|
||||
./ipxe.nix
|
||||
./vm.nix
|
||||
];
|
||||
|
||||
@@ -25,10 +26,18 @@
|
||||
# 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"
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -64,7 +64,15 @@ let
|
||||
tftp-root = "${config.pxe-infra.artifacts.root}/tftpboot";
|
||||
};
|
||||
|
||||
filtered = base // tftpSettings // lib.optionalAttrs (!cfg.authoritative) {
|
||||
# Boot filename: when the iPXE binary is staged, hand it to
|
||||
# UEFI firmware in the DHCP offer so the firmware knows what
|
||||
# to TFTP-fetch. Sent to all clients; the `tag:!known` filter
|
||||
# below still drops requests from unknown MACs.
|
||||
bootSettings = lib.optionalAttrs (config.pxe-infra.tftp.enable && config.pxe-infra.bootloader.enable) {
|
||||
dhcp-boot = config.pxe-infra.bootloader.ipxeBinary;
|
||||
};
|
||||
|
||||
filtered = base // tftpSettings // bootSettings // lib.optionalAttrs (!cfg.authoritative) {
|
||||
# Drop any DHCP request not carrying the `known` tag we set on
|
||||
# static hosts. This is the MAC filter that keeps the rig
|
||||
# from accidentally serving strangers if a real-LAN packet
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# pxe-infra/ipxe — stage the iPXE EFI binary into the TFTP root
|
||||
# and write a static boot.ipxe script 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/<ipxeBinary>
|
||||
# → runs iPXE
|
||||
# → HTTP: http://<bridge.address>/boot.ipxe
|
||||
# → iPXE script sanboots the alpine-worker raw disk image
|
||||
#
|
||||
# The artifact itself is produced by build/mkosi/ in the
|
||||
# pxe-infra-automation repo and rsynced into
|
||||
# artifacts.root/http/<rev>/. A `latest/` symlink points at the
|
||||
# newest <rev>, which the static boot.ipxe references.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
config = lib.mkIf (config.pxe-infra.enable && config.pxe-infra.bootloader.enable) {
|
||||
# iPXE binary from nixpkgs. We drop it under
|
||||
# /etc/static/pxe-infra/tftpboot/ via environment.etc; the
|
||||
# tmpfiles rule in default.nix symlinks from there into the
|
||||
# actual served TFTP root.
|
||||
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.
|
||||
#
|
||||
# `''${...}''` 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
|
||||
:retry
|
||||
echo sanboot failed, retrying in 5s
|
||||
sleep 5
|
||||
sanboot ''${boot-url}/alpine-worker.raw
|
||||
'';
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user