Skip to content

Instantly share code, notes, and snippets.

@frafra
Last active January 10, 2025 09:06
Show Gist options
  • Save frafra/99f6730ebc7716929870ecf3bca629de to your computer and use it in GitHub Desktop.
Save frafra/99f6730ebc7716929870ecf3bca629de to your computer and use it in GitHub Desktop.
GLX in nix-shell

How to solve Could not initialize GLX and similar errors?

Workaround (not recommended)

export QT_XCB_GL_INTEGRATION=none

-- NixOS/nixpkgs#82959 (comment)

This a workaround that works most of the times, but what about a proper solution?

NixGL (recommended)

Setup

nix-channel --add https://github.com/nix-community/nixGL/archive/main.tar.gz nixgl && nix-channel --update
nix-env -iA nixgl.auto.nixGLDefault

-- https://github.com/nix-community/nixGL?tab=readme-ov-file#nix-channel-recommended

On some NVIDIA systems, it is necessary to force the loading of NVIDIA libraries by adding this line to .bashrc or similar:

export __GLX_VENDOR_LIBRARY_NAME=nvidia

-- nix-community/nixGL#177 (comment)

Run the app

Run you apps as usual:

nixGL nix-shell -p rstudio -p R --run rstudio

To avoid running each command using the nixGL wrapper, it is possible to set some environmental variables which will do the same (you might put them in your shellHook):

library_path="$LD_LIBRARY_PATH"
export $(env -i $(which nixGL) $(which printenv))
export LD_LIBRARY_PATH="$library_path:$LD_LIBRARY_PATH"

-- nix-community/nixGL#46 (comment)

@unhammer
Copy link

Thanks, this let me run anki-bin (where export QT_XCB_GL_INTEGRATION=none did not help), but installing nixGL took like half a gig :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment