Skip to content

targets/generic-linux: restore the Nix environment in child shells - #9925

Open
khaneliman wants to merge 1 commit into
session-vars-9-bash-refreshfrom
session-vars-10-nix-environment
Open

khaneliman wants to merge 1 commit into
session-vars-9-bash-refreshfrom
session-vars-10-nix-environment

Conversation

@khaneliman

@khaneliman khaneliman commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

On generic Linux, Home Manager sources nix.sh through the guarded session variables file and again from Bash initExtra. nix.sh is not idempotent, so every interactive Bash startup adds duplicate PATH and XDG_DATA_DIRS entries. Removing the direct call alone is not enough: a login environment can strip the values nix.sh set while keeping the exported session guard, and child shells then start without the Nix profile on PATH, without NIX_PROFILES, and without a certificate file.

Generic Linux now owns a repeatable initializer for the standard Nix environment, in POSIX and native Fish, and sources it instead of nix.sh. It fills PATH, XDG_DATA_DIRS, a nonempty MANPATH, and a missing NIX_PROFILES or NIX_SSL_CERT_FILE. Entries already present keep their positions. Explicit scalar values, including empty strings, are kept. Zsh applies the same initializer in its unchanged-token branch, with scalar fallbacks that preserve the precedence of home.sessionVariables and programs.zsh.sessionVariables declarations.

Profile selection follows the package: Nix 2.25 and later honor NIX_STATE_HOME; older Nix and Lix keep legacy or existing XDG selection.

Stated compatibility change: custom profile scripts shipped in a nix.package are no longer executed, so their additional side effects are not reproduced. The news entry says so.

Tests run the generated Bash, Zsh, and Fish startup files with an inherited guard and stripped values. They cover repeated application, explicit empty and custom scalars, existing PATH precedence, home and Zsh scalar declarations, and profile selection against real Lix package metadata. Startup was also checked against Debian's real login files as an unprivileged user in a container, and against actual Nix 2.34.8 and Lix 2.95.2 packages across legacy, XDG, and NIX_STATE_HOME layouts.

Top 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. (Stated change for custom nix.package profile scripts; 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.

@khaneliman
khaneliman added this pull request to stack #9866 September 11, 2026 02:45
@github-actions github-actions Bot added the shell label Sep 11, 2026
@home-manager-ci
home-manager-ci Bot requested a review from rycee September 11, 2026 02:46
@khaneliman
khaneliman removed this pull request from stack #9866 September 11, 2026 03:12
@khaneliman
khaneliman force-pushed the session-vars-10-nix-environment branch from 6a79140 to 55d6576 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-10-nix-environment branch 2 times, most recently from 366b22d to ca9caf9 Compare September 30, 2026 18:58
@khaneliman
khaneliman force-pushed the session-vars-10-nix-environment branch from ca9caf9 to 632a032 Compare October 1, 2026 02:11
ConorWilliams added a commit to ConorWilliams/nix that referenced this pull request Nov 8, 2026
Waiting on nix-community/home-manager#9925

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On generic Linux, Home Manager sourced nix.sh through the guarded
session variables file and again from Bash initExtra. nix.sh is not
idempotent, so every interactive Bash startup added duplicate PATH and
XDG_DATA_DIRS entries. Removing the direct call alone is not enough: a
login environment can strip the values nix.sh set while keeping the
exported session guard, and child shells then start without the Nix
profile on PATH, without NIX_PROFILES, and without a certificate file.

Generic Linux now owns a repeatable initializer for the standard Nix
environment, in POSIX and native Fish, and sources it instead of nix.sh.
It fills PATH, XDG_DATA_DIRS, a nonempty MANPATH, and a missing
NIX_PROFILES or NIX_SSL_CERT_FILE. Entries already present keep their
positions. Explicit scalar values, including empty strings, are kept.
Zsh applies the same initializer in its unchanged-token branch, with
scalar fallbacks that preserve home and Zsh declaration precedence.

Profile selection follows the package: Nix 2.25 and later honor
NIX_STATE_HOME; older Nix and Lix keep legacy or existing XDG selection.

Custom profile scripts shipped in a nix.package are no longer executed,
so their additional side effects are not reproduced. The news entry
states that change.

Tests run the generated Bash, Zsh, and Fish startup files with an
inherited guard and stripped values, check repeated application,
explicit empty and custom scalars, PATH precedence, and real Lix
metadata selection.
@khaneliman
khaneliman force-pushed the session-vars-10-nix-environment branch from 632a032 to f1cd942 Compare November 18, 2026 01:13

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant