Skip to content

targets/generic-linux: source nix.sh once - #9857

Closed
khaneliman wants to merge 1 commit into
masterfrom
generic-linux-source-nix-once
Closed

khaneliman wants to merge 1 commit into
masterfrom
generic-linux-source-nix-once

Conversation

@khaneliman

@khaneliman khaneliman commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

On generic Linux, Home Manager sources nix.sh through the guarded session variables file and directly from Bash initExtra. The direct call runs in interactive login and non-login shells. Since nix.sh is not idempotent, repeated Bash startup adds duplicate PATH and XDG_DATA_DIRS entries.

Remove the direct call, but retain PATH recovery. Login initialization can reset PATH while preserving __HM_SESS_VARS_SOURCED, so the guard does not guarantee that profile commands remain available. Bash now prepends the configured profile's bin directory only when it is missing. An existing entry keeps its position, preserving development-environment precedence.

This does not replay nix.sh to recover other removed environment values. The news entry documents that remaining boundary; #9925 at the top of the stack removes it.

Tests execute generated Bash startup files with an inherited guard and a reset PATH. They cover command lookup, repeated startup, and existing PATH precedence for traditional and XDG profiles. The existing counting test also checks that the guarded session file sources nix.sh only once.

This is a standalone bugfix at the bottom of the session-variable stack. Part of splitting #9735 into independently reviewable changes; the stack as a whole supersedes that PR.

Checklist

  • Change is backwards compatible. (Recovery of other removed nix.sh values changes; news entry included.)
  • Code formatted with nix fmt.
  • Focused Generic Linux tests pass.
  • Test cases updated/added.
  • Commit messages follow the {component}: {description} format.

@khaneliman khaneliman changed the title generic linux source nix once targets/generic-linux: source nix.sh once Aug 28, 2026
@khaneliman
khaneliman force-pushed the generic-linux-source-nix-once branch 2 times, most recently from 2363414 to bfc8228 Compare August 28, 2026 19:45
@khaneliman
khaneliman marked this pull request as ready for review August 28, 2026 20:22
@khaneliman
khaneliman force-pushed the generic-linux-source-nix-once branch from bfc8228 to 9cb0625 Compare September 9, 2026 21:44
Keep nix.sh inside the guarded session variables file to avoid duplicate
PATH and XDG_DATA_DIRS entries on interactive Bash startup. Restore a
missing profile bin directory after login PATH resets without moving an
existing entry or replaying other session initialization.

Exercise generated Bash startup with inherited guards for traditional
and XDG profiles. Document the remaining environment recovery boundary.
@khaneliman

Copy link
Copy Markdown
Collaborator Author

Folded into #9925 at the top of the stack. That change removes the direct nix.sh call and replaces the PATH-only repair with a full restore of the standard Nix environment, so there is no intermediate state where the repair exists and a later layer deletes it. The stack now starts at #9858 on master.

@khaneliman khaneliman closed this Sep 11, 2026
@khaneliman
khaneliman removed this pull request from stack #9866 September 11, 2026 03:12
@khaneliman
khaneliman deleted the generic-linux-source-nix-once branch September 11, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant