It’s quite tricky to set up SPICE correctly. First you need to add some options to QEMU:
imports = [ <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix> ];
virtualisation.qemu.options = [
"-vga qxl"
"-spice port=5924,disable-ticketing=on"
"-device virtio-serial -chardev spicevmc,id=vdagent,debug=0,name=vdagent"
"-device virtserialport,chardev=vdagent,name=com.redhat.spice.0"
];
Then you have to enable the guest SPICE system-wide daemon
services.spice-vdagentd.enable = true
and, crucially, you need to make sure the per-session agent is started as part of your graphical session. For the latter, if you’re running a DE that implements the XDG autostart spec you’re done, otherwise you need to run spice-vdagent manually (after the X server, in your login session).
Finally, you start the VM as usual but no window will open, instead to connect to the VM you need a SPICE client, like spicy (pkgs.spice-gtk) and specify localhost:5924 (port specified in the qemu.options) as host.
After all of this you get:
- automatic display resizing that follows the window size
- shared clipboard
- client mouse mode