Skip to content

Commit 751f50f

Browse files
stefanbocaMic92
authored andcommitted
nix-profile{,-daemon}.fish: check for profile in XDG_DATA_HOME
...and also NIX_STATE_HOME in nix-profile.fish. This is directly translated from the bash scripts and makes the fish scripts equivalent in functionality to the bash scripts. Note that nix-profile.fish checks for NIX_STATE_HOME and nix-profile-daemon.fish does not, so the two scripts are no longer identical.
1 parent 087f268 commit 751f50f

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
@@ -24,7 +24,33 @@ end
2424

2525
# Set up the per-user profile.
2626

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

2955
# Set up environment.
3056
# 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
@@ -24,7 +24,38 @@ end
2424

2525
# Set up the per-user profile.
2626

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

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

0 commit comments

Comments
 (0)