So, I wrote a trivial program and built it with clang++ to get a trivial executable. Unfortunately I cannot run this binary on other distros because all the dynamic libraries and the elf interpreter point to nix-store locations.
I was wondering what is necessary to be able to run this binary on other systems (e.g. on a typical linux system like Ubuntu).
Usage: nix bundle FLAGS... INSTALLABLE?
Summary: bundle an application so that it works outside of the Nix store.
Examples:
To bundle Hello:
$ nix bundle hello
Thanks! nix bundle does not seem to work at all for me. But I found GitHub - matthewbauer/nix-bundle: Bundle Nix derivations to run anywhere! which works nicely for binaries that are already in the nix-store! Unfortuantely so far my binaries are just locally built binaries without any packaging; but perhaps creating a dummy package for the binary would work!
Thanks! Unfortunately I don’t think making static binaries are always feasible (for example, the actual binary I’m trying to port depends on SDL2, which does not seem to have a static library in the store at all).
I guess that nix-bundle involves some sort of self extraction… Isn’t it possible to simply compile using the usual loader in /lib? Otherwise I guess it should be possible to patch the elf file but it sounds quite dirty…
I’m not certain how it’s done, it uses some very intetesting namespace stuff I think, but it’s similar to an appimage and doesn’t require extraction.
I see, but in simpler cases one may want to produce a standard simple file. For instance to keep the file small and simple, to avoid unnecessary bugs potentially coming from the namespace (like I don’t think you can run setuid apps in namespaces and nesting namespaces can be a problem), to have a simpler debugging procedure (would gdb interact nicely with nix bundle?) and more.
Oh, I don’t disagree, but it’s the best possible generic solution. Nix fundamentally links things to /nix/store, which isn’t present on other distros.
That, or static linking. Maybe you can do something with buildFhsUserEnv. And patchelf, of course.
I think the best option is patchelf --set-interpreter /usr/lib/ld-linux.so, or whatever the interpreter path is on traditional distros.
That doesn’t mean it will work, of course, there’s no guarantee the dependencies will be the same. But if you don’t want to create bundles, not much else you can do.