cmal
cmal

Reputation: 2222

Failed when `nix-build hello.nix`

I followed the steps on http://lethalman.blogspot.com/2014/08/nix-pill-8-generic-builders.html to build GNU Hello, and here is the files I used to build GNU hello 2.9:

$ wget -c http://ftp.gnu.org/gnu/hello/hello-2.9.tar.gz

hello.nix:

$ cat hello.nix
let
  pkgs = import <nixpkgs> {};
  mkDerivation = import ./autotools.nix pkgs;
in mkDerivation {
  name = "hello";
  src = ./hello-2.9.tar.gz;
}

autotools.nix:

$ cat autotools.nix
pkgs: attrs:
  with pkgs;
  let defaultAttrs = {
    builder = "${bash}/bin/bash";
    args = [ ./builder.sh ];
    baseInputs = [ gnutar gzip gnumake gcc binutils coreutils gawk gnused gnugrep ];
    buildInputs = [];
    system = builtins.currentSystem;
  };
  in
  derivation (defaultAttrs // attrs)

builder.sh:

$ cat builder.sh
set -e
unset PATH
for p in $buildInputs; do
  export PATH=$p/bin${PATH:+:}$PATH
done

tar -xf $src

for d in *; do
  if [ -d "$d" ]; then
    cd "$d"
    break
  fi
done

./configure --prefix=$out
make
make install

Error messages:

$ nix-build hello.nix
these derivations will be built:
  /nix/store/d84l57agx3rmw00lxs8gjlw8srmx1bh9-hello.drv
building '/nix/store/d84l57agx3rmw00lxs8gjlw8srmx1bh9-hello.drv'...
/nix/store/vv3xqdggviqqbvym25jf2pwv575y9j1r-builder.sh: line 7: tar: No such file or directory
builder for '/nix/store/d84l57agx3rmw00lxs8gjlw8srmx1bh9-hello.drv' failed with exit code 127
error: build of '/nix/store/d84l57agx3rmw00lxs8gjlw8srmx1bh9-hello.drv' failed

It seems there is gnutar in the autotools.nix but builder still complains tar: No such file or directory, why is this?

Upvotes: 3

Views: 882

Answers (1)

David Grayson
David Grayson

Reputation: 87406

The problem is probably that gnutar is in the baseInputs list, while the buildInputs list you are building your PATH from is totally empty so nothing will be on your PATH. Try changing the for line in your shell script so that it uses the concatentation of both lists to build the path:

for p in $baseInputs $buildInputs; do

You can add echo $PATH to your builder script to debug issues like this.

That is what the blog post author was asking you to do in this sentence from the post:

Complete the new builder.sh by adding $baseInputs in the for loop together with $buildInputs.

Upvotes: 2

Related Questions