this question in nix repo

我来自这里https://github.com/NixOS/nixpkgs/issues/28816而且我正在寻找一种方法将不纯的env变量传递给 nix-build

在本地构建应该有所帮助,但我无法使示例工作,有人可以帮助我, --option builders '' 并将当前用户添加到 trusted-users 并没有帮助

code=`<<'EOF'
with import <nixpkgs> {};
stdenv.mkDerivation {
  name="impure";
  phases=["buildPhase"];
  impureEnvVars=["IMPURE"];
  buildPhase=''
    env | grep IMPURE
    if [ -z $IMPURE ]; then
      echo "Error"
      exit 1
    fi
    echo "foo" > $out
  '';
}
EOF`
export IMPURE=iop; nix-build --option builders "" --option trusted-users $USER -E "$code"

结果

$ code=`<<'EOF'
with import <nixpkgs> {};
stdenv.mkDerivation {
  name="impure";
  phases=["buildPhase"];
  impureEnvVars=["IMPURE"];
  buildPhase=''
    env | grep IMPURE
    if [ -z $IMPURE ]; then
      echo "Error"
      exit 1
    fi
    echo "foo" > $out
  '';
}
EOF`
export IMPURE=iop; nix-build --option builders "" --option trusted-users $USER -E "$code"

these derivations will be built:
  /nix/store/dvsl63bq4qmlrs79wbxvc3vrbxzw6xad-impure.drv
building '/nix/store/dvsl63bq4qmlrs79wbxvc3vrbxzw6xad-impure.drv'...
building
impureEnvVars=IMPURE
buildPhase=env | grep IMPURE
if [ -z $IMPURE ]; then
Error
builder for '/nix/store/dvsl63bq4qmlrs79wbxvc3vrbxzw6xad-impure.drv' failed with exit code 1
error: build of '/nix/store/dvsl63bq4qmlrs79wbxvc3vrbxzw6xad-impure.drv' failed