Skip to content

Commit

Permalink
Handle use-xdg-base-directories for profile link
Browse files Browse the repository at this point in the history
  • Loading branch information
balsoft committed Mar 1, 2023
1 parent d5af43c commit 2fef0f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
29 changes: 6 additions & 23 deletions scripts/nix-profile-daemon.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,12 @@
if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi
__ETC_PROFILE_NIX_SOURCED=1

NIX_LINK=$HOME/.nix-profile
if [ -n "${XDG_STATE_HOME-}" ]; then
NIX_LINK_NEW="$XDG_STATE_HOME/nix/profile"
else
NIX_LINK_NEW=$HOME/.local/state/nix/profile
fi
if ! [ -e "$NIX_LINK" ]; then
NIX_LINK="$NIX_LINK_NEW"
else
if [ -t 2 ] && [ -e "$NIX_LINK_NEW" ]; then
warning="\033[1;35mwarning:\033[0m"
printf "$warning Both %s and legacy %s exist; using the latter.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2
if [ "$(realpath "$NIX_LINK")" = "$(realpath "$NIX_LINK_NEW")" ]; then
printf " Since the profiles match, you can safely delete either of them.\n" 1>&2
else
# This should be an exceptionally rare occasion: the only way to get it would be to
# 1. Update to newer Nix;
# 2. Remove .nix-profile;
# 3. Set the $NIX_LINK_NEW to something other than the default user profile;
# 4. Roll back to older Nix.
# If someone did all that, they can probably figure out how to migrate the profile.
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
fi
NIX_LINK="$HOME/.nix-profile"
if [[ $(nix show-config use-xdg-base-directories) == true ]]; then
if [[ -n "${XDG_STATE_HOME:-}" ]]; then
NIX_LINK="$XDG_STATE_HOME/nix/profile"
else
NIX_LINK="$HOME/.local/state/nix/profile"
fi
fi

Expand Down
28 changes: 5 additions & 23 deletions scripts/nix-profile.sh.in
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
if [ -n "$HOME" ] && [ -n "$USER" ]; then

# Set up the per-user profile.

NIX_LINK="$HOME/.nix-profile"
if [ -n "${XDG_STATE_HOME-}" ]; then
NIX_LINK_NEW="$XDG_STATE_HOME/nix/profile"
else
NIX_LINK_NEW="$HOME/.local/state/nix/profile"
fi
if ! [ -e "$NIX_LINK" ]; then
NIX_LINK="$NIX_LINK_NEW"
else
if [ -t 2 ] && [ -e "$NIX_LINK_NEW" ]; then
warning="\033[1;35mwarning:\033[0m"
printf "$warning Both %s and legacy %s exist; using the latter.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2
if [ "$(realpath "$NIX_LINK")" = "$(realpath "$NIX_LINK_NEW")" ]; then
printf " Since the profiles match, you can safely delete either of them.\n" 1>&2
else
# This should be an exceptionally rare occasion: the only way to get it would be to
# 1. Update to newer Nix;
# 2. Remove .nix-profile;
# 3. Set the $NIX_LINK_NEW to something other than the default user profile;
# 4. Roll back to older Nix.
# If someone did all that, they can probably figure out how to migrate the profile.
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
fi
if [[ $(nix show-config use-xdg-base-directories) == true ]]; then
if [[ -n "${XDG_STATE_HOME:-}" ]]; then
NIX_LINK="$XDG_STATE_HOME/nix/profile"
else
NIX_LINK="$HOME/.local/state/nix/profile"
fi
fi

Expand Down

0 comments on commit 2fef0f4

Please sign in to comment.