all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: bug-guix@gnu.org
Cc: nix-dev <nix-dev@cs.uu.nl>
Subject: Down with /bin/sh!
Date: Thu, 03 Jan 2013 16:14:12 +0100	[thread overview]
Message-ID: <87a9sq47uj.fsf@inria.fr> (raw)

Hello {N,Gu}ixers, and happy new year!

The ‘core-updates’ branch of Guix now makes it possible to build
packages in a chroot lacking /bin/sh.

It’s convenient to have /bin/sh in the chroot, because that’s basically
one of the files whose name is hardcoded in many places, from libc to
shebangs.

However, the problem with /bin/sh is that it’s out of control.  On
non-NixOS distros, it’s not necessarily Bash.  Someone with Dash as
/bin/sh may have different results than someone Bash as /bin/sh.  That’s
an “impurity”, with practical consequences on build reproducibility.

Another issue on non-NixOS distros is that /bin/sh is typically a
dynamically-linked executable.  So adding /bin to the chroot is not
enough; one typically needs to also add /lib* and /lib/*-linux-gnu to
the chroot.  At that point, there are many impurities, and a great
potential for non-reproducibility–which defeats the purpose of the chroot.


So, here’s how this is solved in ‘core-updates’.

  • Right after unpacking a source tarball, all the source files go
    through ‘patch-shebang’, which replaces any #!/bin/sh and similar
    with the right path.

  • Once configure has run, all makefiles that define the ‘SHELL’
    variable are patched similarly.

The GNU build system supports ‘CONFIG_SHELL’ and ‘SHELL’, which
simplifies things (info "(autoconf) config.status Invocation").

Occasionally, packages have references to /bin/sh elsewhere, which need
to be patched as well, notably:

  • the ‘system’ and ‘popen’ functions in the GNU libc;

  • the ‘default_shell’ variable in GNU make;

  • io.c in GNU Awk;

  • ice-9/popen.scm in GNU Guile.

For libc, referring to the compile-time Bash would retain a dependency
on the bootstrap environment.  So glibc is changed to contain a copy of
a statically-linked Bash in its store path, which it can refer to
(thanks to Shea and Lluís for the suggestion).

The bootstrap libc and awk need a different trick, though, since they
must be relocated (IOW, their path is not known in advance.)  The trick
is to search for ‘sh’ in $PATH, with these simple patches:

  http://git.savannah.gnu.org/cgit/guix.git/tree/distro/packages/patches/glibc-bootstrap-system.patch?h=core-updates
  http://git.savannah.gnu.org/cgit/guix.git/tree/distro/packages/patches/gawk-shell.patch?h=core-updates

(For security reasons, these patches are /not/ used in the final libc
and awk.)

So far, it seems that little or no manual tweaking is needed beyond the
above, so hopefully it’ll scale.  The main advantage is that it makes it
possible to use Guix reliably on non-NixOS distros; even on a distro
like NixOS, that’s one less impurity, and thus improved reproducibility.

Thanks,
Ludo’.

             reply	other threads:[~2013-01-03 15:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-03 15:14 Ludovic Courtès [this message]
2013-01-03 16:00 ` Down with /bin/sh! Rob Vermaas
2013-01-03 16:27   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a9sq47uj.fsf@inria.fr \
    --to=ludo@gnu.org \
    --cc=bug-guix@gnu.org \
    --cc=nix-dev@cs.uu.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.