nix-shell:如何从环境文件中加载环境变量?

问题描述 投票:1回答:1

关于此问题:nix-shell: how to specify a custom environment variable?

使用此推导:

stdenv.mkDerivation rec {
  FOO = "bar";
}

[FOO将在nix外壳中作为环境变量提供,但是是否可以从env文件中加载环境变量?

nix nixpkgs
1个回答
0
投票

您可以使用nix-shellnix-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 ''; }

© www.soinside.com 2019 - 2024. All rights reserved.