How can I get a shared clipboard for NixOS Virtual Machine with GNOME?

I have been trying to get a basic NixOS VM working so I can test my home-manager configuration. This blog post blew my mind. The code for the actual VM in that post is here and I can reproduce it with working copy/paste between my NixOS host and the VM.

However, if I switch to GNOME I lose the ability to copy and paste:

  services.xserver = {
	  enable = true;
    desktopManager.gnome.enable = true;
    displayManager.gdm.enable = true;

I believe the ‘xserver’ is basically an anachronism here and this installs the Wayland version of GNOME.

Does anyone have a shared clipboard working for a NixOS VM running GNOME? I would also appreciate pointers towards documentation. What I have found so far is very scattered and lacks context.

I don’t believe spice-vdagent supports Wayland. You can still run a GNOME session under Xorg for now, by clicking the little gear in GDM (see here for example), and that’ll probably help.

Thank you for the suggestion. The gear is not visible, but I was able to switch to Xorg by setting services.xserver.displayManager.gdm.wayland = false;. I still haven’t been able to get the clipboard working.

In case anyone else is trying to get a GNOME NixOS VM running using nix-build, I also had to add a swapfile or GNOME would run out of memory and crash after a few seconds:

 swapDevices = [ {
    device = "/var/lib/swapfile";
    size = 8*1024;
  } ];

Are you sure? Note that it’ll only appear after you’ve selected or typed in your user name.

That setting will control whether GDM uses Wayland, but not whether your user session uses Wayland. You can check the latter in GNOME (version 45; these names will have changed in 46) by going into Settings, clicking About in the sidebar, and clicking System Details; the Windowing System entry will tell you what sort of session you’re running (X11 or Wayland). Or you can run

systemctl --user status org.gnome.Shell@x11

and see if it is active or inactive.

I’m pretty sure that it is using X11 and I cannot see the gear:

If anyone wants to try to reproduce, I committed the current code I’m running here: GitHub - wrycode/simple-nix-vm

(commit 7a6858e9d86abdd71822f124c6344a0fb0a6d88c for posterity)

Huh! Welp, that’s me told. :laughing: Good luck with figuring this one out.