Trouble with setting up Virtual Machine Manager in NixOS

Hi all,

My host OS is Mint and I’ve already installed Virtual Machine Manager (VMM) on Mint and it’s working fine.

I wanted to do some experiments with NixOS, including installing VMM on it and running a guest OS inside it.

So my setup will be like this:

VMM
└── NixOS
    └── VMM
        └── Alpine

NixOS installs successfully on Mint’s VMM:

Then I followed this guide to install VMM on NixOS:

But virsh net-start default fails:

Anyway, when I open VMM, shows as QEMU/KVM connected:

But when I proceed to install Alpine, I get an error:

Any ideas how can I fix these problem?

PS: Is there a way to manage virsh (make it auto start default) via configuration.nix?

Not sure about VMM specifically (edit: do you just mean virt-manager?) but when I was figuring out how to use libvirt, the key turned out to be to add -c qemu:///system to virsh commands and such. I’ve written a more detailed guide here in case that’s helpful.

1 Like

I am still getting the same error:

$ virsh -c qemu:///system net-start default
error: Faailed to start network default
error: internal error: Network is already in use by interface enp1s0
  • Running virsh -c qemu:///system net-start default on a host NixOS environment works.
  • Running virsh -c qemu:///system net-start default on a a NixOS environment that itself runs in a VMM fails.

That is because the default network in libvirt (and thus, virt-manager) is 192.168.122.x/24. In the guest OS, it is already your primary network, so it cannot be used (error: internal error: Network is already in use by interface enp1s0). One way to change it would be to edit connection details, remove the default network and create a new one with different IPs. If you want to have something declarative, I’m affraid there is not much network related settings in configuration, but you can create new xml in /etc/libvirt/networks/ and use systemd service to replace default network.

2 Likes

Thanks! A custom network with CIDR range 172.16.0.0/24 worked.

PS: Looks like it’s not necessary to run the virsh commands as VMM can autostart the network on boot.

1 Like