Skip to content

programs/bash: refresh session variables in interactive shells - #9865

Open
khaneliman wants to merge 1 commit into
session-vars-7-resource-safefrom
session-vars-9-bash-refresh
Open

khaneliman wants to merge 1 commit into
session-vars-7-resource-safefrom
session-vars-9-bash-refresh

Conversation

@khaneliman

@khaneliman khaneliman commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Interactive non-login Bash shells now apply the session variables file, so a new terminal picks up values changed by home-manager switch. Zsh and Fish got this earlier in the stack; Bash needs its own gate: [[ $- == *i* ]] && ! shopt -q login_shell. Login shells are skipped because .profile already applied the file. Non-interactive shells are skipped because Bash can read .bashrc for remote commands, where startup output can corrupt protocols such as scp and rsync.

The generic Linux hook no longer sources the session variables file separately; it keeps its existing nix.sh call, which #9925 above replaces.

There is no ownership manifest; ordering does its job. The refresh runs first, then bashrcExtra, then initExtra, so anything that must survive is declared in a place that runs after it.

programs.bash.sessionVariables is reapplied after the generic values to preserve its precedence. Its expansions run whenever an interactive non-login shell starts. Direct self-references can therefore change repeatedly; Home Manager warns about the forms it can detect. Declarative search variables remain idempotent.

Stated compatibility break: a profileExtra assignment to a name Home Manager also manages previously reached these shells by inheritance and is now overwritten. The release note and news entry say so and point at initExtra as the migration target.

Part of splitting #9735 into independently reviewable changes; the stack as a whole supersedes that PR.

Checklist

  • Change is backwards compatible. (Stated break for profileExtra collisions; release note and news entry included.)
  • Code formatted with nix fmt.
  • Code tested through nix build .#test-all.
  • Test cases updated/added.
  • Commit messages follow the {component}: {description} format.

@github-actions github-actions Bot added the shell label Aug 28, 2026
@khaneliman khaneliman changed the title session vars 9 bash refresh programs/bash: refresh session variables in interactive shells Aug 28, 2026
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from b128abd to bd75139 Compare August 28, 2026 06:17
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from bd75139 to 4428531 Compare August 28, 2026 19:53
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch 2 times, most recently from aa02619 to 67aeef0 Compare August 28, 2026 20:58
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from 67aeef0 to 16cd53f Compare August 28, 2026 21:04
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch 2 times, most recently from a791e07 to b6a82f6 Compare August 29, 2026 04:20
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from b6a82f6 to b1d67a5 Compare August 29, 2026 04:47
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch 2 times, most recently from 41fb156 to 8ef4557 Compare August 29, 2026 14:26
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch 2 times, most recently from 06e09a5 to dcf95bb Compare August 30, 2026 03:48
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch 2 times, most recently from 56f2c74 to e16d832 Compare August 30, 2026 22:54
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from e16d832 to cc91b3b Compare August 30, 2026 23:49
@khaneliman
khaneliman marked this pull request as ready for review August 30, 2026 23:51
@home-manager-ci
home-manager-ci Bot requested a review from rycee August 30, 2026 23:52
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from cc91b3b to 23a62b0 Compare September 9, 2026 22:13
@khaneliman
khaneliman removed this pull request from stack #9866 September 11, 2026 03:12
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from 23a62b0 to 85ef91e Compare September 11, 2026 03:12
@khaneliman
khaneliman added this pull request to stack #9926 September 11, 2026 03:12
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from 85ef91e to 1e2413d Compare September 30, 2026 04:23
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch 2 times, most recently from 2fc1a77 to 6ed09be Compare October 1, 2026 02:11
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.
@khaneliman
khaneliman force-pushed the session-vars-9-bash-refresh branch from 6ed09be to 4bca12c Compare November 18, 2026 01:13
@github-actions github-actions Bot added the ai label Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant