Do you use NixOS on your router/firewall?

I’m thinking about using NixOS for a home router. (or vanlife)
Or use non declarative OPNsense?
Has anyone done this successfully before? or am I in uncharted waters?
What hardware did you use?

The things I’m thinking about
possibilities:

  • multiple rj45 1G
  • dual wifi 2.4 & 5
  • sims: 1 or 2 (1 or 2 modems)
  • x86 or aarch
  • low power
  • ecc memory (zfs)
  • open source

more advanced/future proof:

  • rj45 10G
  • sfp

software:

  • auto boot after power failure / unencrypted disk
  • firewall
  • forward some traffic to home server
  • wireguard vpn(some home server services only available behind vpn)
  • traffic shaping / failover / management rules ?
  • adguard
2 Likes

I do, but it’s not handling WiFi or switching. I have a Raspberry Pi Compute Module 4 on this DFRobot router carrier board acting as NAT, DHCP server, and DNS server on my local network. It plugs into a Ubiquiti switch that powers two Ubiquiti wireless access points. So it’s not full NixOS like I’d like, but I had a really hard time finding acceptable hardware for a good DIY WiFi AP.

It works great though. I had to fumble about getting NixOS to boot on it because the CM4 wasn’t supported at the time, but it should work with the standard SD image as of a week or so ago. I tested it with devices on either side of the NAT and it was able to get full gigabit speed across it.

And I really like having NixOS on the thing. More than once, I’ve made use of NixOS’s ability to rollback generations in the boot loader. I also have the root fs on ZFS (sidenote: You don’t need ECC for ZFS; that’s a myth. I’m running ZFS on a pi on an SD card. You’ll be fine). All in all, great experience, would recommend, as long as your hardware is well supported.

3 Likes

Hows the VPN performance on the Pi?
I thought about replacing my aging PC Engine APU with a similar setup to yours.

I don’t really use it for VPN in any meaningful capacity. It is on my tailscale account though, just so I can remote into it easily when necessary. Testing iperf3 over that, looks like I get about 200Mbps over the gigabit link between my desktop and the pi, if that’s any indication of how well it handles encrypting network traffic.

1 Like

Thank you, that should be enough for my use case :slight_smile:
Now I only have to wait for the Pis to become available…

@mackenzie a lot of people use these for home built routers but I don’t really know how up to date the hardware is and if it works with NixOS.

However I can tell you that they are running quite well.
Once you managed to install them, only possible with serial console…

I saw francis’s blog about an apu2e4 and nixos.
Though he doesn’t mention wifi.

2 Likes

They support it that much I know.
No idea about the performance however.

You can configure a wifi access point on NixOS with hostapd. I’ve done it with the Pi’s wifi interface, and it does work. But the hard part is getting good wifi hardware for the task, particularly if you want a dual-band network.

I use NixOS on my router. You can see the config here. I use a Protectli Vault firewall appliance for my router. Wi-Fi is handled by a pair of Orbis in AP mode.

2 Likes

I’m thinking about using NixOS for a home router. (or vanlife) Or use non declarative OPNsense? Has anyone done this successfully before? or am I in uncharted waters?

I’m using both which obviously both come with their own pros and cons.

The NixOS router is for home use. Having a canonical source of truth for your network and using that to generate DNS/DHCP configuration and so on is just fantastic. Current software:

  • dnsmasq for DNS/DHCP
  • VPN (wireguard)
  • mosquitto (MQTT broker)
  • mitmproxy

The main “pro” is of course that you can make it do anything you need. The largest downside compared to OPNsense (which we’re currently using for work and it’s awesome - it’s far better than any of the watchguard, sophos, fortinet stuff you can otherwise find) is that OPNsense will let you know when you try to apply an invalid configuration and just not let you do that. With NixOS you can end up hosing dnsmasq on the router and then be without DNS.

What hardware did you use?

A super old Sophos (then Astaro) ASG 120 r4 small-business firewall. I mean, this thing was outdated 5 years ago. Someone was throwing it away due to getting a replacement and after swapping the HDD for a small SSD, this thing flies.

At some point in the near future, I’ll replace it with something like this and then leave the Sophos as a cold stand-by unit: https://www.aliexpress.com/item/1005003990581434.html

Having the same CPU arch as the rest of the machines makes things much easier so I really am not inclined to go aarch64.

  • auto boot after power failure / unencrypted disk

Mine does that - just a BIOS setting.

  • firewall
  • forward some traffic to home server
  • wireguard vpn(some home server services only available behind vpn)

Yes to all.

  • traffic shaping / failover / management rules ?

Firewall rules of course but no traffic shaping.

  • adguard

Used to but was overruled by wife who clicks on ads sometimes.

4 Likes
  • VPN (wireguard)

I hadn’t actually tried to see how much it would handle, so I just gave it a go. CPU is maxed out when doing about 200mbps over the wireguard VPN (it’s a 500/500 connection).

CPU is Atom N450 @ 1.66GHz (single core with HT). Keep in mind that this is a 12 years old CPU and anything made within the last couple of years is going to be able to saturate the 500/500 without breaking a sweat.

I use nixos modules on my openwrt router: https://github.com/Mic92/dotfiles/tree/master/openwrt

5 Likes

I’ve noticed that GitHub - telent/nixwrt: This repo is dormant : NixWRT is being rewritten as Liminix exists, but no idea what state it’s in.

The wiki also mentions NixOS on routers I’ve noticed in the past

1 Like

This does make me wonder what the minimal requirements for running nixos are. I’ve contemplated this a few times before, but my router doesn’t have the 20GB of disk space all my other systems seem to need for NixOS (I think it has barely 2GB or so).

I guess the minimal branch is a lot smaller?

2 Likes

nixpkgs is clearly not optimized for size like openwrt is, which can get quite a lot of features in 7MB. You might want to rather look at project like the banana pi router Banana Pi Smart Router-Banana Pi open source hardware community,Single board computer, Router,IoT,STEM education to get hardware powerful enough for NixOS.

2 Likes

That, or write my own router-targeting nixos :wink: Thanks, I was wondering how all these people are pulling this off, guess not everybody uses puny hardware.

3 Likes

I use NixOS on a Turris Omnia. Wifi works fine. Biggest pain points are lacking binary caches and Firewall software. Writing manual nftables rules does get a bit annoying at times.

https://skogsbrus.xyz/blog/2022/06/12/router/

2 Likes

please if someone finds out tells us, it would be great to have that in the documentation and the download page as well

I’m running NixOS as a router/firewall/vpn on a PC Engines apu1c4 product file The only downside I found is that the device can do max 500Mbps PPPoE. I’m not running WiFi on it because configuring multiple SSIDs on different VLANs proved too difficult, my UniFi access points now handle this.

2 Likes