Making `/lib64/ld-linux-x86-64.so.2` available

Is there a way that I can make /lib64/ld-linux-x86-64.so.2 available without having to wrap things in a shell or something similar as is discussed in How to deal with `/lib64/ld-linux-x86-64.so.2` missing on NixOS?. I know that that is not how NixOS should be used, but now after a few years I’m done fighting it. For example, if I download a new version of Julia (https://julialang.org/downloads/), then I can run the binary after I have patched bin/julia and libexec/7z. By patching, I mean that I change the interpreter from

$ patchelf --print-interpreter bin/julia
/lib64/ld-linux-x86-64.so.2

to, for example,

$ patchelf --print-interpreter bin/julia
/nix/store/lyl6nysc3i3aqhj6shizjgj0ibnf1pvg-glibc-2.34-210/lib/ld-linux-x86-64.so.2

I don’t think that it makes sense to wrap each the binary invokation in some kind of shell. Literally the only thing is that a symlink is missing.

So, basically, my question is: Can I create a symlink via the NixOS config?

Yes, you can.

And I know @gytis-ivaskevicius does or did this in their repository, though I was not able to find it quickly.

Perhaps you have better luck? Or they chime in as usual and just point you to the right location in their config.

Yes. Adding

system.activationScripts.ldso = lib.stringAfter [ "usrbinenv" ] ''
    mkdir -m 0755 -p /lib64
    ln -sfn ${pkgs.glibc.out}/lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2.tmp
    mv -f /lib64/ld-linux-x86-64.so.2.tmp /lib64/ld-linux-x86-64.so.2 # atomically replace
  '';

works :partying_face: Thanks @NobbZ and @gytis-ivaskevicius

1 Like

There is also: GitHub - Mic92/nix-ld: Run unpatched dynamic binaries on NixOS

2 Likes