experiment

This commit is contained in:
Robert Helgesson 2021-02-03 23:24:43 +01:00
parent fa8692f84c
commit 61475c4779
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
3 changed files with 22 additions and 5 deletions

View File

@ -479,7 +479,7 @@ in
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
${config.lib.shell.exportAll cfg.sessionVariables}
${config.lib.shell.exportAll' { colonVars = ["NIX_PATH" "PATH"]; } cfg.sessionVariables}
'' + lib.optionalString (cfg.sessionPath != [ ]) ''
export PATH="$PATH''${PATH:+:}${concatStringsSep ":" cfg.sessionPath}"
'' + cfg.sessionVariablesExtra;

View File

@ -4,8 +4,25 @@ rec {
# Produces a Bourne shell like variable export statement.
export = n: v: ''export ${n}="${toString v}"'';
export' = { colonVars ? [ ] }:
n: v:
let
replaceMatch = match:
lib.replaceStrings [ ":\$${match}:" ":\$${match}" "\$${match}:" ] [
"\${${match}:+:\$${match}:}"
"\${${match}:+:\$${match}}"
"\${${match}:+\$${match}:}"
];
mkValue = n: v:
if builtins.elem n colonVars then replaceMatch n v else toString v;
in ''export ${n}="${mkValue n v}"'';
# Given an attribute set containing shell variable names and their
# assignment, this function produces a string containing an export
# statement for each set entry.
exportAll = vars: lib.concatStringsSep "\n" (lib.mapAttrsToList export vars);
exportAll' = opts: vars:
lib.concatStringsSep "\n" (lib.mapAttrsToList (export' opts) vars);
}

View File

@ -13,8 +13,8 @@ let
export __HM_SESS_VARS_SOURCED=1
export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"
export NIX_PATH="testpath=$HOME/testpath:$NIX_PATH"
export PATH="$PATH:$HOME/bin"
export NIX_PATH="testpath=$HOME/testpath''${NIX_PATH:+:$NIX_PATH}"
export PATH="''${PATH:+$PATH:}$HOME/bin"
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"
@ -25,8 +25,8 @@ let
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
export NIX_PATH="testpath=$HOME/testpath:$NIX_PATH"
export PATH="$PATH:$HOME/bin"
export NIX_PATH="testpath=$HOME/testpath''${NIX_PATH:+:$NIX_PATH}"
export PATH="''${PATH:+$PATH:}$HOME/bin"
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"