关于此问题:nix-shell: how to specify a custom environment variable?
使用此推导:
stdenv.mkDerivation rec {
FOO = "bar";
}
[FOO
将在nix外壳中作为环境变量提供,但是是否可以从env文件中加载环境变量?
您可以使用nix-shell
的nix-shell
将它们作为外壳程序代码从文件中加载环境变量。例如:
shellHook
如果您的外壳也不是包,则可以从sourcing切换到stdenv.mkDerivation {
name = "my-shell";
shellHook = ''
# Mark variables which are modified or created for export.
set -a
source env.sh
# or to make it relative to the directory of this shell.nix file
# source ${toString ./env.sh}
set +a
'';
}
。