diff --git a/scripts/nix-profile-daemon.sh.in b/scripts/nix-profile-daemon.sh.in index 8cfd3149ee8..98adf46f768 100644 --- a/scripts/nix-profile-daemon.sh.in +++ b/scripts/nix-profile-daemon.sh.in @@ -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 diff --git a/scripts/nix-profile.sh.in b/scripts/nix-profile.sh.in index c4d60cf376a..b41437e536d 100644 --- a/scripts/nix-profile.sh.in +++ b/scripts/nix-profile.sh.in @@ -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