"NVIDIA LXC hook not found" with lxd v4.2 ("lxc config set container nvidia.runtime true" failed)

Possible duplicate of Nvidia runtime is missing hooks.

I set up an Ubuntu 18.04 instance (using lxd v4.2 on NixOS) with PulseAudio and X11 forwarding working. nvidia-smi run from within the container showed the right GPU and a cuda (nvcc) compilation test worked fine from inside. But as soon as I started some 3D application for testing like glxgears or gltron it was a segfault/core dump. Browsers like Firefox and Chromium launched but warned about missing GLX stuff and ran a bit slower than I’m used to with chrome://gpu / about:support showing software rendering only.
TL;DR: xclock & xeyes run but glxgears & similar apps segfault and core dump.

I mainly followed this guide and the only hitch so far is creating containers with the nvidia.runtime variable set to true, which I’m guessing is necessary for hardware accelerated rendering, assuming that’s possible in LXD without the usual GPU passthrough for VMs that requires multiple GPUs like in this case.

No existing containers can have the runtime setting changed and no new ones can be created on my machine with it enabled from the start.
Doing so gives: Error: Initialize LXC: The NVIDIA LXC hook couldn't be found

I’m not sure if there’s some misunderstanding on my end here and I’m trying to do something not possible with my setup.

I have nvidia-docker with the container runtime installed if that’s relevant.

Any feedback is appreciated.

  • Nvidia Driver: 495.44
  • Distro: NixOS 21.11
  • Kernel: 5.10.87