Run your nix programs with your host graphics drivers.
Go to file
Félix Baylac Jacqué 375148c949 Introduce a cache system
Copying & patching all the DSOs is a time consuming process (~10s on a
slow hard drive computer). We definitely don't want to go through it
for each process start, we need to introduce a cache.

For this cache, we go the concervative way. We're going to "resolve" a
DSO name (ie. find the DSO absolute path) and sha256-hash each DSO.
We're then going to compare the fingerprints to determine whether or
not we need to nuke and rebuild the DSO cache.

The cache state is persisted through a JSON file saved in the cache dir.
2022-12-05 13:33:01 +01:00
overlays Nix: add patched libglvnd overlay 2022-11-24 17:03:46 +01:00
src Introduce a cache system 2022-12-05 13:33:01 +01:00
.envrc Introduce a cache system 2022-12-05 13:33:01 +01:00
README.md Readme: status update 2022-11-24 17:12:22 +01:00
default.nix Introduce a cache system 2022-12-05 13:33:01 +01:00
flake.lock Add Nix build infrastructure 2022-11-24 17:03:42 +01:00
flake.nix Nix: add patched libglvnd overlay 2022-11-24 17:03:46 +01:00
shell.nix Add Nix build infrastructure 2022-11-24 17:03:42 +01:00

README.md

NixGLHost

Running OpenGL Nix-built binaries on a foreign Linux distro is quite often a challenge. NixGLHost glues a nix-built program to your host system graphics drivers.

Current status: experimental.

How to Use

First of all, build your Opengl program with our custom libglvnd. You can use this project's flake default overlay as a convenience. Let's build glxgears, living in the glxinfo derivation:

nix build .#glxinfo

Let say that your host graphics drivers are stored in /lib/x86_64-linux-gnu/. TODO: explain how to figure out where are the host graphic drivers.

You can run glxgear with your host graphics driver using:

PATH=$(nix build --print-out-paths)/bin:$PATH
nixglhost /lib/x86_64-linux-gnu $(nix build  --print-out-paths .#glxinfo)/bin/glxgears

NixGLHost Approach

Re-using the host graphics dynamic libraries turned out being quite challenging.

NixGLHost relies on a patched libGLvnd to inject the host DSOs without polluting the LD_LIBRARY_PATH. You can use the ./overlays/nixpkgs.nix nixpkgs overlay (exposed via flake.nix for external projects) to build a binary with this custom libglvnd.

Here's how everything works:

  1. Detect the host vendor graphic DSOs via some heuristics.
  2. Copy the host vendor DSOs to a cache location.
  3. Modify the cached DSOs runpath to point to the cache. The graphics DSOs depend on each other and won't be able to find each other using the default Nix LD_LIBRARY_PATH.
  4. Inject the libGLVnd-specific env variables to point to the patched vendor lib.
  5. Execute the wrapped binary.

This approach won't affect the Nix hermiticity: the only "external" DSOs loaded to the Nix-built program are the host-specific graphics drivers.

Support

  • [-] Proprietary Nvidia
    • GLX
    • EGL
    • Cuda
    • OpenCL
  • Mesa
    • GLX
    • EGL
    • OpenCL

Alternative Approaches

  • NixGL: tries to auto detect the host vendor driver, download it again, store it in the nix-store then wraps the nix-built binary and inject the downloaded vendor driver through LD_LIBRARY_PATH.

Authors/Maintainers