Files
nixos/modules/pxe-infra/bridge.nix
T
oqyude a940356e0a feat(pxe-infra): add isolated bridge + MAC-filtered DHCP module (L2)
Adds the L2 layer of the PXE pipeline test bed (docs/ARCHITECTURE.md
§L2) to rydiwo only — isolated private subnet, never touches LAN.

- modules/options.nix: options.pxe-infra.{enable, bridge, dhcp.*,
  guests[]} — fully typed, default master toggle is off so the
  existing rydiwo build is unchanged
- modules/pxe-infra/default.nix: umbrella that imports the two
  sub-modules; inert when the master toggle is off
- modules/pxe-infra/bridge.nix: idempotent systemd oneshot that
  creates the Linux bridge, assigns the lab host a private IPv4,
  and is explicitly NetworkManager.unmanaged so NM does not
  reconfigure it
- modules/pxe-infra/dhcp.nix: dnsmasq as DHCP-only on the bridge
  only (bind-interfaces + interface=, port=0 disables DNS, no-resolv,
  no-poll, cache-size=0); MAC-filtered via dhcp-host=…,set:known and
  dhcp-ignore=tag:!known when authoritative=false
- configurations/mini-laptop.nix: adds modules/pxe-infra to
  imports, plus a commented example showing how to enable for a
  real guest

Sidesteps docs/OPEN-QUESTIONS.md Q21 (LAN-permission) by design:
a fully isolated bridge satisfies L2 without the lab node answering
DHCP on the real LAN. nix flake check passes for all six hosts.

Refs: docs/ARCHITECTURE.md §L2, docs/OPEN-QUESTIONS.md F20/F21/F23.
2026-10-13 01:45:28 +03:00

63 lines
2.3 KiB
Nix

# pxe-infra/bridge — bring up the private Linux bridge the PXE
# VM attaches to.
#
# Why a systemd oneshot instead of systemd.networkd:
# rydiwo (and other desktop-class hosts in this flake) run
# NetworkManager (modules/desktop/default.nix), not systemd-
# networkd. We still want the bridge up at boot, regardless of
# LAN connectivity, so we drive the interface ourselves with
# the iproute2 `ip` command.
#
# Why NetworkManager.unmanaged:
# If NM were allowed to touch the bridge, it might try to
# reconfigure it (DHCP the bridge, replace the static IP we
# just set, or remove it entirely). Marking it unmanaged keeps
# NM out of our hair.
{
config,
lib,
pkgs,
...
}:
{
config = lib.mkIf config.pxe-infra.enable {
# NM must leave the bridge alone — we set it up ourselves.
networking.networkmanager.unmanaged = [ config.pxe-infra.bridge.name ];
# Order: bridge must be up before dnsmasq tries to bind to it.
systemd.services.pxe-infra-bridge = {
description = "pxe-infra: bring up ${config.pxe-infra.bridge.name} bridge";
wantedBy = [ "multi-user.target" ];
after = [ "systemd-modules-load.service" ];
wantedBefore = [ "dnsmasq.service" ];
path = [ pkgs.iproute2 ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
set -euo pipefail
# Idempotent bridge creation.
if ! ip link show dev ${config.pxe-infra.bridge.name} >/dev/null 2>&1; then
ip link add name ${config.pxe-infra.bridge.name} type bridge \
forward_delay 0 stp 0
fi
# Idempotent address assignment. Only rewrite the address
# if it isn't already what we expect — preserves state in
# case NM did something unexpected before this service ran.
if ! ip -j addr show dev ${config.pxe-infra.bridge.name} \
| grep -q '"${config.pxe-infra.bridge.address}"'; then
ip addr flush dev ${config.pxe-infra.bridge.name} || true
ip addr add ${config.pxe-infra.bridge.address}/${toString config.pxe-infra.bridge.prefixLength} \
dev ${config.pxe-infra.bridge.name}
fi
# Always make sure the link is up.
ip link set ${config.pxe-infra.bridge.name} up
'';
};
};
}