|
24 | 24 |
|
25 | 25 | # Set up the per-user profile.
|
26 | 26 |
|
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 |
28 | 59 |
|
29 | 60 | # Set up environment.
|
30 | 61 | # This part should be kept in sync with nixpkgs:nixos/modules/programs/environment.nix
|
|
0 commit comments