看着https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/pybind11/default.nix,在我看来,我应该能够避免运行带有以下内容的测试(即设置-DPYBIND11_TEST=OFF
):
pybind11 = pkgs.pybind11.overrideAttrs (oldAttrs: rec {
doCheck = false;
});
但是,这不起作用。
我通过直接修改cmakeFlags解决了我的问题:
pybind11 = pkgs.pybind11.overrideAttrs (oldAttrs: rec {
cmakeFlags = [
"-DPYTHON_EXECUTABLE=${pkgs.python.interpreter}"
"-DPYBIND11_TEST=OFF"
];
});
但是我想知道为什么前一种方法不起作用。
答案 0 :(得分:1)
它不起作用,因为派生使用的是rec
关键字,该关键字没有覆盖的概念。摘录:
{ stdenv, fetchurl, fetchFromGitHub, cmake, catch, python, eigen }:
stdenv.mkDerivation rec { #0
name = "pybind-${version}";
version = "2.2.4";
doCheck = true; #1
cmakeFlags = [
"-DPYBIND11_TEST=${if doCheck then "ON" else "OFF"}"
];
}
使用.overrideAttrs (oldAttrs: { doCheck = false; })
时,您仅覆盖doCheck
属性,而不覆盖cmakeFlags
,该属性仍从引入的词汇范围引用doCheck
(#1
)由rec {}
(#0
)
因此,以下内容等同于上面的代码段:
{ stdenv, fetchurl, fetchFromGitHub, cmake, catch, python, eigen }:
stdenv.mkDerivation (let #0
name = "pybind-${version}";
version = "2.2.4";
doCheck = true; #1
cmakeFlags = [
"-DPYBIND11_TEST=${if doCheck then "ON" else "OFF"}"
];
in { #0
name = name;
version = version;
doCheck = doCheck; #1
cmakeFlags = cmakeFlags;
}
mkDerivation
只能看到它获得的attrset,而不能自省和修改构建该attrset的表达式。这是必需的Nix语言设计原则,因为它使您可以推理代码并启用惰性。 rec
语义根本不适合覆盖。