Skip to content

Commit 247f166

Browse files
authored
Merge pull request #13245 from stefanboca/sb/push-yoorqzwsxmzn
nix-profile{,-daemon}.fish: check for profile in XDG_DATA_HOME
2 parents d929eed + 751f50f commit 247f166

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

scripts/nix-profile-daemon.fish.in

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,33 @@ end
2323

2424
# Set up the per-user profile.
2525

26-
set --local NIX_LINK $HOME/.nix-profile
26+
set --local NIX_LINK "$HOME/.nix-profile"
27+
set --local NIX_LINK_NEW
28+
if test -n "$XDG_STATE_HOME"
29+
set NIX_LINK_NEW "$XDG_STATE_HOME/nix/profile"
30+
else
31+
set NIX_LINK_NEW "$HOME/.local/state/nix/profile"
32+
end
33+
if test -e "$NIX_LINK_NEW"
34+
if test -t 2; and test -e "$NIX_LINK"
35+
set --local warning "\033[1;35mwarning:\033[0m "
36+
printf "$warning Both %s and legacy %s exist; using the former.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2
37+
38+
if test (realpath "$NIX_LINK") = (realpath "$NIX_LINK_NEW")
39+
printf " Since the profiles match, you can safely delete either of them.\n" 1>&2
40+
else
41+
# This should be an exceptionally rare occasion: the only way to get it would be to
42+
# 1. Update to newer Nix;
43+
# 2. Remove .nix-profile;
44+
# 3. Set the $NIX_LINK_NEW to something other than the default user profile;
45+
# 4. Roll back to older Nix.
46+
# If someone did all that, they can probably figure out how to migrate the profile.
47+
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
48+
end
49+
end
50+
51+
set NIX_LINK "$NIX_LINK_NEW"
52+
end
2753

2854
# Set up environment.
2955
# This part should be kept in sync with nixpkgs:nixos/modules/programs/environment.nix

scripts/nix-profile.fish.in

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,38 @@ end
2323

2424
# Set up the per-user profile.
2525

26-
set --local NIX_LINK $HOME/.nix-profile
26+
set --local NIX_LINK
27+
if test -n "$NIX_STATE_HOME"
28+
set NIX_LINK "$NIX_STATE_HOME/.nix-profile"
29+
else
30+
set NIX_LINK "$HOME/.nix-profile"
31+
set --local NIX_LINK_NEW
32+
if test -n "$XDG_STATE_HOME"
33+
set NIX_LINK_NEW "$XDG_STATE_HOME/nix/profile"
34+
else
35+
set NIX_LINK_NEW "$HOME/.local/state/nix/profile"
36+
end
37+
if test -e "$NIX_LINK_NEW"
38+
if test -t 2; and test -e "$NIX_LINK"
39+
set --local warning "\033[1;35mwarning:\033[0m "
40+
printf "$warning Both %s and legacy %s exist; using the former.\n" "$NIX_LINK_NEW" "$NIX_LINK" 1>&2
41+
42+
if test (realpath "$NIX_LINK") = (realpath "$NIX_LINK_NEW")
43+
printf " Since the profiles match, you can safely delete either of them.\n" 1>&2
44+
else
45+
# This should be an exceptionally rare occasion: the only way to get it would be to
46+
# 1. Update to newer Nix;
47+
# 2. Remove .nix-profile;
48+
# 3. Set the $NIX_LINK_NEW to something other than the default user profile;
49+
# 4. Roll back to older Nix.
50+
# If someone did all that, they can probably figure out how to migrate the profile.
51+
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
52+
end
53+
end
54+
55+
set NIX_LINK "$NIX_LINK_NEW"
56+
end
57+
end
2758

2859
# Set up environment.
2960
# This part should be kept in sync with nixpkgs:nixos/modules/programs/environment.nix

0 commit comments

Comments
 (0)