Persistent network interfaces, NixOS and USB WiFi dongles - how can I get all three to play nicely?

I have a USB WiFi dongle on my PC, attached to a USB hub.
If I move either the dongle to another USB slot on the hub, or the hub to another USB port on the PC, my network breaks on reboot.

For example, when I move the dongle in the hub, it changes from wlp47s0f3u4u4 to wlp47s0f3u3u4.
When I move the hub, but leave the dongle in place, it changes from wlp47s0f3u4u4 to wlp47s0f3u4u3.

Worse, I can’t update the config to reflect the change, because I’ve got no WiFi connection to rebuild my config from, so I have to put my hub and USB dongle back in the right slots.

Can I harden my configuration.nix so that dhcpcd will ask for an IP address for the dongle interface regardless of my USB configuration?

1 Like

Did you consider using network manager?

I think networking.useDHCP still works, although it’s deprecated. See Undeprecate networking.useDHCP · Issue #75515 · NixOS/nixpkgs · GitHub.

1 Like

You could set useDHCP for both interfaces if you don’t want to use the deprecated setting or networkmanager. Maybe tune the timeout so it doesn’t take so long.

On a related note, why do you need an internet connection to rebuild? It should all be cached, if the DHCP setting is the only change rebuilding should work fine.

That might result in nixos-generate-config produces network configuration that times out when interface is removed · Issue #107908 · NixOS/nixpkgs · GitHub.

1 Like