当`nix-build hello.nix`失败

时间:2018-11-15 06:52:03

标签: nix

我按照http://lethalman.blogspot.com/2014/08/nix-pill-8-generic-builders.html的步骤构建了GNU Hello,下面是我用来构建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

错误消息:

$ 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

gnutar中似乎有autotools.nix,但构建者仍在抱怨tar: No such file or directory,为什么?

1 个答案:

答案 0 :(得分:1)

问题可能是gnutarbaseInputs列表中,而您从中构建PATH的buildInputs列表却完全是空的,因此PATH中没有任何内容。尝试更改您的Shell脚本中的for行,以便它使用两个列表的组合来构建路径:

for p in $baseInputs $buildInputs; do

您可以在构建器脚本中添加echo $PATH来调试此类问题。

这是博客文章作者在帖子中用这句话要您做的事情:

  

通过在$循环中将$ baseInputs与$ buildInputs一起添加来完成新的builder.sh。