OpenGL with libvirt and Nvidia driver?

When enabling use of the Nvidia driver (services.xserver.videoDrivers = [ "nvidia" ]) I lose the ability to use OpenGL for my libvirt guests; the option to enable opengl, via virt-manager, is there but the guest VM will fail to start. It looks like libvirt is trying to use the wrong driver and unable to find it, but it’s not clear why it isn’t looking for the Nvidia driver or how I can force it to do so.

Error seen when attempting to run a guest with OpenGL enabled while the host is using Nvidia driver:

Error starting domain: internal error: process exited while connecting to monitor: MESA-LOADER: failed to open nouveau (search paths /run/opengl-driver/lib/dri)
failed to load driver: nouveau
MESA-LOADER: failed to open kms_swrast (search paths /run/opengl-driver/lib/dri)
failed to load driver: kms_swrast
MESA-LOADER: failed to open swrast (search paths /run/opengl-driver/lib/dri)
failed to load swrast driver
2020-05-12T15:45:34.599799Z qemu-system-x86_64: egl: gbm_create_device failed
2020-05-12T15:45:34.599826Z qemu-system-x86_64: Failed to initialize EGL render node for SPICE GL

Traceback (most recent call last):
  File "/nix/store/9zmil5nqrjscy75cgh498d2cjh21w84w-virt-manager-2.2.1/share/virt-manager/virtManager/asyncjob.py", line 75, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/nix/store/9zmil5nqrjscy75cgh498d2cjh21w84w-virt-manager-2.2.1/share/virt-manager/virtManager/asyncjob.py", line 111, in tmpcb
    callback(*args, **kwargs)
  File "/nix/store/9zmil5nqrjscy75cgh498d2cjh21w84w-virt-manager-2.2.1/share/virt-manager/virtManager/object/libvirtobject.py", line 66, in newfn
    ret = fn(self, *args, **kwargs)
  File "/nix/store/9zmil5nqrjscy75cgh498d2cjh21w84w-virt-manager-2.2.1/share/virt-manager/virtManager/object/domain.py", line 1279, in startup
    self._backend.create()
  File "/nix/store/vnzr628n5rdgd9mggj9f4vqqq5jla1vn-python3.7-libvirt-6.1.0/lib/python3.7/site-packages/libvirt.py", line 1234, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
libvirt.libvirtError: internal error: process exited while connecting to monitor: MESA-LOADER: failed to open nouveau (search paths /run/opengl-driver/lib/dri)
failed to load driver: nouveau
MESA-LOADER: failed to open kms_swrast (search paths /run/opengl-driver/lib/dri)
failed to load driver: kms_swrast
MESA-LOADER: failed to open swrast (search paths /run/opengl-driver/lib/dri)
failed to load swrast driver
2020-05-12T15:45:34.599799Z qemu-system-x86_64: egl: gbm_create_device failed
2020-05-12T15:45:34.599826Z qemu-system-x86_64: Failed to initialize EGL render node for SPICE GL

This is not an issue if I disable the Nvidia driver and use nouveau.

Any thoughts on where I’ve gone wrong, or what I can try, are appreciated.

I believe all relevant configuration is in this post, but my config is available on GitHub if that’s useful.

Getting the same issue, did you manage to overcome this?

Is that even supposed to work with Nvidia’s blobby crap? I doubt upstream would have been very found of dealing with another driver stack, especially not a closed one.

What happens if you try adding hardware.opengl.enable = true; to your /etc/nixos/configuration.nix? See the wiki page for more info.

I’m not sure if that’ll fix it but it’s worth a shot…

I am not sure, I have a not so strong memory of it working on other distros.

It is enabled. The issue is something similar to this: VirtualBox cannot access OpenGL with Nvidia Drivers as Normal User · Issue #22760 · NixOS/nixpkgs · GitHub.
We need to use a hook called addOpenGLRunpath on the qemu package. @Atemu Looking further it should/does work on Nvidia.

4 Likes

After further testing, calling the VM directly from the QEMU CLI works fine with OpenGL, but calling it through virsh/virt-manager does not. The addOpenGLRunpath change is unneeded for the qemu package, maybe for libvirt it is…

Edit: tried adding the runpath to libvirtd, still doesn’t work. I guess it’s till to hit up the maintainers.

Are you running Windows (in the VM)? Because for me it works perfectly with a Linux VM but not with a Windows VM

1 Like

I did not manage to overcome this, but am grateful that you’ve managed to reignite the topic as it’s still of interest to me - thanks! Hopefully I’ll get a chance to revisit this over the weekend following along with the new information in this thread. :slight_smile:

It happens to any VM. also I created an issue in nixpkgs libvirt: openGL does not work with Nvidia GPUs · Issue #164436 · NixOS/nixpkgs · GitHub

It’s still broken with Nvidia :frowning: