What is the nix-way to specify LD_LIBRARY_PATH?

For example, I have a python package that requires libstdc++.so.6.
So my immediate solution was to

find -L /run /nix -name libstdc++.so.6
The result was (sans error messages about permission or symlink loops)
Then I just ran
env LD_LIBRARY_PATH=/nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib:$LD_LIBRARY_PATH python
And problem solved.

Of course, this is not the proper nix-way. So what are the proper nix-ways if I were to
make /nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib/libstdc++.so.6 available either

  1. in a shell temporarily,
  2. system-wide by default (preferring gcc 8.3.0 over older gcc), or
  3. for a specific user by default?

Moreover, regarding how nixos works:

  1. Why libstdc++.so.6 is only available in /nix/store/*/lib but not /run/current-system/sw/lib ?
    In another occasion I used

env LD_LIBRARY_PATH=/run/current-system/sw/lib:$LD_LIBRARY_PATH

to run something requiring libX11.so.
Why libX11.so is linked under /run/current-system/sw/lib while libstdc++.so.6 is not?

  1. When I ran

find -L /nix/store/gcc-8.3.0 -name libstdc++.so.6 2>/dev/null | xargs md5sum

I got

0de7cba5b9ff44a00ddf115a1429ca36 /nix/store/7fvwr8la2k701hrx2w5xnvjr5kkc7ysv-gcc-8.3.0-lib/lib/libstdc++.so.6
a78854179583018bd6a233b3be55f78a /nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib64/libstdc++.so.6
a78854179583018bd6a233b3be55f78a /nix/store/784rh7jrfhagbkydjfrv68h9x3g4gqmk-gcc-8.3.0-lib/lib/libstdc++.so.6

Why are there two different files for the gcc-8.3.0?
And why do I have two gcc-8.3.0-lib directories in /nix/store ?
(I have already executed

sudo nix-collect-garbage -d
sudo nix-store --optimise


From a very first intuitive thaught, I’d say, the proper way is to provide whatever is necessary for building as a buildInputs. propagatedBuildInputs if nix can’t recognize on its own, that the dependency indeed is used…

1 Like