1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-15 23:59:45 +01:00

lib/shell: add appendToVar function

This commit is contained in:
Thiago Kenji Okada 2023-10-19 01:02:01 +01:00
parent 1e030277ba
commit 664086fa4c
2 changed files with 11 additions and 2 deletions

View file

@ -579,8 +579,9 @@ in
${config.lib.shell.exportAll cfg.sessionVariables}
'' + concatStringsSep "\n"
(mapAttrsToList
(env: values: ''
export ${env}="''$${env}''${${env}:+:}${concatStringsSep ":" values}"'')
(env: values: config.lib.shell.export
env
(config.lib.shell.appendToVar ":" env values))
cfg.sessionSearchVariables)
+ cfg.sessionVariablesExtra;
};

View file

@ -1,6 +1,14 @@
{ lib }:
rec {
# Produces a Bourne shell like statement that appends 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}";
# Produces a Bourne shell like variable export statement.
export = n: v: ''export ${n}="${toString v}"'';