[Nix-dev] Building portable linux binaries on NixOS

Bryan Gardiner bog at khumba.net
Fri Oct 9 07:50:38 CEST 2015


On Thu, 8 Oct 2015 00:03:23 +0200
Kamil Chmielewski <kamil.chm at gmail.com> wrote:

> 2015-10-07 20:44 GMT+02:00 Bryan Gardiner <bog at khumba.net>:
> 
> > > your shell does not find "./go-app".
> > > What does ls -l say?
> >
> 
> The file path is right and exists for sure.
> 
> 
> > Most likely Kamil is in the right directory, and this is just a known
> > quirk: bash tries to exec the program, the exec fails because the
> > binary's interpreter is set incorrectly, and bash incorrectly
> > interprets the failure as the program not existing.  See
> > https://nixos.org/patchelf.html (although, there is an open bug about
> > patchelf not working on Go binaries, see
> > https://github.com/NixOS/patchelf/issues/66).
> 
> Looks like the issue. Any ideas what to do?

I'm not sure if you've tried patchelf and hit that bug, or if you
haven't...  If you haven't, then try something like the following:

$ patchelf --set-interpreter /lib/ld-linux.so.2 go-app
$ patchelf --set-rpath /lib:/usr/lib:/usr/local/lib go-app
$ ./go-app  # (on Ubuntu)

You should consult /etc/ld.so.conf on Ubuntu for the correct library
directories (not on Ubuntu here, so I can't see what how it does
things).

I think though, wouldn't the correct thing to do (after setting the
interpreter) actually be to *remove* the RPATH from the binary to have
it work on non-NixOS, using the normal system library lookup?  I don't
see a --remove-rpath option on patchelf though.  I can't recall
whether RPATH inhibits normal lookup directories, if not then you
wouldn't need to change it, or you could just set it to be empty...
See ld.so(8).

Cheers,
Bryan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20151008/4ab299f5/attachment-0001.bin 


More information about the nix-dev mailing list