From 0b25ac41ee8754cecfacfbbb311ed008e5670260 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 19 Oct 2023 13:02:18 +0100 Subject: [PATCH] home-environment: prepend instead of append --- modules/home-environment.nix | 10 +++++----- modules/lib/shell.nix | 10 +++++----- tests/modules/home-environment/session-path.nix | 2 +- .../home-environment/session-search-variables.nix | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 3533ea2c4..8f40eae32 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -309,7 +309,7 @@ in ".git/safe/../../bin" ]; description = '' - Extra directories to add to {env}`PATH`. + Extra directories to be prepend to {env}`PATH`. These directories are added to the {env}`PATH` variable in a double-quoted context, so expressions like `$HOME` are @@ -329,9 +329,9 @@ in ]; }; description = '' - Extra directories to add to arbitrary PATH-like environment - variables (e.g.: {env}`MANPATH`). The values will be concatenated - by `:`. + Extra directories to be prepend to arbitrary PATH-like + environment variables (e.g.: {env}`MANPATH`). The values + will be concatenated by `:`. These directories are added to the environment variable in a double-quoted context, so expressions like `$HOME` are @@ -581,7 +581,7 @@ in (mapAttrsToList (env: values: config.lib.shell.export env - (config.lib.shell.appendToVar ":" env values)) + (config.lib.shell.prependToVar ":" env values)) cfg.sessionSearchVariables) + cfg.sessionVariablesExtra; }; diff --git a/modules/lib/shell.nix b/modules/lib/shell.nix index cdcfdefa5..c6113d0fd 100644 --- a/modules/lib/shell.nix +++ b/modules/lib/shell.nix @@ -1,13 +1,13 @@ { lib }: rec { - # Produces a Bourne shell like statement that appends new values to + # Produces a Bourne shell like statement that prepend new values to # an possibly existing variable, using sep(ator). # Example: - # appendToVar ":" "PATH" [ "$HOME/bin" "$HOME/.local/bin" ] - # => "$PATH\${PATH:+:}$HOME/bin:$HOME/.local/bin" - appendToVar = sep: n: v: - "\$${n}\${${n}:+${sep}}${lib.concatStringsSep sep v}"; + # prependToVar ":" "PATH" [ "$HOME/bin" "$HOME/.local/bin" ] + # => "$HOME/bin:$HOME/.local/bin:${PATH:+:}\$PATH" + prependToVar = sep: n: v: + "${lib.concatStringsSep sep v}\${${n}:+${sep}}\$${n}"; # Produces a Bourne shell like variable export statement. export = n: v: ''export ${n}="${toString v}"''; diff --git a/tests/modules/home-environment/session-path.nix b/tests/modules/home-environment/session-path.nix index 57cfeceda..55c4084a7 100644 --- a/tests/modules/home-environment/session-path.nix +++ b/tests/modules/home-environment/session-path.nix @@ -10,6 +10,6 @@ hmSessVars=home-path/etc/profile.d/hm-session-vars.sh assertFileExists $hmSessVars assertFileContains $hmSessVars \ - 'export PATH="$PATH''${PATH:+:}bar:baz:foo"' + 'export PATH="bar:baz:foo''${PATH:+:}$PATH"' ''; } diff --git a/tests/modules/home-environment/session-search-variables.nix b/tests/modules/home-environment/session-search-variables.nix index c260e6fee..66dcb034b 100644 --- a/tests/modules/home-environment/session-search-variables.nix +++ b/tests/modules/home-environment/session-search-variables.nix @@ -10,6 +10,6 @@ hmSessVars=home-path/etc/profile.d/hm-session-vars.sh assertFileExists $hmSessVars assertFileContains $hmSessVars \ - 'export TEST="$TEST''${TEST:+:}bar:baz:foo"' + 'export TEST="bar:baz:foo''${TEST:+:}$TEST"' ''; }