[Nix-dev] Building portable linux binaries on NixOS

Bryan Gardiner bog at khumba.net
Fri Oct 9 18:33:26 CEST 2015


On Fri, 9 Oct 2015 12:18:03 +0200
Joachim Schiele <js at lastlog.de> wrote:

> On 09.10.2015 07:50, Bryan Gardiner wrote:
> > 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...
> 
> $ patchelf --set-rpath /lib:/usr/lib:/usr/local/lib go-app
> 
> will 'replace' all previously set RPATHs so there is no need for
> --remove-rpath

And from further reading, RPATH doesn't inhibit ld.so.conf, so that
shouldn't even be necessary.  Okay thanks!  Don't know why I thought
that...

- 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/20151009/88d31b80/attachment.bin 


More information about the nix-dev mailing list