Run your nix programs with your host graphics drivers.
Go to file
Félix Baylac Jacqué 61a5fcdae8 Re-thinking the host library auto detection mechanism.
We made the incorrect assumption that the first DSO we'd stumble upon
in the load path would be the most appropriate one for the host
system. IE. it'd be the x86_64-gnu-linux on such a system. It turned
out not being the case, meaning we can't take such a shortcut and have
to handle the case where we end up with multiple same libraries for
different archs.

This forced us to do two things:

1. It forced us to rethink the cache directory structure. We now have
   to cache each library directory separately. Meaning we now have to
   inject the GLX/EGL/Cuda directories of *all* these library
   directories subpaths to the LD_LIBRARY_PATH. The dynamic linker
   will then try to open these DSOs (and fail) until it stumble upon
   the appropriate one.
2. We had to give up on the way we injected EGL libraries using
   asolute paths. We don't know which DSO is adapted to the wrapped
   program arch. Instead of injecting the absolute paths through the
   JSON configuration files, we just stipulate the libraries names in
   them. We then inject the various EGL DSOs we find through the
   LD_LIBRARY_PATH, similarly to what we already do for GLX and Cuda.
2022-12-14 14:32:54 +01:00
overlays Nix: add patched libglvnd overlay 2022-11-24 17:03:46 +01:00
src Re-thinking the host library auto detection mechanism. 2022-12-14 14:32:54 +01:00
tests/fixtures/json_permut Re-thinking the host library auto detection mechanism. 2022-12-14 14:32:54 +01:00
.envrc Introduce a cache system 2022-12-05 13:33:01 +01:00
INTERALS.md Update doc 2022-12-05 15:38:58 +01:00
README.md Update doc 2022-12-05 15:38:58 +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/Cuda/OpenCL Nix-built binaries on a foreign Linux distro is quite often a challenge. These programs are relying on some host-specific graphics drivers at runtime. These drivers are host-specific, it is obviously impossible to distribute the drivers for each and every hosts setup through a pre-defined generic nix closure.

NixGLHost solves this issue by re-using your host system graphics drivers. It copies them to an isolated environment and inject the said environment to the Nix runtime closure.

Current status: experimental.

How to Use

All you have to do is to wrap your nix-built OpenGL/Cuda program with nixglhost:

For instance, let's say you want to run my-gl-program, a nix-built program on your favorite distribution. All you'll have to do is:

nixglhost my-gl-program

Example

Let's nix-build glxgears, living in the glxinfo Nixpkgs derivation then execute it with nixglhost.

cd $thisRepoCheckout
PATH=$(nix build --print-out-paths)/bin:$PATH
nixglhost $(nix build  --print-out-paths .#glxinfo)/bin/glxgears

Internals

You can read the INTERNALS.md file to learn how exactly NixGLHost works.

Support

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

Alternative Approaches

  • NixGL: tries to auto detect the host vendor driver type/version, then download/install it from its Nixpkgs derivation.

Authors/Maintainers