Networkd + libvirt + bridged networking -- how?


I’ve switched up my NixOS setups and now am using:

    networking = {
      # ...
      useNetworkd = true;
      interfaces."eth0".useDHCP = true;
      interfaces."enp56s0u2u3".useDHCP = true;
      interfaces."enp56s0u1u3".useDHCP = true;
      interfaces."wlan0".useDHCP = true;
    virtualisation.libvirtd = {
      enable = true;
      onBoot = "ignore";
      qemuRunAsRoot = false;

    virtualisation.spiceUSBRedirection.enable = true;

But I can’t seem to figure out how to create a useful virbr0 now for use with libvirtd.

If I naively go into virt-manager and try to start the default network (virbr0), I get this confusing error message about “Cannot allocate memory”:

Error starting network 'default': internal error: Child process (VIR_BRIDGE_NAME=virbr0 /nix/store/a9j00qbafqhai9nl8fvrwmivkcavcli5-dnsmasq-2.83/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/nix/store/fnxa395lcwdyb9cpxl1n43c870hgn2q7-libvirt-7.0.0/libexec/libvirt_leaseshelper) unexpected exit status 3: 
dnsmasq: cannot run lease-init script /nix/store/fnxa395lcwdyb9cpxl1n43c870hgn2q7-libvirt-7.0.0/libexec/libvirt_leaseshelper: Cannot allocate memory

Traceback (most recent call last):
  File "/nix/store/y6pv4phsnnqgzjbwwyb89dxqgla5fsi9-virt-manager-3.1.0/share/virt-manager/virtManager/", line 65, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/nix/store/y6pv4phsnnqgzjbwwyb89dxqgla5fsi9-virt-manager-3.1.0/share/virt-manager/virtManager/", line 101, in tmpcb
    callback(*args, **kwargs)
  File "/nix/store/y6pv4phsnnqgzjbwwyb89dxqgla5fsi9-virt-manager-3.1.0/share/virt-manager/virtManager/object/", line 57, in newfn
    ret = fn(self, *args, **kwargs)
  File "/nix/store/y6pv4phsnnqgzjbwwyb89dxqgla5fsi9-virt-manager-3.1.0/share/virt-manager/virtManager/object/", line 69, in start
  File "/nix/store/bwd2fwf2iylp9rcdcs3iz0myyhs85009-python3.8-libvirt-7.0.0/lib/python3.8/site-packages/", line 3436, in create
    raise libvirtError('virNetworkCreate() failed')
libvirt.libvirtError: internal error: Child process (VIR_BRIDGE_NAME=virbr0 /nix/store/a9j00qbafqhai9nl8fvrwmivkcavcli5-dnsmasq-2.83/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/nix/store/fnxa395lcwdyb9cpxl1n43c870hgn2q7-libvirt-7.0.0/libexec/libvirt_leaseshelper) unexpected exit status 3: 
dnsmasq: cannot run lease-init script /nix/store/fnxa395lcwdyb9cpxl1n43c870hgn2q7-libvirt-7.0.0/libexec/libvirt_leaseshelper: Cannot allocate memory

Any suggestions? Should I be explicitly creating the virbr0 in my nixos configuration, and if so, what does that look like? I preferred it when libvirtd was able to do this itself.

1 Like

This does work for me (nixpkgs @ 5e19a1f495a323dd9763d9534c22337461350e59), virsh --version says 7.0.0. My config is just virtualisation.libvirtd.enable = true;

Regarding setting up libvirts bridge manually, it is doable and we’re using it in lxc container where libvirt fails to set-up its network, see:

@colemickens did you ever solve this?
I’m seeing exactly this issue on one machine, but on another similar (also nixos) machine it doesn’t happen.

I want to get it solved though, because now basically now I’m unable to spinup any networked VM on my desktop PC…

@sorki your link no longer works, the repo is no longer there

Trying to get netdev bridge working :slight_smile: - I want to have NFS to my host and connect to the internet as usual

1 Like

Thanks, I’ll re-publish the repository.

Here’s the Gist of the module libvirt with statically configured bridge · GitHub


Just reporting back that it’s working for me now, but I need to stop the firewall.

After setting virtualisation.libvirtd.enable = true, this is the needed qemu argument:

    -netdev tap,id=net0,br=virbr0,helper=$(type -p qemu-bridge-helper)

virbr0 is set up by NixOS and the helper does the rest with tap.