Open
Conversation
convoliution
commented
Jan 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This change makes
nix-daemon.shidempotent, enabling any interactive shell to ensure it has itsPATHcorrectly configured for Nix-managed executables.Context
When a login shell starts an interactive shell, the latter is unable to access
nixand Nix-managed executables, or they are out-precedented by system executables. This leads to issues in tmux (issue #13255), SteamOS (issue #13355), and in my own experience the terminal in VS Code.This is because when the former shell executes
nix-daemon.sh(at the beginning of e.g.,/etc/zshrc), it exports a flag indicating the script has been run:nix/scripts/nix-profile-daemon.sh.in
Line 4 in a9b1a52
before modifying
PATHto give precedence to Nix-managed executables:nix/scripts/nix-profile-daemon.sh.in
Line 71 in a9b1a52
However, the latter shell inherits
__ETC_PROFILE_NIX_SOURCED, and so skips the entirety ofnix-daemon.sh:nix/scripts/nix-profile-daemon.sh.in
Line 3 in a9b1a52
thus missing out on the
PATHmodification.Implementation Strategy
This change first filters out possible duplicate Nix entries from
PATH(andXDG_DATA_DIRSwhile we're at it) by:s for ease of processing,:$NIX_ENTRY:s (replacing them with:s),:s from (1),and then finally prepending/appending the Nix entries as appropriate.
One possible issue is that since I'm using
sed, there may be edge cases involving regex metacharacters, but I think they're astronomically unlikely to actually cause a problem.Validation
I tried to access https://nix.dev/manual/nix/development/development/building.html but Anubis fails to load for me 🤖, so instead I just directly manually overwrote my local
/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.shBefore
Following tmux's behavior of creating login shells for new windows (tmux-users mailing list), which VS Code also does by default for its integrated terminal (source):
Entries are appended ahead of
/Users/convoliution/.nix-profile/bin:/nix/var/nix/profiles/default/bin. This happens because on macOS,/etc/zprofile(which runs before/etc/zshrc) modifiesPATHby calling thepath_helperutility (UNIX StackExchange). An analogous modification toPATHoccurs on Debian (issue #13255).After
And to verify that it's idempotent for the four environment variables it sets, barring changes to the user's profile or certificates:
Alternative Approaches
This is an alternative to PR #14697, which would revert PR #12805 by allowing
nix-daemon.shto be run multiple times but resulting in duplicate entries prepended toPATH(issue #5950).I felt there were two conflicting ideas here. PR #12805 (and the open PR #14922 for
nix.sh) which exports the flag is certainly a bug fix and desired behavior;nix-daemon.shhas always stated:nix/scripts/nix-profile-daemon.sh.in
Line 1 in a9b1a52
But the purpose and intended postcondition of
nix-daemon.shis clearly, among other things, to have Nix's*/bindirectories at the beginning ofPATH:nix/scripts/nix-profile-daemon.sh.in
Line 71 in a9b1a52
which PR #14697 guarantees.
By making
nix-daemon.shidempotent, we can have our script and run it too 🍰.Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.