From f7acbc68681062a57e4774a7efecc043a25d1c55 Mon Sep 17 00:00:00 2001 From: oqyude Date: Tue, 13 Oct 2026 03:32:16 +0300 Subject: [PATCH] fix(pxe-infra): put free pool in dhcp-range, not dhcp-host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dhcp-host and dhcp-range are different dnsmasq keys. The free-pool lines from the optional rangeStart/rangeEnd options were being concatenated into the dhcp-host list, which dnsmasq rendered as dhcp-host=52:54:00:12:34:56,10.66.0.10,pxe-vm-01,set:known dhcp-host=10.66.0.100,10.66.0.200,12h i.e. it would try to give IP 10.66.0.200 to the device whose MAC is 10.66.0.100. Even worse, with no dhcp-range at all, dnsmasq does not open its DHCP server socket — it only runs TFTP. The UEFI firmware in the VM would send DISCOVER and get nothing back, ending in PXE-E18: Server response timeout. Move the pool to its own list, with a sane default (the entire /24 minus the host address) so the server actually starts even when rangeStart/rangeEnd are left null. The MAC filter (dhcp-ignore=tag:!known) still prevents unknown MACs from getting a lease from the range. Co-authored-by: Sisyphus --- modules/pxe-infra/dhcp.nix | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/pxe-infra/dhcp.nix b/modules/pxe-infra/dhcp.nix index 6bd2c67..e7c4447 100644 --- a/modules/pxe-infra/dhcp.nix +++ b/modules/pxe-infra/dhcp.nix @@ -32,10 +32,20 @@ let in "${body},set:known") cfg.guests; - # Free address pool — only configured when both bounds are set. - rangeLines = lib.optionals - (cfg.rangeStart != null && cfg.rangeEnd != null) - [ "${cfg.rangeStart},${cfg.rangeEnd},${cfg.leaseTime}" ]; + # Free address pool. Always set so dnsmasq actually opens + # its DHCP server socket — without a `dhcp-range` line, dnsmasq + # silently runs TFTP only and the UEFI firmware's DHCP DISCOVER + # times out. The range is gated by the MAC filter + # (dhcp-ignore=tag:!known) below, so unknown MACs never see a + # lease, but the range must exist. + dhcp-range = + if cfg.rangeStart != null && cfg.rangeEnd != null + then [ "${cfg.rangeStart},${cfg.rangeEnd},${cfg.leaseTime}" ] + # Default: the entire bridge subnet minus the host address. + # Hardcoded for /24 because the bridge defaults to + # 10.66.0.1/24; if the bridge address/prefix changes, + # update this default. + else [ "10.66.0.2,10.66.0.254,12h" ]; base = { # Bind to the private bridge only — never 0.0.0.0, never eth0. @@ -52,8 +62,8 @@ let log-dhcp = true; log-queries = false; log-facility = "-"; - # Reservations + free pool (lists become repeated keys). - dhcp-host = dhcpHostLines ++ rangeLines; + # Static reservations. + dhcp-host = dhcpHostLines; }; # Optional TFTP module on the same dnsmasq instance. Used to