Run your nix programs with your host graphics drivers.
Go to file
Félix Baylac Jacqué 891dd0bf95
Cache cold build: prevent race condition
We had a race condition on cold cache builds. When several nix-gl-host
instances were called, they were trying to concurrently build the

This lead to some weird errors and busted caches.

We introduce a file lock preventing any concurrent access to the

We take advantage of this bug to rethink the way we build the cache
and do it in a more robust way. Instead of building it in place, we're
now building it first in a temporary directory (while making sure to
patchelf the DSOs according their final destination). We then move
this directory to the actual cache destination iff the cache has been
built successfully.
2023-01-17 16:14:16 +01:00
src Cache cold build: prevent race condition 2023-01-17 16:14:16 +01:00
tests/fixtures/json_permut Hot Cache: use the DSO last write time/size instead of content hash 2022-12-14 19:20:10 +01:00
.envrc Introduce a cache system 2022-12-05 13:33:01 +01:00
default.nix flake: add meta.mainProgram 2023-01-05 16:48:38 +01:00
flake.lock Add Nix build infrastructure 2022-11-24 17:03:42 +01:00
flake.nix Flake: overlays removal leftovers. 2022-12-22 19:14:23 +01:00 Update doc 2022-12-05 15:38:58 +01:00 Update doc 2022-12-05 15:38:58 +01:00
shell.nix Add Nix build infrastructure 2022-11-24 17:03:42 +01:00


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


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


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


  • [-] 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.