Nvidia libraries not accessible inside snaps

I had to copy the Nvidia proprietary blobs into /var/lib/snapd/lib as follows:

/usr/lib/x86_64-linux-gnu/{nv, libGL*, libEGL*} -> /var/lib/snapd/lib AND /var/lib/snapd/lib/gl
/usr/lib/x86_64-linux-gnu/nvidia/xorg/nvidia_drv.so -> /var/lib/snapd/lib/gl/xorg/nvidia_drv.so
You have to do the same for /usr/lib/i386-linux-gnu into /var/lib/snapd/lib32 if you want to use 32-bit apps running OpenGL.

This fixed Stellarium, Anbox and Ohmygiraffe snaps for me. Stellarium and Ohmygiraffe use regular OpenGL; Anbox uses EGL/GLES.

This is obviously an awful hack that has to be maintained whenever I update driver versions, so snapd needs to handle this better.

Hey, thank you for reporting this. This hack should not be necessary, I wonder what’s going on on your system. Can you please share the output of snap version as well as the information on your GPU (model and driver version used). If you used a driver from outside of the distribution package please include the origin as well.

So I’m a dummy and I asked another question before this split happened. Here it is for consistency

Can you please install a small helper snap and run a few commands?

  • sudo snap install snapd-hacker-toolbelt
  • snapd-hacker-toolbelt.busybox ls /var/lib/snapd/lib/gl
  • cat /sys/modules/nvidia/version
# snap version
snap    2.42.5
snapd   2.42.5
series  16
ubuntu  20.04
kernel  5.4.12-xanmod7

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce RTX 2080 Ti/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 440.48.02

# snapd-hacker-toolbelt.busybox ls /var/lib/snapd/lib/gl
libEGL.so                               libGLX.so.0                             libnvidia-fbc.so
libEGL.so.1                             libGLX.so.0.0.0                         libnvidia-fbc.so.1
libEGL.so.1.1.0                         libGLX_indirect.so.0                    libnvidia-fbc.so.440.48.02
libEGL_mesa.so.0                        libGLX_mesa.so.0                        libnvidia-glcore.so.440.48.02
libEGL_mesa.so.0.0.0                    libGLX_mesa.so.0.0.0                    libnvidia-glsi.so.440.48.02
libEGL_nvidia.so.0                      libGLX_nvidia.so.0                      libnvidia-glvkspirv.so.440.48.02
libEGL_nvidia.so.440.48.02              libGLX_nvidia.so.440.48.02              libnvidia-ifr.so
libGL.so                                libGLdispatch.so                        libnvidia-ifr.so.1
libGL.so.1                              libGLdispatch.so.0                      libnvidia-ifr.so.440.48.02
libGL.so.1.7.0                          libGLdispatch.so.0.0.0                  libnvidia-ml.so
libGLESv1_CM.so                         libnvcuvid.so                           libnvidia-ml.so.1
libGLESv1_CM.so.1                       libnvcuvid.so.1                         libnvidia-ml.so.440.48.02
libGLESv1_CM.so.1.2.0                   libnvcuvid.so.440.48.02                 libnvidia-opencl.so.1
libGLESv1_CM_nvidia.so.1                libnvidia-cbl.so.440.48.02              libnvidia-opencl.so.440.48.02
libGLESv1_CM_nvidia.so.440.48.02        libnvidia-cfg.so                        libnvidia-opticalflow.so
libGLESv2.so                            libnvidia-cfg.so.1                      libnvidia-opticalflow.so.1
libGLESv2.so.2                          libnvidia-cfg.so.440.48.02              libnvidia-opticalflow.so.440.48.02
libGLESv2.so.2.1.0                      libnvidia-compiler.so.440.48.02         libnvidia-ptxjitcompiler.so
libGLESv2_nvidia.so.2                   libnvidia-egl-wayland.so.1              libnvidia-ptxjitcompiler.so.1
libGLESv2_nvidia.so.440.48.02           libnvidia-egl-wayland.so.1.1.3          libnvidia-ptxjitcompiler.so.440.48.02
libGLEW.so.2.1                          libnvidia-eglcore.so.440.48.02          libnvidia-rtcore.so.440.48.02
libGLEW.so.2.1.0                        libnvidia-encode.so                     libnvidia-tls.so.440.48.02
libGLU.so.1                             libnvidia-encode.so.1                   libnvoptix.so.1
libGLU.so.1.3.1                         libnvidia-encode.so.440.48.02           libnvoptix.so.440.48.02
libGLX.so                               libnvidia-fatbinaryloader.so.440.48.02  xorg

Nvidia binary is from ppa:graphics-drivers.

I guess Nvidia may have changed the names or locations of the drivers they ship, or added dependencies that need to be exposed to the snap environment.

Running the latest Nvidia binaries generally improves performance, recent kernel compatibility, fixes bugs when running games, and so on – so unfortunately downgrading is not an option for me. When they make these one-sided changes, I guess that makes ecosystems like Snapcraft basically dependent on the Nvidia binaries and needing to track changes. I’m not sure what changed though, nor whether the problem is the driver version or if it’s just an Ubuntu 20.04 thing.

BTW, I tried running the “core” snap edge version, and it didn’t help. I was getting a generic libGL error message about the inability to load “swrast” until I copied those files. At one point I had only copied some of them, but not all, and that created a slightly worse situation where the Nvidia GL stack tried to load but didn’t have everything it needed, so the error messages were even more cryptic.

I ended up trying this because someone else in some other random github issue for some snap that depended on GL commented that they had to copy nvidia_drv.so (the GLX driver) into /var/lib/snapd/lib/gl/xorg. That alone didn’t solve my problem, hence starting to copy random shared libraries that contained “nv” or “GL” in their name.

BTW, I get an ENOENT on /sys/modules/nvidia/version. Weird, huh, considering my GL stack is definitely the Nvidia binary.

1 Like

This is duplicate of Nvidia beta drivers completely break snaps

I am working on this and I’ll send the PR to fix this after some more experiments. It should hit snapd / core edge channel in a day or two.

1 Like

I am currently seeing this too.

I’m using Debian 9 with package nvidia-driver, and I’ve encountered a similar issue with the snap package obs-studio.

I had to adapt the above solution for my specific use case, because the /snap/obs-studio directory is read-only.

This worked for me:

sudo mount --bind $SOURCE/libGL.so.1 $DEST/libGL.so.1
sudo mount --bind $SOURCE/libEGL.so.1 $DEST/libEGL.so.1.0.0
sudo mount --bind $SOURCE/libGLX.so.0 $DEST/libGLX.so.0
sudo mount --bind $SOURCE/nvidia/current/libGLX_nvidia.so.390.138 $DEST/libGLX_mesa.so.0

For extra info of the troubleshooting steps I took, see https://github.com/snapcrafters/obs-studio/issues/68.

Note that all of these files should already be available inside the snap’s mount namespace at /var/lib/snapd/lib/gl/, so it sounds like the obs-studio somehow is not setup to look for those libraries

Although I note that we will mount the files with the same name, so perhaps some configuration needs to happen for obs-studio to use the nvidia libs as “mesa” there.

Can you show the output of:

$ snap run --shell obs-studio -c 'ls /var/lib/snapd/lib/gl/'

as well as

$ snap version