Nix mkDerivation 无法将本地文件系统 zip 文件识别为 src
Nix mkDerivation can't recognize local filesystem zip file as src
根据 https://nixos.org/nixpkgs/manual/#ssec-unpack-phase 我可以将 zip 文件用作 'source'。
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "test-environment";
nativeBuildInputs = [ unzip ];
buildInputs = [ unzip ];
src = "./x.zip";
}
nix-build
these derivations will be built:
/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv
building '/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv'...
unpacking sources
unpacking source archive ./x.zip
unzip: cannot find or open ./x.zip, ./x.zip.zip or ./x.zip.ZIP.
unzip: cannot find or open ./x.zip, ./x.zip.zip or ./x.zip.ZIP.
do not know how to unpack source archive ./x.zip
builder for '/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv' failed with exit code 1
error: build of '/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv' failed
我的工作目录中有一个 x.zip
文件。为什么会失败?
更新:
如果我设置 unpackCmd = "ls -altr";
我会看到以下输出:
total 16
drwxr-x--- 9 nobody nixbld 4096 May 26 12:39 ..
drwx------ 2 nixbld nixbld 4096 May 26 12:39 .
-rw-r--r-- 1 nixbld nixbld 5806 May 26 12:39 env-vars
为什么我的 zip 文件没有出现在该上下文中?
您不希望您的 Nix 派生引用本地文件系统元素!如果任何东西都没有经过哈希处理并放入商店,那么你的构建是不纯的,并且不会在沙盒模式下工作。
将其更改为 src = ./x.zip
,文件将被散列并添加到存储中,src
将被设置为 /nix/store/.....-x.zip
路径。
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "test-environment";
nativeBuildInputs = [ unzip ];
buildInputs = [ unzip ];
src = ./x.zip; ## NO QUOTES!
}
根据 https://nixos.org/nixpkgs/manual/#ssec-unpack-phase 我可以将 zip 文件用作 'source'。
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "test-environment";
nativeBuildInputs = [ unzip ];
buildInputs = [ unzip ];
src = "./x.zip";
}
nix-build
these derivations will be built:
/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv
building '/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv'...
unpacking sources
unpacking source archive ./x.zip
unzip: cannot find or open ./x.zip, ./x.zip.zip or ./x.zip.ZIP.
unzip: cannot find or open ./x.zip, ./x.zip.zip or ./x.zip.ZIP.
do not know how to unpack source archive ./x.zip
builder for '/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv' failed with exit code 1
error: build of '/nix/store/431i1riasgh2hjs5rd9azfh0ssjlg7qj-test-environment.drv' failed
我的工作目录中有一个 x.zip
文件。为什么会失败?
更新:
如果我设置 unpackCmd = "ls -altr";
我会看到以下输出:
total 16
drwxr-x--- 9 nobody nixbld 4096 May 26 12:39 ..
drwx------ 2 nixbld nixbld 4096 May 26 12:39 .
-rw-r--r-- 1 nixbld nixbld 5806 May 26 12:39 env-vars
为什么我的 zip 文件没有出现在该上下文中?
您不希望您的 Nix 派生引用本地文件系统元素!如果任何东西都没有经过哈希处理并放入商店,那么你的构建是不纯的,并且不会在沙盒模式下工作。
将其更改为 src = ./x.zip
,文件将被散列并添加到存储中,src
将被设置为 /nix/store/.....-x.zip
路径。
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "test-environment";
nativeBuildInputs = [ unzip ];
buildInputs = [ unzip ];
src = ./x.zip; ## NO QUOTES!
}