NixOS Networking Configuration for VMs on Notebook: Use ethernet bridge until unplug

Hey fellow NixOS enthusiasts!

I’ve been using NixOS on my notebook, leveraging it to host some virtual machines. Typically, these VMs use the default bridge created by libvirt.

Here’s the catch - when I’m at home with my desktop machine, I want to connect to these VMs seamlessly. Unfortunately, setting this up via WiFi proved to be a bit challenging for me. As a workaround, I decided to create a bridge device using networking.bridges... in my NixOS configuration to bridge my ethernet device (router is near my desk anyways so i dont really mind it not being wireless), and it works like a charm.

However, there’s a minor hiccup. When I unplug my ethernet cable, I lose all networking capabilities until I manually run ip link set bridge down. I suspect this happens because ip routes still lists the bridge device as the default.

Is there any convenient way to get around this?