OpenGL: Difference between revisions
imported>Primeos dev Briefly document how to debug Mesa issues |
imported>Kreyren Compilance with FHS 3.0 -> Use "Optional" directory instead of "Service" dedicated for system-provided services |
||
Line 11: | Line 11: | ||
To avoid a lot of rebuilds there's an internal NixOS option to override the Mesa drivers: <code>hardware.opengl.package</code> | To avoid a lot of rebuilds there's an internal NixOS option to override the Mesa drivers: <code>hardware.opengl.package</code> | ||
It can be used like this: <code>hardware.opengl.package = (import / | It can be used like this: <code>hardware.opengl.package = (import /opt/nixpkgs-mesa { }).pkgs.mesa.drivers;</code> | ||
However, since Mesa 21.0.2 this doesn't necessarily work anymore and something like the following might be required: | However, since Mesa 21.0.2 this doesn't necessarily work anymore and something like the following might be required: | ||
<pre> | <pre> | ||
system.replaceRuntimeDependencies = [ | system.replaceRuntimeDependencies = [ | ||
({ original = pkgs.mesa; replacement = (import / | ({ original = pkgs.mesa; replacement = (import /opt/nixpkgs-mesa { }).pkgs.mesa; }) | ||
({ original = pkgs.mesa.drivers; replacement = (import / | ({ original = pkgs.mesa.drivers; replacement = (import /opt/nixpkgs-mesa { }).pkgs.mesa.drivers; }) | ||
]; | ]; | ||
</pre> | </pre> |
Revision as of 15:20, 12 June 2021
OpenGL must break purity due to the need for hardware-specific linkage. Intel, AMD, and Nvidia have different drivers for example. On NixOS, these libraries are symlinked under
/run/opengl-driver/lib
and optionally (if hardware.opengl.driSupport32Bit
is enabled)
/run/opengl-driver-32/lib
When a program is installed in your environment, these libraries should be found automatically. However, this is not the case in a `nix-shell`. To fix, add this line to your shell.nix:
LD_LIBRARY_PATH="/run/opengl-driver/lib:/run/opengl-driver-32/lib";
Testing Mesa updates
To avoid a lot of rebuilds there's an internal NixOS option to override the Mesa drivers: hardware.opengl.package
It can be used like this: hardware.opengl.package = (import /opt/nixpkgs-mesa { }).pkgs.mesa.drivers;
However, since Mesa 21.0.2 this doesn't necessarily work anymore and something like the following might be required:
system.replaceRuntimeDependencies = [ ({ original = pkgs.mesa; replacement = (import /opt/nixpkgs-mesa { }).pkgs.mesa; }) ({ original = pkgs.mesa.drivers; replacement = (import /opt/nixpkgs-mesa { }).pkgs.mesa.drivers; }) ];
Note: Both of these approaches are impure and only work to a certain degree (many limitations!). If you want to use a different version of Mesa your best option is to use an overlay or a Git worktree where you use the same Nixpkgs revision and only alter pkgs/development/libraries/mesa/
for one of the two approaches mentioned above.
Debugging Mesa issues
There are a lot of useful environment variables for debugging purposes: https://docs.mesa3d.org/envvars.html
The most important one is LIBGL_DEBUG=verbose
and helps with debugging error like:
libGL error: MESA-LOADER: failed to open $DRIVER (search paths /run/opengl-driver/lib/dri) libGL error: failed to load driver: $DRIVER