mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 07:04:17 +00:00
nushell: Allow arbitrary env vars
This commit is contained in:
parent
471e3eb0a1
commit
1a08dc8f6e
3 changed files with 22 additions and 8 deletions
|
@ -145,11 +145,17 @@ in {
|
|||
};
|
||||
|
||||
environmentVariables = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
type = types.attrsOf (pkgs.formats.json { }).type;
|
||||
default = { };
|
||||
example = { FOO = "BAR"; };
|
||||
example = {
|
||||
FOO = "BAR";
|
||||
BOOLEAN_VAR = true;
|
||||
NUMERIC_VAR = 4;
|
||||
LIST_VAR = [ "elem1" 2 ];
|
||||
OBJECT_VAR = { some = "field"; };
|
||||
};
|
||||
description = ''
|
||||
An attribute set that maps an environment variable to a shell interpreted string.
|
||||
Environment variables that will be set.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
@ -173,9 +179,12 @@ in {
|
|||
})
|
||||
|
||||
(let
|
||||
envVarsStr = concatStringsSep "\n"
|
||||
(mapAttrsToList (k: v: "$env.${k} = ${v}") cfg.environmentVariables);
|
||||
in mkIf (cfg.envFile != null || cfg.extraEnv != "" || envVarsStr != "") {
|
||||
hasEnvVars = cfg.environmentVariables != { };
|
||||
envVarsStr = lib.mkIf hasEnvVars ''
|
||||
${builtins.toJSON cfg.environmentVariables} | load-env
|
||||
'';
|
||||
|
||||
in mkIf (cfg.envFile != null || cfg.extraEnv != "" || hasEnvVars) {
|
||||
"${configDir}/env.nu".text = mkMerge [
|
||||
(mkIf (cfg.envFile != null) cfg.envFile.text)
|
||||
cfg.extraEnv
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$env.FOO = 'BAR'
|
||||
|
||||
|
||||
$env.BAR = $'(echo BAZ)'
|
||||
{"BAR":"$'(echo BAZ)'","BOOLEAN_VAR":true,"LIST_VAR":["elem1",2],"NUMERIC_VAR":4} | load-env
|
||||
|
|
|
@ -28,7 +28,12 @@
|
|||
"ll" = "ls -a";
|
||||
};
|
||||
|
||||
environmentVariables = { BAR = "$'(echo BAZ)'"; };
|
||||
environmentVariables = {
|
||||
BAR = "$'(echo BAZ)'";
|
||||
BOOLEAN_VAR = true;
|
||||
NUMERIC_VAR = 4;
|
||||
LIST_VAR = [ "elem1" 2 ];
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.nushell = { };
|
||||
|
|
Loading…
Reference in a new issue