Subject: bug#46297: nix-service-configuration is missing the default /bin/sh

From: pukkamustard <[email-masked]>
Date: Thu, 22 Apr 2021 07:30:58 +0000

Oleg Pykhalov <[email-masked]> writes:

> It doens't fail without the patch.  Could I ask what issue the
> build-sandbox-paths introduce for you?  Also it would be helpful 
> if you
> provide terminal output with an error you occurred.

Ah, sorry I didn't see that there where system tests.

This is how I ran into the issue (nixpkgs/ folder is a checkout of 
the nixpkgs repo).

```
$ nix-build nixpkgs/ -A ocaml-ng.ocamlPackages_4_11.ocaml

building 
'/nix/store/075nqnnbsgz2frmg5fzhj3ql8lajvgq3-ocaml-4.11.2.tar.xz.drv'...

trying 
http://caml.inria.fr/pub/distrib/ocaml-4.11/ocaml-4.11.2.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time 
  Time  Current
                                 Dload  Upload   Total   Spent 
                                 Left  Speed
100 3418k  100 3418k    0     0  2553k      0  0:00:01  0:00:01 
--:--:-- 2555k
building 
'/nix/store/p4b4shz2alnb2zpiyx44rf7yn5k30m32-ocaml-4.11.2.drv'...
unpacking sources
unpacking source archive 
/nix/store/9harmbwn44004ylalfnvlic4qp5ppvi4-ocaml-4.11.2.tar.xz
source root is ocaml-4.11.2
setting SOURCE_DATE_EPOCH to timestamp 1614163229 of file 
ocaml-4.11.2/yacc/wstr.c
patching sources
configuring
fixing libtool script ./build-aux/ltmain.sh
configure flags: --disable-static -prefix 
/nix/store/gvwnh8wn0ib40fd6k3wa4xf7ja1y17l9-ocaml-4.11.2
/nix/store/bmnhfb10m2s3whl6478dmqhcrkjwk77y-stdenv-linux/setup: 
./configure: /bin/sh: bad interpreter: No such file or directory
builder for 
'/nix/store/p4b4shz2alnb2zpiyx44rf7yn5k30m32-ocaml-4.11.2.drv' 
failed with exit code 126
error: build of 
'/nix/store/p4b4shz2alnb2zpiyx44rf7yn5k30m32-ocaml-4.11.2.drv' 
failed

````

The build succeeds if I do following:

```
$ sudo nix-build nixpkgs/ -A ocaml-ng.ocamlPackages_4_11.ocaml 
--option build-sandbox-paths 
"/bin/sh=//nix/store/0xrjvxvh3wvdbf8pc2850jry1fcx292g-busybox-1.32.1/bin/busybox"
these derivations will be built:
  /nix/store/p4b4shz2alnb2zpiyx44rf7yn5k30m32-ocaml-4.11.2.drv
building 
'/nix/store/p4b4shz2alnb2zpiyx44rf7yn5k30m32-ocaml-4.11.2.drv'...
unpacking sources
unpacking source archive 
/nix/store/9harmbwn44004ylalfnvlic4qp5ppvi4-ocaml-4.11.2.tar.xz
source root is ocaml-4.11.2
setting SOURCE_DATE_EPOCH to timestamp 1614163229 of file 
ocaml-4.11.2/yacc/wstr.c
patching sources
configuring
fixing libtool script ./build-aux/ltmain.sh
configure flags: --disable-static -prefix 
/nix/store/gvwnh8wn0ib40fd6k3wa4xf7ja1y17l9-ocaml-4.11.2
configure: Configuring OCaml version 4.11.2
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
.
.
.
/nix/store/gvwnh8wn0ib40fd6k3wa4xf7ja1y17l9-ocaml-4.11.2
```

Note that I need to use sudo as otherwise Nix would simply ignore 
my request to override system configurations. And I had to run 
`nix-build -A busybox` to make sure busybox was in the /nix/store.

The build-sandbox-paths I manually supplied seem to be the 
defaults (as stated in documentation linked in John Soo's mail), 
so I assumed that just removing the build-sandbox-path setting 
from the nix.conf would solve the issue. I was a bit sloppy with 
testing it completely...

This might be an upstream issue with how OCaml is built in Nix. I 
think Nix builders should use ${stdenv.shell} instead of /bin/sh 
(https://github.com/NixOS/nixpkgs/issues/183). But maybe good if 
we can fix it in the Guix nix-service as well.

-pukkamustard