Félix Baylac Jacqué
6fb5f29175
Good news: we did not have to patch libglvnd for the EGL support. All the low-level machinery was already here (but sadly undocumented). Bad news: properly supporting the EGL stack turned out being more involving than its GLX counterpart on the wrapper side. Not only you need the main EGL lib in charge of implementing the primitives (libEGL_nvidia.so), but also two other libraries implementing the wayland and gbm bindings. These DSOs in turn depend on some non-glibc but open source shared libraries. I decided to use the ones coming from the host system rather than the ones provided by Nixpkgs: it's best to assume that the host system did its homework to determine which version of these libraries the Nvidia driver is expecting to work with. |
||
---|---|---|
overlays | ||
README.md | ||
default.nix | ||
flake.lock | ||
flake.nix | ||
nixglhost-wrapper.py | ||
shell.nix |
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:
- Detect the host vendor graphic DSOs via some heuristics.
- Copy the host vendor DSOs to a cache location.
- 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
. - Inject the libGLVnd-specific env variables to point to the patched vendor lib.
- 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
.