LD_LIBRARY_PATH
is the correct environment variable to set.
The system configuration’s environment.sessionVariables
is the wrong place to set it.
It’s better to set it in a nix shell. If you’re unfamiliar with writing a shell.nix file, there’s a tutorial on nix.dev, and the reference documentation for mkShell in the nixpkgs manual.
I think it’s worth explaining about how LD_LIBRARY_PATH
being set relates to “GLIBCXX_
not found”.
On Linux, programs linked against shared libraries are run with the dynamic linker. This is similar to how running ./foo.sh
uses the shebang #!/usr/bin/env bash
to run/interpret the file.
Some further reading: this article with a simple demonstration about the dynamic linker from baedung.com, this unix.stackexchange question What is /lib64/ld-linux-x86-64.so.2 and why can it be used to execute file? (with an answer linking to an in-depth LWN article about how ELF binaries get run).
The man page for ld-linux points out that it uses the LD_LIBRARY_PATH
to indicate where to look for shared libraries.
On NixOS, a dynamic linker has a path like /nix/store/35pq4hr29c3sl79lgfwgsvd9nwzyp4am-glibc-2.39-5/lib64/ld-linux-x86-64.so.2
.
So, setting LD_LIBRARY_PATH
helps when e.g. using Python packages with pre-compiled shared binaries, since it helps Python find those shared libraries.
But, setting it globally also means that all programs are going to pick up the same version of glibc (or other libraries on LD_LIBRARY_PATH
). Programs packaged with Nix (if packaged correctly) should be able to find the shared libraries they depend on without LD_LIBRARY_PATH
being set. And apparently can fail with LD_LIBRARY_PATH
set to include incompatible versions of libraries they’re linked against.