`nix-build hello.nix` 时失败
Failed when `nix-build hello.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
autotools.nix
里面好像有gnutar
,但是builder还是抱怨tar: No such file or directory
,这是为什么?
问题可能是 gnutar
在 baseInputs
列表中,而您从中构建 PATH 的 buildInputs
列表完全是空的,因此您的 PATH 上不会有任何内容。尝试更改 shell 脚本中的 for
行,以便它使用两个列表的连接来构建路径:
for p in $baseInputs $buildInputs; do
您可以将 echo $PATH
添加到构建器脚本中以调试此类问题。
这就是博客 post 作者要求您在 post:
的这句话中做的事情
Complete the new builder.sh by adding $baseInputs in the for loop together with $buildInputs.
我按照 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
autotools.nix
里面好像有gnutar
,但是builder还是抱怨tar: No such file or directory
,这是为什么?
问题可能是 gnutar
在 baseInputs
列表中,而您从中构建 PATH 的 buildInputs
列表完全是空的,因此您的 PATH 上不会有任何内容。尝试更改 shell 脚本中的 for
行,以便它使用两个列表的连接来构建路径:
for p in $baseInputs $buildInputs; do
您可以将 echo $PATH
添加到构建器脚本中以调试此类问题。
这就是博客 post 作者要求您在 post:
的这句话中做的事情Complete the new builder.sh by adding $baseInputs in the for loop together with $buildInputs.