How to set `runtimeDependencies` for shared libraries?

In case it can help someone, I got bitten by a similar issue as runtimeDependencies was not applied automatically. I actually realized that while some file were binary blob (these ones were patched correctly) the binaries that got compiled by the derivation are not fixed (which make sense…). To force to patch them, you can use something like:

    NIX_LDFLAGS = "-rpath ${lib.makeLibraryPath [ libtiff ]} $NIX_LDFLAGS";

(you can also set this variable in a phase using export + removing space around =)
but note that alone it is not enough, as nix automatically optimize it later and removes the just added rpath (maybe that could explain your issue?) So avoid this unecessary optimization, just do:

dontPatchELF = true;

To debug, you may like:

$ readelf -d $out/lib/yourfile
…
 0x000000000000001d (RUNPATH)            Bibliothèque runpath:[/nix/store/df8cvw3adyk0ip2vx6x6i0vdjyv2yinz-blablb/lib:/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib:/nix/store/mdck89nsfisflwjv6xv8ydj7dj0sj2pn-gcc-11.3.0-lib/lib]
…

and check what is in the RUNPATH line.

1 Like