mirror of
https://github.com/nix-community/home-manager
synced 2024-07-06 05:13:28 +02:00
lib/shell: add appendToVar function
This commit is contained in:
parent
1e030277ba
commit
664086fa4c
|
@ -579,8 +579,9 @@ in
|
||||||
${config.lib.shell.exportAll cfg.sessionVariables}
|
${config.lib.shell.exportAll cfg.sessionVariables}
|
||||||
'' + concatStringsSep "\n"
|
'' + concatStringsSep "\n"
|
||||||
(mapAttrsToList
|
(mapAttrsToList
|
||||||
(env: values: ''
|
(env: values: config.lib.shell.export
|
||||||
export ${env}="''$${env}''${${env}:+:}${concatStringsSep ":" values}"'')
|
env
|
||||||
|
(config.lib.shell.appendToVar ":" env values))
|
||||||
cfg.sessionSearchVariables)
|
cfg.sessionSearchVariables)
|
||||||
+ cfg.sessionVariablesExtra;
|
+ cfg.sessionVariablesExtra;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
{ lib }:
|
{ lib }:
|
||||||
|
|
||||||
rec {
|
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.
|
# Produces a Bourne shell like variable export statement.
|
||||||
export = n: v: ''export ${n}="${toString v}"'';
|
export = n: v: ''export ${n}="${toString v}"'';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user