1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-05 16:26:58 +00:00

nushell: set env in config.nu file

This commit is contained in:
Joaquín Triñanes 2024-12-28 20:52:56 +01:00 committed by Robert Helgesson
parent 46c83c07b9
commit 709aaab1a5
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
3 changed files with 23 additions and 22 deletions

View file

@ -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 != "") {

View file

@ -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"})

View file

@ -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": ({|| "> "})
}