Add:
virtualisation.libvirtd.enable = true;
and
users.users.<you>.extraGroups = [ "libvirtd" ];
to your /etc/nixos/configuration.nix
.
Then run sudo nixos-rebuild boot
and reboot your machine.
A fresh install of libvirtd on NixOS will have a default storage pool for users in the libvirtd group:
$ virsh pool-dumpxml default
<pool type='dir'>
<name>default</name>
...
<target>
<path>/var/lib/libvirt/images</path>
</target>
</pool>
But no default pool for root:
$ sudo virsh pool-dumpxml default
error: failed to get pool 'default'
error: Storage pool not found: no storage pool with matching name 'default'
Additionally the images directory referenced above will not exist.
If your system is in a different state than this, you may have leftover configuration from a previous libvirtd install. You can run the following commands to reset it. This will destroy any machines you had defined!
sudo rm -rf /var/lib/libvirt
sudo systemctl libvirtd restart
Create an images directory modifiable by the libvirtd group (bash syntax):
images=/var/lib/libvirt/images
sudo mkdir $images
sudo chown root:libvirtd $images
sudo chmod g+w $images
Create a default pool for root:
sudo virsh pool-define-as default dir --target $images
sudo virsh pool-autostart default
sudo virsh pool-start default
Confirm you have an active default pool:
sudo virsh pool-list
cd nixops-libvirtd
nix-shell
poetry install
poetry shell
nixops create -d test tests/functional/single_machine_libvirtd_base.nix
nixops deploy -d test
nixops ssh -d test machine