- Nix 99.1%
- Shell 0.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| hosts | ||
| modules | ||
| .gitignore | ||
| disko.nix | ||
| flake.lock | ||
| flake.nix | ||
| hardware-configuration.nix | ||
| README.md | ||
| update | ||
AGENTS.md
Stack
NixOS flake (nixpkgs nixos-unstable, disko). All configuration is Nix. No build step beyond nix commands.
Topology
Four NixOS hosts, all QEMU VMs with virtio interfaces:
- nixgw (
192.168.59.44) — upstream router / NAT gateway. Interfaces:uplink(wan),outside(10.0.0.1/24). - firewall1 (
.2octet) — active-active firewall. Interfaces:outside(10.0.0.2/24),inside(10.0.1.2/24),sync(10.1.1.2/24). Hostname on the box:fw2. - firewall2 (
.3octet) — active-active firewall peer. Same layout,.3octets. Hostname on the box:fw3. - internal (
10.0.1.1/24) — internal host, BGP neighbor to both firewalls.
BGP ASNs: nixgw=65000, firewalls=65001, internal=65002. Firewalls peer with each other over the outside link and with nixgw on outside, with internal on inside. Sync interface (10.1.1.0/24) carries conntrackd FT-FW UDP traffic (port 3781).
Modules
modules/common.nix— base config for every host (SSH, systemd-boot, nftables baseline, locale, root pubkey). Importshardware-configuration.nix.modules/nftables-firewall.nix— zone definitions and firewall-specific input rules (allows BFD 3784/udp, BGP 179/tcp, SSH 22/tcp, ICMP, conntrackd 3781/udp on sync).modules/firewall-interfaces.nix— interface + routing config for firewall hosts. TakesfirewallIp(just the .2/.3 octet, not the full IP).modules/bgp.nix— Bird3 BGP config generator. Definesmodules.bgp.sessionsoption; generates BFD + kernel + direct + static + BGP protocols.modules/conntrackd.nix— conntrackd HA sync for active-active pair (FT-FW mode over sync interface).
Host configs
hosts/<name>/default.nix imports the relevant modules and sets host-specific values (firewallIp, conntrackd peer, BGP session parameters). Hosts are auto-discovered from the hosts/ directory by flake.nix.
Commands
# Build all host configs (creates result-* symlinks in repo root)
nix build .#nixosConfigurations.nixgw.config.system.build.toplevel \
.#nixosConfigurations.firewall1.config.system.build.toplevel \
.#nixosConfigurations.firewall2.config.system.build.toplevel \
.#nixosConfigurations.internal.config.system.build.toplevel
# Deploy to all hosts (production order: nixgw first, then firewalls, then internal)
./update
# Dry-run a config before deploying
nixos-rebuild switch --flake .#firewall1 --target-host root@10.0.0.2 --dry-run
./update deploys in order: nixgw -> firewall1 -> firewall2 -> internal. Preserve this order — deploying firewalls before nixgw would cut off SSH to nixgw (its only routable access is via the firewall pair).
There is no nix flake check — the flake has no checks attribute.
Quirks
stateVersion = "26.05"is set inmodules/common.nix, not inhardware-configuration.nix(which only pulls in the qemu-guest profile).- All hosts use
networking.ifstate(notnetworking.interfaces) for interface configuration. - Each firewall host imports
hardware-configuration.nixviacommon.nix— this is the only place it's referenced. - All hosts use Bird3 (
pkgs.bird3); BGP uses a custom NixOS module (modules/nftables.nix) with zone/policy abstraction for generating nftables rulesets. modules.firewallInterfaces.firewallIpis the bare octet number ("2"or"3"), used to compose10.0.0.X/24and10.0.1.X/24— not the full IP.- Disk layout is fixed: GPT with 500M ESP at
/boot, remainder ext4 at/. Managed by disko. - IPv6 is disabled globally (
networking.enableIPv6 = false). - NAT/masquerade is only on nixgw (nftables
inet nattable). Firewall nftables ruleset has it commented out. resultandresult-*symlinks in the repo root are gitignored; they are build artifacts.