R B*_*ett 3 haskell nix haskell-stack
我在 nix 中使用堆栈。我需要将环境变量作为数据库密码传递以在运行时连接到 Postgres。目前,我在 YAML 中启用了 nix 并自定义了自己.nix的密码以将密码放入.nix.
堆栈.yaml:
nix:
enable: true
pure: true
shell-file: shell.nix
Run Code Online (Sandbox Code Playgroud)
shell.nix:
{ghc}:
with (import <nixpkgs> {});
haskell.lib.buildStackProject {
inherit ghc;
name = "myenv";
buildInputs = [ postgresql_10 ];
PGPASSWORD = "pw";
}
Run Code Online (Sandbox Code Playgroud)
但是当我想将代码提交到 GitHub/Gitlab 并转到 CI/CD 管道时,显式输入密码.nix似乎不太好。我想知道有什么好的方法可以解决这个问题吗?
您可以将builtins.getEnvNix 表达式中的函数用于外部环境中环境变量的值,因此您可以执行以下操作:
PGPASSWORD = builtins.getEnv "PGPASSWORD";
Run Code Online (Sandbox Code Playgroud)
这只是设置其值的一种方式。您还可以使用import导入从未提交到 git 的 Nix 表达式文件,或者您可以使用builtins.readFile读取从未提交到 git 的文件。
| 归档时间: |
|
| 查看次数: |
289 次 |
| 最近记录: |