The last layer of the boot-and-report pipeline. Per
docs/ARCHITECTURE.md §L6, the report sink must survive the VM
disappearing — anything inside the guest is gone the moment the
VM tears down. This module provides that place: a minimal HTTP
service bound to the bridge IP that accepts run reports and
writes them to disk atomically.
- modules/options.nix: new options.pxe-infra.reportSink
- enable: master switch (default true)
- port: TCP port (default 8080; unprivileged so DynamicUser
can run the daemon without CAP_NET_BIND_SERVICE)
- modules/pxe-infra/report-sink.py: new file, the actual
service. Python stdlib only (no third-party deps, no version
drift, no extra security surface). Endpoints:
POST /report — body is JSON with at least `run_id`; the
file is written atomically (temp + rename)
to /var/lib/pxe-infra/reports/<run_id>.json
GET /health — returns "ok" for liveness checks
A 1 MB body cap is plenty for any structured run report
per RUNNER-DESIGN.md. Path-traversal hardening: run_id must
match [A-Za-z0-9_-]+.
- modules/pxe-infra/report-sink.nix: new file, the Nix module
that wraps report-sink.py. systemd service with:
- DynamicUser + StateDirectory="pxe-infra/reports": no
persistent system-user state, the daemon writes into
/var/lib/pxe-infra/reports/ as a throwaway UID
- NoNewPrivileges, ProtectSystem=strict, ProtectHome,
PrivateTmp, RestrictAddressFamilies=AF_INET{,6}: only
needs to bind a TCP socket and write one file
- Environment sets REPORTS_BIND to the bridge IP, so the
daemon never accidentally listens on 0.0.0.0
- modules/pxe-infra/default.nix: imports the new module.
Refs: docs/ARCHITECTURE.md §L6, docs/RUNNER-DESIGN.md
"Result object".
45 lines
1.7 KiB
Nix
45 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
|
|
./report-sink.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"
|
|
];
|
|
};
|
|
}
|