Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nix-profile*.sh.in: append PATHs idempotently
Browse files Browse the repository at this point in the history
When people source the Nix profile scripts more than once,
they can cause appended PATH variables to grow longer each
time. This is somewhat benign, but it does spook people and
cause support load.

(cherry picked from commit cc5db08)
abathur authored and kra-mo committed Nov 9, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8e222fb commit da701ca
Showing 2 changed files with 30 additions and 4 deletions.
11 changes: 9 additions & 2 deletions scripts/nix-profile-daemon.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Only execute this file once per shell.
if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi
__ETC_PROFILE_NIX_SOURCED=1
export __ETC_PROFILE_NIX_SOURCED=1

NIX_LINK=$HOME/.nix-profile
if [ -n "${XDG_STATE_HOME-}" ]; then
@@ -60,5 +60,12 @@ else
unset -f check_nix_profiles
fi

export PATH="$NIX_LINK/bin:@localstatedir@/nix/profiles/default/bin:$PATH"
# only append once
case ":$PATH:" in
*:"$NIX_LINK/bin:@localstatedir@/nix/profiles/default/bin":*)
;;
*)
export PATH="$NIX_LINK/bin:@localstatedir@/nix/profiles/default/bin:$PATH"
;;
esac
unset NIX_LINK
23 changes: 21 additions & 2 deletions scripts/nix-profile.sh.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Only execute this file once per shell.
if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi
export __ETC_PROFILE_NIX_SOURCED=1

if [ -n "$HOME" ] && [ -n "$USER" ]; then

# Set up the per-user profile.
@@ -51,9 +55,24 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then
# pick up `.nix-profile/share/man` because is it close to `.nix-profile/bin`
# which is in the $PATH. For more info, run `manpath -d`.
if [ -n "${MANPATH-}" ]; then
export MANPATH="$NIX_LINK/share/man:$MANPATH"
# only append once
case ":$MANPATH:" in
*:"$NIX_LINK/share/man":*)
;;
*)
export MANPATH="$NIX_LINK/share/man:$MANPATH"
;;
esac
fi

export PATH="$NIX_LINK/bin:$PATH"
# only append once
case ":$PATH:" in
*:"$NIX_LINK/bin":*)
;;
*)
export PATH="$NIX_LINK/bin:$PATH"
;;
esac

unset NIX_LINK NIX_LINK_NEW
fi

0 comments on commit da701ca

Please sign in to comment.