[Nix-dev] Dealing with non-Bash /bin/sh on non-NixOS

Michael Raskin 7c6f434c at mail.ru
Sat Nov 3 15:49:18 CET 2012


>A common problem for people trying to use Nix/Nixpkgs/Guix on non-NixOS
>distros, especially Debian derivatives, is that their /bin/sh is not
>Bash.  On Debian and derivatives, it’s a symlink to /bin/dash.
>
>When building without a chroot, things eventually fail because stdenv,
>and sometimes build systems, assume that /bin/sh is Bash.
>
>When enabling ‘build-use-chroot’, things fail because the symlink’s
>target is not included in the chroot.
>
>For things to work, people have to set ‘build-use-chroot = false’ and
>make /bin/sh a symlink to /bin/bash.  Enabling ‘build-use-chroot’ won’t
>work unless /bin/sh is not a symlink *and* is statically-linked.
>
>Is there a better way to approach that problem?

I can only share my experience.

The server itself is Fedora; I want to have external system undamaged,
but I do have root and I can use it at will.

Note: when you do this for the first time, you may accidentally put 
computer in non-desired state w.r.t. nested bind mounts that don't want
to go away. Also, if you do anything wrong, you have a good chance to
have your / (real root filesystem) remounted RO. Please learn to do it 
in a situation where you can afford to reboot your computer at will. It 
is not a constant annoyance, it is a risk when you first set the things 
up, and I don't want to give dangerous advice.

I have some basic-chroot.nix, which is what basics I need to do Nix 
builds and look at simple problems comfortably.

It is literally:

let nixpkgs = import <nixpkgs> {}; in with nixpkgs; 
  symlinkJoin "chroot-system" [
    nixUnstable openssl (glibcLocales.override {allLocales = true;})
    rlwrap gcc zlib patchelf coreutils stdenv bashInteractive su gnugrep
    gnused less findutils curl wget utillinuxCurses subversion openssh
    gzip vim file strace lsof 
  ]

I build it as /var/chroot-env

When I need to do a rebuild that includes some local work, I do

/etc/nixos/configurations/misc/raskin/misc-scripts/special-chroot \
     /var/nix-chroot /root root usr-only /var/chroot-env

(chroot inside /var/nix-chroot with /root inside new root being used as
home, be user "root" afterwards, do not populate /bin or /lib, and use 
/var/chroot-env as package set source. 

This environment is clean enough for nix builds (both chroot builds and
non-chroot builds) to work, and close enough to LSB that you can even do
some tests while packaging complicated LSB-reliant packages.

Works For Me, I can explain details further if you are interested. Maybe
then the log of email exchange could be copied to wiki...





More information about the nix-dev mailing list