feat(pxe-infra): add TFTP (via dnsmasq) and HTTP (via nginx) — L3
Wires the L3 PXE services from docs/ARCHITECTURE.md into the
homelab flake. The DHCP module already running on the bridge gets
TFTP bolted on (same dnsmasq daemon, same interface binding); a
new nginx vhost serves kernel, initramfs, and rootfs over HTTP
from the same private bridge.
- modules/options.nix: new options.pxe-infra.{artifacts, http, tftp}
- artifacts.root defaults to /var/lib/pxe-infra; both servers
read from subdirs of that path
- http.{enable, port}: nginx listener (default port 80, bound
to the bridge IP only)
- tftp.enable: opt-out for the dnsmasq TFTP module
- modules/pxe-infra/dhcp.nix: when pxe-infra.tftp.enable, the
dnsmasq settings now include `enable-tftp` and `tftp-root=`.
No new daemon; the same bind-interfaces + interface= already
restricts the DHCP server to the bridge, and that carries
through to the TFTP server.
- modules/pxe-infra/http.nix: new file. services.nginx.enable
and a single vhost listening on the bridge IP, root at
artifacts.root/http, autoindex on. No default-server catch-all,
so requests on any other interface are refused at the listen
layer, not silently answered.
- modules/pxe-infra/default.nix: imports the new http.nix and
adds systemd-tmpfiles rules that create artifacts.root plus
its http/ and tftpboot/ subdirs at boot. The module does not
populate them — that is L5 (image build)'s job.
nginx does not speak TFTP (UDP/69, RFC 1350); TFTP stays with
dnsmasq where it shares the daemon with DHCP. ARCHITECTURE.md
L3 calls out TFTP+HTTP conflation as the mistake; DHCP+TFTP
sharing a daemon is a natural fit and avoids a second service
on the Chuwi MiniBook.
Refs: docs/ARCHITECTURE.md §L3, docs/OPEN-QUESTIONS.md
"Resolved (2026-10-13)" B.9/B.10.
This commit is contained in:
1 parent
a940356e0a
commit
54a93f1e48
4 files changed
+127
-4
No files matched your search
@@ -226,5 +226,65 @@
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# Where the boot artifacts land on disk. TFTP serves its
|
||||
# `tftpboot` subdirectory; HTTP serves its `http` subdirectory.
|
||||
# The contents themselves are produced elsewhere (mkosi under
|
||||
# build/mkosi/, see docs/OPEN-QUESTIONS.md B.9/B.10) and copied
|
||||
# in by whatever deployment step is in use.
|
||||
artifacts = {
|
||||
root = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/lib/pxe-infra";
|
||||
description = ''
|
||||
Local directory under which the boot artifacts (kernel,
|
||||
initramfs, rootfs/ISO, iPXE image) are expected to live.
|
||||
TFTP serves the `tftpboot` subdirectory; HTTP serves the
|
||||
`http` subdirectory. The pxe-infra module creates both
|
||||
subdirectories at boot via systemd-tmpfiles; it does not
|
||||
populate them.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# HTTP server: nginx, bound to the bridge IP only. Carries the
|
||||
# heavy payloads (kernel, initramfs, rootfs) per
|
||||
# docs/ARCHITECTURE.md §L3.
|
||||
http = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to enable nginx for HTTP serving of kernel,
|
||||
initramfs, and rootfs. Bound to the bridge interface only.
|
||||
'';
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 80;
|
||||
description = ''
|
||||
TCP port for the HTTP server. Bound to the bridge IP only,
|
||||
so it does not collide with any other HTTP service on the
|
||||
LAN.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# TFTP: piggybacks on the same dnsmasq instance as DHCP.
|
||||
# ARCHITECTURE.md L3 separates TFTP from HTTP (different roles,
|
||||
# different protocol); DHCP+TFTP sharing a daemon is a natural
|
||||
# fit and avoids spinning up a second service.
|
||||
tftp = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether dnsmasq should also serve TFTP for the iPXE boot
|
||||
image. Reuses the same daemon and bridge binding as DHCP
|
||||
(`bind-interfaces` + `interface=...` carry over). The
|
||||
serve root is `artifacts.root/tftpboot`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
# pxe-infra — isolated private network for PXE VM guests (L2 of
|
||||
# docs/ARCHITECTURE.md). Provides a Linux bridge plus a
|
||||
# MAC-filtered DHCP server so a fresh VM can netboot from this
|
||||
# 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
|
||||
@@ -8,11 +9,25 @@
|
||||
# this umbrella alone has no effect on a host that opts out.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = [
|
||||
./bridge.nix
|
||||
./dhcp.nix
|
||||
./http.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).
|
||||
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 - -"
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -56,7 +56,15 @@ let
|
||||
dhcp-host = dhcpHostLines ++ rangeLines;
|
||||
};
|
||||
|
||||
filtered = base // lib.optionalAttrs (!cfg.authoritative) {
|
||||
# Optional TFTP module on the same dnsmasq instance. Used to
|
||||
# hand out the iPXE bootloader (a few hundred KB) before the
|
||||
# client switches to HTTP for the kernel/initramfs/rootfs.
|
||||
tftpSettings = lib.optionalAttrs config.pxe-infra.tftp.enable {
|
||||
enable-tftp = true;
|
||||
tftp-root = "${config.pxe-infra.artifacts.root}/tftpboot";
|
||||
};
|
||||
|
||||
filtered = base // tftpSettings // 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,40 @@
|
||||
# pxe-infra/http — nginx serving kernel, initramfs, and rootfs
|
||||
# over HTTP, bound to the bridge interface only.
|
||||
#
|
||||
# Per docs/ARCHITECTURE.md §L3, HTTP is the carrier for everything
|
||||
# heavy: kernel, initramfs, rootfs, and ISO. TFTP is reserved for
|
||||
# the bootloader (iPXE) and lives in modules/pxe-infra/dhcp.nix
|
||||
# (same dnsmasq instance).
|
||||
#
|
||||
# The vhost listens on the bridge IP only, not 0.0.0.0, and no
|
||||
# default catch-all vhost is configured — a stray request to
|
||||
# nginx on any other interface is refused at the listen layer,
|
||||
# not silently answered.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
config = lib.mkIf (config.pxe-infra.enable && config.pxe-infra.http.enable) {
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
|
||||
virtualHosts."pxe-artifacts" = {
|
||||
listen = [{
|
||||
addr = config.pxe-infra.bridge.address;
|
||||
port = config.pxe-infra.http.port;
|
||||
}];
|
||||
root = "${config.pxe-infra.artifacts.root}/http";
|
||||
# Directory listing for the artifact tree. Lets the user
|
||||
# point a browser at the bridge IP to see what versions are
|
||||
# staged. No fancy autoindex formatting.
|
||||
extraConfig = ''
|
||||
autoindex on;
|
||||
autoindex_exact_size off;
|
||||
autoindex_localtime on;
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user