From e8950c147c1aa252c6d5d948b1c6bb43384aa499 Mon Sep 17 00:00:00 2001 From: Illia Bobyr Date: Tue, 16 Dec 2025 02:52:33 -0800 Subject: [PATCH] nix-profile.fish: $NIX_STATE_HOME: Warn about old .nix-profile It seems reasonable to check if both `.nix-profile` and `.local/state/nix/profile` are present when `$NIX_STATE_HOME` is set. Even more so, `$XDG_STATE_HOME` is used in the `$NIX_LINK_NEW` logic, that was effectively disabled in `nix-profile.fish`. Note that `.local/state/nix/profile` is actually an incorrect path, it will be fixed in a subsequent commit. --- scripts/nix-profile-daemon.fish.in | 1 + scripts/nix-profile.fish.in | 49 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/scripts/nix-profile-daemon.fish.in b/scripts/nix-profile-daemon.fish.in index 1a20dffd2459..63a0c46fdaf3 100644 --- a/scripts/nix-profile-daemon.fish.in +++ b/scripts/nix-profile-daemon.fish.in @@ -24,6 +24,7 @@ end # Set up the per-user profile. set --local NIX_LINK "$HOME/.nix-profile" + set --local NIX_LINK_NEW if test -n "$XDG_STATE_HOME" set NIX_LINK_NEW "$XDG_STATE_HOME/nix/profile" diff --git a/scripts/nix-profile.fish.in b/scripts/nix-profile.fish.in index abf716cec6fc..fb3d8cb88e88 100644 --- a/scripts/nix-profile.fish.in +++ b/scripts/nix-profile.fish.in @@ -28,32 +28,33 @@ if test -n "$NIX_STATE_HOME" set NIX_LINK "$NIX_STATE_HOME/.nix-profile" else set NIX_LINK "$HOME/.nix-profile" - set --local NIX_LINK_NEW - if test -n "$XDG_STATE_HOME" - set NIX_LINK_NEW "$XDG_STATE_HOME/nix/profile" - else - set NIX_LINK_NEW "$HOME/.local/state/nix/profile" - end - if test -e "$NIX_LINK_NEW" - if test -t 2; and test -e "$NIX_LINK" - set --local warning "\033[1;35mwarning:\033[0m " - printf "$warning Both %s and legacy %s exist; using the former.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2 - - if test (realpath "$NIX_LINK") = (realpath "$NIX_LINK_NEW") - 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 - end - end +end - set NIX_LINK "$NIX_LINK_NEW" +set --local NIX_LINK_NEW +if test -n "$XDG_STATE_HOME" + set NIX_LINK_NEW "$XDG_STATE_HOME/nix/profile" +else + set NIX_LINK_NEW "$HOME/.local/state/nix/profile" +end +if test -e "$NIX_LINK_NEW" + if test -t 2; and test -e "$NIX_LINK" + set --local warning "\033[1;35mwarning:\033[0m " + printf "$warning Both %s and legacy %s exist; using the former.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2 + + if test (realpath "$NIX_LINK") = (realpath "$NIX_LINK_NEW") + 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 + end end + + set NIX_LINK "$NIX_LINK_NEW" end # Set up environment.