Compile with Nix inside the dev shell

eb-local dev loads the European Environment for Scientific Software Installations and the modules you name. A Nix shell brings its own compiler and its own glibc. Link from nix-shell when the library you need lives in the stack, and keep that directory in DT_RPATH.

What Nix 2.35.6 recorded

tests/site/nix-dev.sh builds a small library outside the Nix store and links a program against it.

On Nix 2.35.6, nix-shell -p gcc kept a DT_RPATH entry for that directory. nix-shell --pure -p gcc kept the same entry. readelf showed a DT_RPATH entry and no DT_RUNPATH entry. NIX_ENFORCE_PURITY was unset in the shell.

The DT_RPATH entry also names Nix’s glibc 2.44, and the program interpreter is that glibc’s ld-linux. The host glibc on the machine where this was measured is glibc 2.39. The program ran under env -i while the Nix store was present, because the interpreter path is the Nix store path.

A sandboxed build

nix-build runs the compiler in a sandbox. The same link failed there, and the log said cannot find -lanswer. The sandbox hides a directory outside the Nix store, including a stack prefix. Build the program in nix-shell when the library lives outside the store.