NixOS as a guest OS in QEMU/KVM - how to share clipboard, displaying scaling, etc

Related work:

https://www.reddit.com/r/NixOS/comments/dkl9t9/display_scaling_with_nixos_as_qemukvm_guest/

I’m not sure anyone has reached a resolution yet. So here it goes for 2020:

I’m trying to run NixOS as a guest OS inside of KVM, I’ve set it up through virt-manager, and after downloading the nixos graphical installation iso from Download Nix / NixOS | Nix & NixOS here I asked virt-manager to boot it and installed it on the VM using the directions from NixOS 23.11 manual | Nix & NixOS. virt-manager was about to recognize my os as nixos-20.03 and seemed to have a default profile for it.

I modified my configuration.nix file to include gnome shell, and add qemuGuest and spice-vdagentd.
The additions I added look like:

  services.xserver.videoDrivers = [ "qxl" ];
  
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome3.enable = true;

  services.dbus.packages = with pkgs; [ gnome2.GConf ];
  services.qemuGuest.enable = true;
  services.spice-vdagentd.enable = mkSure true;

systemctl status reports that qemu-guest-agent.service is running, but spice-vdagent has some errors:

● spice-vdagentd.service - spice-vdagent daemon
   Loaded: loaded (/nix/store/fn4bc6avww5vzx4lyvs913gpmm5qd1y0-unit-spice-vdagentd.service/spice-vdagentd.service; enabled; vendor preset>
   Active: active (running) since Tue 2020-07-14 17:16:40 BST; 1min 18s ago
  Process: 683 ExecStartPre=/nix/store/c4vnsvk19p5kmmgqhn1h4nx3f276a2x8-unit-script-spice-vdagentd-pre-start (code=exited, status=0/SUCCE>
  Process: 697 ExecStart=/nix/store/s4gp0qjx75mg8n25dd7798l8lx3b85ka-spice-vdagent-0.19.0/bin/spice-vdagentd (code=exited, status=0/SUCCE>
 Main PID: 700 (spice-vdagentd)
       IP: 0B in, 0B out
    Tasks: 1 (limit: 4915)
   Memory: 1.5M
      CPU: 12ms
   CGroup: /system.slice/spice-vdagentd.service
           └─700 /nix/store/s4gp0qjx75mg8n25dd7798l8lx3b85ka-spice-vdagent-0.19.0/bin/spice-vdagentd

Jul 14 17:16:40 emurgo systemd[1]: Starting spice-vdagent daemon...
Jul 14 17:16:40 emurgo systemd[1]: Started spice-vdagent daemon.
Jul 14 17:16:41 emurgo spice-vdagentd[700]: Error getting active session: No data available
Jul 14 17:16:41 emurgo spice-vdagentd[700]: Error getting active session: No data available
Jul 14 17:16:41 emurgo spice-vdagentd[700]: Error getting active session: No data available
Jul 14 17:16:41 emurgo spice-vdagentd[700]: Error getting active session: No data available
Jul 14 17:17:26 emurgo spice-vdagentd[700]: Error getting session for pid 1490: No data available

virt-manager also reports that there is a “qemu-ga” channel that’s “connected”. I don’t know what that means. Nevertheless, copy-and-paste between the guest and host OS does not work, and virt-manager reports that “guest agent is not available” when I go to select the auto display scaling option.

Any ideas?

2 Likes

I’m also running a similar setup, and wondering how to make this work. I have a NixOS guest in virt-manager, and currently trying to figure out how to get resize-screen-to-window working.

What is mkSure?

mkSure sets the priority of the attribute very high so that it will override any values set by other services or settings in nixpkgs.

Hmm, the semantics of this seem confusing… what if I do mkSure false somewhere and then mkSure true somewhere else?

Have you tried stopping the qemu-guest-agent service, and starting the agent manually (you’ll find its location in ps x|grep qemu)? I’m having a similar problem with qemu not being able to connect to the agent (Qemu guest agent on Hetzner Cloud doesn't work) and so far that’s the only solution I’ve found.

It’s just a priority system, and you can think of mkSure and mkForce as ‘named’ priorities that you can use instead of magic numbers like 50. IIRC if you have both mkSure true and mkSure false it just errors out.

2 Likes

Gotcha, are these in the docs somewhere I could consult?

I know mkForce and the priority thing is here NixOS 23.11 manual | Nix & NixOS but I don’t really know where mkSure is

3 Likes

Adding services.spice-vdagentd.enable = true; to the guest nixOS machine should work

I have the spice-vdagent as user systemd service running, but the checkbox “Auto resize VM with window” in virt-manager only became enabled after I executed spice-vdagent on the terminal. Then auto-resize also worked.
After restart I have to execute spice-vdagent again to make it work. It’s not clear what the the service is doing or if it is doing anything.