From 709aaab1a5c35a8d1f1e7546efa226e09f3316fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Tri=C3=B1anes?= Date: Sat, 28 Dec 2024 20:52:56 +0100 Subject: [PATCH] nushell: set env in config.nu file --- modules/programs/nushell.nix | 15 ++++++++------- tests/modules/programs/nushell/config-expected.nu | 15 +++++++++++++++ tests/modules/programs/nushell/env-expected.nu | 15 --------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index b1f90658..92a8f4e9 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -205,6 +205,12 @@ in { (lib.mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases); in lib.mkIf writeConfig { "${configDir}/config.nu".text = lib.mkMerge [ + (let + hasEnvVars = cfg.environmentVariables != { }; + envVarsStr = '' + load-env ${toNushell { } cfg.environmentVariables} + ''; + in lib.mkIf hasEnvVars envVarsStr) (let flattenSettings = let joinDot = a: b: "${if a == "" then "" else "${a}."}${b}"; @@ -220,6 +226,7 @@ in { ''; settingsLines = lib.concatMapStrings mkLine (flattenSettings cfg.settings); + in lib.mkIf (cfg.settings != { }) settingsLines) (lib.mkIf (cfg.configFile != null) cfg.configFile.text) cfg.extraConfig @@ -227,16 +234,10 @@ in { ]; }) - (let - hasEnvVars = cfg.environmentVariables != { }; - envVarsStr = '' - load-env ${toNushell { } cfg.environmentVariables} - ''; - in lib.mkIf (cfg.envFile != null || cfg.extraEnv != "" || hasEnvVars) { + (lib.mkIf (cfg.envFile != null || cfg.extraEnv != "") { "${configDir}/env.nu".text = lib.mkMerge [ (lib.mkIf (cfg.envFile != null) cfg.envFile.text) cfg.extraEnv - envVarsStr ]; }) (lib.mkIf (cfg.loginFile != null || cfg.extraLogin != "") { diff --git a/tests/modules/programs/nushell/config-expected.nu b/tests/modules/programs/nushell/config-expected.nu index 6d5b09b2..4578f953 100644 --- a/tests/modules/programs/nushell/config-expected.nu +++ b/tests/modules/programs/nushell/config-expected.nu @@ -1,3 +1,18 @@ +load-env { + "ENV_CONVERSIONS": { + "PATH": { + "from_string": ({|s| $s | split row (char esep) }) + "to_string": ({|v| $v | str join (char esep) }) + } + } + "FOO": "BAR" + "LIST_VALUE": [ + "foo" + "bar" + ] + "PROMPT_COMMAND": ({|| "> "}) +} + $env.config.display_errors.exit_code = false $env.config.hooks.pre_execution = [ ({|| "pre_execution hook"}) diff --git a/tests/modules/programs/nushell/env-expected.nu b/tests/modules/programs/nushell/env-expected.nu index 50f6f767..aacc3792 100644 --- a/tests/modules/programs/nushell/env-expected.nu +++ b/tests/modules/programs/nushell/env-expected.nu @@ -1,17 +1,2 @@ $env.FOO = 'BAR' - -load-env { - "ENV_CONVERSIONS": { - "PATH": { - "from_string": ({|s| $s | split row (char esep) }) - "to_string": ({|v| $v | str join (char esep) }) - } - } - "FOO": "BAR" - "LIST_VALUE": [ - "foo" - "bar" - ] - "PROMPT_COMMAND": ({|| "> "}) -}