How to **not** use libs from nix

I have a machine with Ubuntu 22.04 and I am using Nix (not NixOS) in conjunction with home-manager to easily install tools.

When trying to build a rust project from source, I have the following errors:

error: /nix/store/90illc73xfs933d06daq6d41njs8yh66-glibc-2.32-37/lib/ version `GLIBC_2.33' not found (required by /projects/kbct/target/debug/deps/
   --> /home/oliv/.cargo/registry/src/
284 | pub use proc_macro_error_attr::proc_macro_error;

From various searches, I understand that this stems from mix os libs and nix libs.
Particularly, this github issue recommends not to use nix to install compilers, and advice I plan to use not to bother too much.


  • even with rustup, rustc, cargo, etc installed locally,
  • without anything set for LD_LIBRARY_PATH or this var set explicitly to /usr/lib:/usr/lib32:/usr/lib64
    I still see the libc installed by nix being used to compile.

Not being very versed into compiler options, I seek for help to properly configure my env not to use these libs to build my project.

Thanks very much to all that will answer

Some notes:

  • I have read about patchself to fix hard-coded lib paths in .so, but these files being built by cargo, I am not sure I can automate the fix after every build.

How did you install your toolchain, and what is the content of LD_PRELOAD ?

Rust toolchain has been installed using rustup, following procedure. That is curl --proto '=https' --tlsv1.2 -sSf | sh (at the time of the writing).

Currently, either in fishshell and bash (mostly using fishshell), LD_PRELOAD is empty.

However, even if I am not expert in what ldd does, seeing it regularly used in these questions, I tested it upon rustc installed by rustup and I see:

❯ ldd rustc (0x00007ffcd43be000) => /home/oliv/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/./../lib/ (0x00007f145bc00000) => /home/oliv/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/./../lib/ (0x00007f145b800000) => /lib/x86_64-linux-gnu/ (0x00007f14600ec000) => /lib/x86_64-linux-gnu/ (0x00007f14600e7000) => /lib/x86_64-linux-gnu/ (0x00007f14600e2000) => /lib/x86_64-linux-gnu/ (0x00007f145b5d8000) => /home/oliv/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/./../lib/../lib/ (0x00007f1456078000) => /lib/x86_64-linux-gnu/ (0x00007f14600c0000) => /lib/x86_64-linux-gnu/ (0x00007f145fb19000)
	/nix/store/90illc73xfs933d06daq6d41njs8yh66-glibc-2.32-37/lib/ => /lib64/ (0x00007f146010a000) => /nix/store/6hhqb94ilrdmh0cx5bhdqb92m6bqkvdj-zlib-1.2.11/lib/ (0x00007f14600a1000)

I can see that both libz and libm are coming from nix, while the ohers are local or from rustup.
Conversely, points to my os version.

I apologize because I haven’t enough knowledge of these, but could it be the source of the issue?

did you install gcc, stdenv, clang or binutils with nix (either nix-env or home-manager) ? What does which cc ld rustc cargo report ?

Also did you install nixpkgs’s rustup in the past, then uninstalled it, and installed the official rustup afterwards without nuking .rustup in-between ?

1 Like

It may be excessive but dear @symphorien, you are a life-saver.
Indeed, I did uninstall nix rustup without nuking .rustup. Performing this cleaning and re-installing the toolchain solved the issues.
I managed to compile my project without any error this time :tada:

So, once more, thanks for your prompt answers today and for your previous helpful answers in various threads.

Before closing this discussion, if I may ask, is there something specific to configure how libraries are used (as it was the OP). Or, because some are hard-coded into binaries, should one just wind up tools until a clean state is restored?

1 Like

An executable hardcodes the so-called ELF interpreter it needs: nixpkgs-provided stuff uses a nix-provided interpreter (part of glibc) and “normal” executables hardcode /lib/ Optionally, executables can also hardcode where libraries they use should be looked for with RUNPATH or RPATH. This is the case of all nixpkgs-provided executables, but is more rare for “normal” executables. When the RUNPATH or RPATH are not set, libraries are looked in the environment variable LD_LIBRARY_PATH or in system-configured path like /usr/lib. So LD_LIBRARY_PATH can somewhat influence where libraries are picked, but not fully, and it cannot change what ELF interpreter is used.

The issue here is that nixpkgs’s rustup is patched to use patchelf to point executables downloaded by rustup to some nixpkgs-provided ELF interpreter and patch their RPATH to some working libs. This is required to make rustup work on NixOS where the default ELF interpreter does not exist. As these changes are persistent (because they modify the executable) removing rustup and reinstalling another that does not have this behavior is not enough.

1 Like

I’m glad to find the solution to this here! Arguably, rustup installed via Nix should alter the location of ~/.rustup so as not to run into these issues.

I wonder how often tools/users hardcode the path to the compiler in ~/.rustup

That is one solution, but honestly I prefer a project specific devshell which pulls in the required Rust version, either just from nixpkgs or from fenix. That way the rust version built by Nix for the package, and the rust version used in development are identical.

1 Like