Interactive non-login Bash shells now apply the current session
variables file before bashrcExtra and initExtra. New terminals pick up
values changed by home-manager switch.
Login shells skip the refresh because .profile already applied it.
Non-interactive shells skip it because sshd can read .bashrc for remote
commands, where startup output can corrupt protocols such as scp and
rsync.
Apply programs.bash.sessionVariables after generic values to preserve
its precedence. Expansions run on every interactive non-login shell, so
warn when direct self-references can change repeatedly. Declarative
search paths remain stable across repeated sourcing.
A profileExtra assignment that collides with a Home Manager-managed
variable is now overwritten in non-login shells. Move such overrides to
initExtra, which runs after the refresh.
targets.genericLinux no longer needs its separate initExtra source.
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#3999Closes#4559
Allow boolean values in sessionVariables for Home Manager shell modules and serialize them consistently in generated session files.
- modules/lib/shell: stringify boolean values using lib.boolToString in export helper
- modules/home-environment, programs.bash, programs.zsh: include lib.types.bool in sessionVariables option type
- tests: add IS_TRUE/IS_FALSE assertions in home-environment, bash, and zsh session-variables tests
Some applications consider environment variables to be “true” simply if
they are set. Previously it was not possible to have a var set and later
override (e.g. with `lib.mkForce`) to *unset* it. This makes that
possible. The filtering must be done in the `exportAll` as attempting to
do it in the option’s `apply` causing infinite recursion (likely why it
is `lazyAttrsOf`).
Instead of having to manually stub packages that should not be
downloaded we instead automatically stub all packages (except a small
list of whitelisted ones). Tests can re-introduce the real package by
using the `realPkgs` module argument.
Before the XDG variables would be set from the user's environment, if
available. This would break some tests.
With this change the tests should be fully deterministic.
Fixes#1190
This replaces some derivation outputs by simple strings rather than
full Nix store paths. This removes the need to download the whole
derivation when all we need is a static string.
Unfortunately, using `attrsOf` is not possible since it results in too
eager evaluation. In particular, the
home.sessionVariables = {
FOO = "Hello";
BAR = "${config.home.sessionVariables.FOO} World!";
};
example will cause an infinite recursion.
This commit restores the option type of
- `home.sessionVariables`,
- `pam.sessionVariables`,
- `programs.bash.sessionVariables`, and
- `programs.zsh.sessionVariables`
to `attrs`. It also adds test cases for the above options to avoid
regressions.
Fixes#659