diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index 9772f711..a977bd4a 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -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 ]; }) ]; diff --git a/tests/modules/programs/nushell/env-expected.nu b/tests/modules/programs/nushell/env-expected.nu index 280b59bf..3d818c42 100644 --- a/tests/modules/programs/nushell/env-expected.nu +++ b/tests/modules/programs/nushell/env-expected.nu @@ -1,2 +1,4 @@ let-env FOO = 'BAR' + +let-env BAR = $'(echo BAZ)' \ No newline at end of file diff --git a/tests/modules/programs/nushell/example-settings.nix b/tests/modules/programs/nushell/example-settings.nix index 28060d7b..d8cb01a7 100644 --- a/tests/modules/programs/nushell/example-settings.nix +++ b/tests/modules/programs/nushell/example-settings.nix @@ -20,6 +20,8 @@ "lsname" = "(ls | get name)"; "ll" = "ls -a"; }; + + environmentVariables = { BAR = "$'(echo BAZ)'"; }; }; test.stubs.nushell = { };