Qemu/kvm copy & paste

So I am very new to NixOS as of today and testing it out in a VM in KVM on my Fedora host.
I am trying to get the copy/paste feature working in the VM but, so far, I have been unsuccessful. I have added the following packages to my config:

pkgs.spice
pkgs.spice-vdagent

And added the following services to my config:

services.spice-vdagentd.enable = true;
services.qemuGuest.enable = true;

Am I missing something?
If need be, I can post my complete config.

Also, for my understanding, after I make these changes and run sudo nixos-rebuild switch is there a need to reboot the machine to get the new config to work?
Thanks in advance from a complete noobie.

1 Like

You figured anything out here?:wink:

It’s quite tricky to set up SPICE correctly. First you need to add some options to QEMU:

  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
1 Like