Merge pull request #9590 from wh0/patch-1

nix-profile: fix both profile links detection
This commit is contained in:
Robert Hensing 2024-06-03 14:37:08 +02:00 committed by GitHub
commit de5050f73b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

View file

@ -1,4 +1,5 @@
# Only execute this file once per shell.
# This file is tested by tests/installer/default.nix.
if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi
__ETC_PROFILE_NIX_SOURCED=1
@ -9,11 +10,9 @@ else
NIX_LINK_NEW=$HOME/.local/state/nix/profile
fi
if [ -e "$NIX_LINK_NEW" ]; then
NIX_LINK="$NIX_LINK_NEW"
else
if [ -t 2 ] && [ -e "$NIX_LINK_NEW" ]; then
if [ -t 2 ] && [ -e "$NIX_LINK" ]; 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
printf "$warning Both %s and legacy %s exist; using the former.\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
@ -26,6 +25,7 @@ else
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
fi
fi
NIX_LINK="$NIX_LINK_NEW"
fi
export NIX_PROFILES="@localstatedir@/nix/profiles/default $NIX_LINK"

View file

@ -1,3 +1,4 @@
# This file is tested by tests/installer/default.nix.
if [ -n "$HOME" ] && [ -n "$USER" ]; then
# Set up the per-user profile.
@ -9,11 +10,9 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then
NIX_LINK_NEW="$HOME/.local/state/nix/profile"
fi
if [ -e "$NIX_LINK_NEW" ]; then
NIX_LINK="$NIX_LINK_NEW"
else
if [ -t 2 ] && [ -e "$NIX_LINK_NEW" ]; then
if [ -t 2 ] && [ -e "$NIX_LINK" ]; 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
printf "$warning Both %s and legacy %s exist; using the former.\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
@ -26,6 +25,7 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then
printf "$warning Profiles do not match. You should manually migrate from %s to %s.\n" "$NIX_LINK" "$NIX_LINK_NEW" 1>&2
fi
fi
NIX_LINK="$NIX_LINK_NEW"
fi
# Set up environment.

View file

@ -13,6 +13,17 @@ let
'';
};
install-both-profile-links = {
script = ''
tar -xf ./nix.tar.xz
mv ./nix-* nix
ln -s $HOME/.local/state/nix/profiles/a-profile $HOME/.nix-profile
mkdir -p $HOME/.local/state/nix
ln -s $HOME/.local/state/nix/profiles/b-profile $HOME/.local/state/nix/profile
./nix/install --no-channel-add
'';
};
install-force-no-daemon = {
script = ''
tar -xf ./nix.tar.xz