I’m trying to create a haskell executable on an ubuntu machine with Nix installed that can be run on another ubuntu system that does not have nix installed. Running the executable on the system without Nix installed gives me a “No such file or directory” error.
Running ldd on the executable indicates, among other things:
I understood that to mean that the executable was dynamically linking to an interpreter in the nix store (which would not be present on this system that does not have nix installed), but that the interpreter was nevertheless found on the local system at /lib64/ld-linux-x86-64.so.2, so there shouldn’t be any problem (since ldd didn’t give a not found message).
But since I was getting a “No such file or directory” error when running my executable, I tried running ~patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 my-executable-exe on the executable. After that, it ran fine.
Can you help me understand why patchelf helps here? I must be misunderstanding something about the initial ldd command’s response, since I thought that indicated it could find the interpreter, but it seems that it couldn’t since updating the path to the interpreter fixed my problem.
Also, if you have any hints on how best to incorporate this patchelf command into my flake, I’d appreciate it. I’m still figuring out nix and flakes, and this is giving me some trouble. This is my current flake:
If you look at ldd source you’ll see how it extracts libraries: it runs encoded there ld-linux.so instead of using binary’s interpreter. I suggest using lddtree from pax-utils to list needed libraries.