nushell: add envVars attribute (#3930)

This commit is contained in:
Yt 2023-05-03 18:12:21 -04:00 committed by GitHub
parent 0e4c33d760
commit 788777b536
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -121,6 +121,15 @@ in {
this option) to command strings or directly to build outputs.
'';
};
environmentVariables = mkOption {
type = types.attrsOf types.str;
default = { };
example = { FOO = "BAR"; };
description = ''
An attribute set that maps an environment variable to a shell interpreted string.
'';
};
};
config = mkIf cfg.enable {
@ -141,10 +150,15 @@ in {
];
})
(mkIf (cfg.envFile != null || cfg.extraEnv != "") {
(let
envVarsStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "let-env ${k} = ${v}")
cfg.environmentVariables);
in mkIf (cfg.envFile != null || cfg.extraEnv != "" || envVarsStr != "") {
"${configDir}/env.nu".text = mkMerge [
(mkIf (cfg.envFile != null) cfg.envFile.text)
cfg.extraEnv
envVarsStr
];
})
];

View File

@ -1,2 +1,4 @@
let-env FOO = 'BAR'
let-env BAR = $'(echo BAZ)'

View File

@ -20,6 +20,8 @@
"lsname" = "(ls | get name)";
"ll" = "ls -a";
};
environmentVariables = { BAR = "$'(echo BAZ)'"; };
};
test.stubs.nushell = { };