Virt-manager
Introduction
Virt-manager is a graphical app that lets you create, run, and manage VMs. On NixOS it presumes KVM, which is a Type 1 hypervisor. In plain language, Virt-manager is the de facto app for VMs. It's fast, reliable, and well suited for using guest VMs on your personal computer.
If you have experience with VirtualBox, VMware Workstation, or Parallels Desktop, this is what your're looking for on Linux and NixOS.
It's very fast. It utilizes Virtio and paravirtualization to give you the best experience.
Prerequisite
For the best performance ensure that your host UEFI settings have Vt-x and Vt-d (Intel) or AMD-V and AMD-Vi (AMD) enabled.
Installation
NixOS
NixOS 23.11 or better:
programs.virt-manager.enable = true;
users.groups.libvirtd.members = ["your_username"];
virtualisation.libvirtd.enable = true;
virtualisation.spiceUSBRedirection.enable = true;
You will get a warning when you open it for the first time:
Could not detect a default hypervisor. Make sure the appropriate QEMU/KVM virtualization packages are installed to manage virtualization on this host.
A virtualization connection can be manually added via File->Add Connection
To resolve:
File (in the menu bar) -> Add connection HyperVisor = QEMU/KVM Autoconnect = checkmark Connect
The same can also be achieved declaratively by setting the corresponding dconf settings with home-manager. If you want to do this instead of the imperative configuration described above, add the following snippet to your home-manager configuration:
dconf.settings = {
"org/virt-manager/virt-manager/connections" = {
autoconnect = ["qemu:///system"];
uris = ["qemu:///system"];
};
};
You may get the following error:
authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'
To resolve, add the user to the libvirtd
group:
{
users.users.<myuser>.extraGroups = [ "libvirtd" ];
}
Networking
The default network starts off as being inactive, you must enable it before it is accessible. This can be done by running the following command:
virsh net-start default
Or autostart:
virsh net-autostart default
By default this will enable the virbr0
virtual network bridge.
Display
The default Video may not allow different resolutions, `Virtio` will allow for more.
Windows Guest
See Virtio-win guest tools for additional drivers for both paravirtual and emulated hardware
Guest Agent
When running NixOS as a guest, enable the QEMU guest agent with:
{
services.qemuGuest.enable = true;
services.spice-vdagentd.enable = true; # enable copy and paste between host and guest
}
The host must provide the needed virtio serial port under the special name org.qemu.guest_agent.0
.
Migrate Linux VM from VirtualBox to Virt-manager
If you have a VirtualBox VM, do this to move to Virt-manager:
1) In VirtualBox, freshen your VM OS with all available updates.
2) Uninstall VirtualBox Guest Additions.
Linux guest VM:
sudo /opt/VBoxGuestAdditions-*/uninstall.sh
sudo poweroff
3) Remove any VirtualBox references from your host's NixOS configuration, and install Virt-manager.
4) Create a directory for your VM for use with Virt-manager.
mkdir -p ~/VirtualMachines
5) Convert your VirtualBox virtual machine disk to Virt-manager's preferred file format.
qemu-img convert -f vdi -O qcow2 /path/to/your/ubuntu24.vdi ~/VirtualMachines/ubuntu24.qcow2
6) Launch Virt-manager on your NixOS host.
7) Click "New VM" and choose "Import existing disk image".
8) Browse and select the QCOW2 file you just created.
9) Configure the VM settings:
- Choose "Generic Linux" as the OS type
- Set your RAM and CPU preferences
- Set your network setting preferences
- Before finalizing, check "Customize configuration before install".
- In the customization window:
-- Set the disk bus to VirtIO for better performance
-- Set the network adapter is using VirtIO
10) Start the VM.
11) After your guest VM successfully boots and you login, install the QEMU Guest Agent.
Ubuntu guest VM:
sudo aptitude update
sudo aptitude install qemu-guest-agent