Files
home-manager/tests/modules/programs/bash/session-variables.nix
Austin Horstman 1553bea9ff home-environment: refresh session vars in shells
Move the once-per-session guard to the final extra-code section. Plain
and search variables can then refresh without rerunning arbitrary code.
Keep the extra body top-level so shell parse behavior stays unchanged.

Use an exported generation token for Zsh. Changes to generic or
Zsh-specific values reapply both layers, while unchanged nested shells
keep Zsh precedence and do not repeat self-references.

Plain values are re-evaluated each time the file is applied. Command
substitutions run again, and some self-references can change repeatedly.
Removing a variable still requires a new session.

Closes #3999
Closes #4559
2026-09-30 21:06:23 -05:00

42 lines
1.0 KiB
Nix

{ config, ... }:
{
programs.bash = {
enable = true;
enableCompletion = false;
sessionVariables = {
V1 = "v1";
V2 = "v2-${config.programs.bash.sessionVariables.V1}";
IS_EMPTY = "";
IS_NULL = null;
IS_TRUE = true;
IS_FALSE = false;
};
};
nmt.script = ''
sessionVars=home-path/etc/profile.d/hm-session-vars.sh
env -u __HM_SESS_VARS_SOURCED "$BASH" --noprofile --norc -uc '
. "$1"
[ "$__HM_SESS_VARS_SOURCED" = 1 ]
' shell "$TESTED/$sessionVars" \
|| fail "an empty extra section did not set the sourced marker"
assertFileExists home-files/.profile
assertFileContent \
"$(normalizeStorePaths home-files/.profile)" \
${builtins.toFile "session-variables-expected" ''
. "/nix/store/00000000000000000000000000000000-hm-session-vars.sh/etc/profile.d/hm-session-vars.sh"
export IS_EMPTY=""
export IS_FALSE="false"
export IS_TRUE="true"
export V1="v1"
export V2="v2-v1"
''}
'';
}