Active-Active Firewall Cluster
  • Nix 99.1%
  • Shell 0.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Göran Heinemann 52d6ce9625 readme
2026-08-14 15:14:58 +02:00
hosts allow irtt traffic in all required firewalls 2026-08-14 15:12:56 +02:00
modules allow irtt traffic in all required firewalls 2026-08-14 15:12:56 +02:00
.gitignore cleanup 2026-08-06 13:06:45 +02:00
disko.nix wirking disko 2026-08-05 11:23:01 +02:00
flake.lock flake.lock: Update 2026-08-12 13:33:39 +02:00
flake.nix multihost flake 2026-08-05 11:50:21 +02:00
hardware-configuration.nix add nftables and formatting 2026-08-05 11:33:03 +02:00
README.md readme 2026-08-14 15:14:58 +02:00
update update gw ip 2026-08-13 11:34:39 +02:00

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 (.2 octet) — 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 (.3 octet) — active-active firewall peer. Same layout, .3 octets. 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). Imports hardware-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. Takes firewallIp (just the .2/.3 octet, not the full IP).
  • modules/bgp.nix — Bird3 BGP config generator. Defines modules.bgp.sessions option; 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 in modules/common.nix, not in hardware-configuration.nix (which only pulls in the qemu-guest profile).
  • All hosts use networking.ifstate (not networking.interfaces) for interface configuration.
  • Each firewall host imports hardware-configuration.nix via common.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.firewallIp is the bare octet number ("2" or "3"), used to compose 10.0.0.X/24 and 10.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 nat table). Firewall nftables ruleset has it commented out.
  • result and result-* symlinks in the repo root are gitignored; they are build artifacts.