diff --git a/lix/libstore/profiles.cc b/lix/libstore/profiles.cc index 0482fc1bb..aa511fd86 100644 --- a/lix/libstore/profiles.cc +++ b/lix/libstore/profiles.cc @@ -153,8 +153,11 @@ void deleteGenerations( auto [gens, curGen] = findGenerations(profile); + if (!curGen) + throw Error("cannot find current generation of profile '%1%', is it a valid symlink?", profile); + if (gensToDelete.count(*curGen)) - throw Error("cannot delete current version of profile %1%'", profile); + throw Error("cannot delete current version of profile '%1%'", profile); for (auto & i : gens) { if (!gensToDelete.count(i.number)) continue; diff --git a/tests/functional/common/vars-and-functions.sh.in b/tests/functional/common/vars-and-functions.sh.in index 99a859f49..647926efa 100644 --- a/tests/functional/common/vars-and-functions.sh.in +++ b/tests/functional/common/vars-and-functions.sh.in @@ -68,6 +68,11 @@ clearProfiles() { rm -rf "$profiles" } +linkProfilesTo() { + target="$1" + ln -s "$HOME"/.local/state/nix/profiles "$target" +} + clearStore() { echo "clearing store..." chmod -R +w "$NIX_STORE_DIR" diff --git a/tests/functional/user-envs.sh b/tests/functional/user-envs.sh index bb48a8430..14c87ea69 100644 --- a/tests/functional/user-envs.sh +++ b/tests/functional/user-envs.sh @@ -4,6 +4,13 @@ if [ -z "${storeCleared-}" ]; then clearStore fi +# Test if invalid profiles symlinks are supported. +# https://git.lix.systems/lix-project/lix/issues/801 +VOID=$(mktemp -d) +rm -rf "$VOID" +linkProfilesTo $VOID +expectStderr 1 nix-env --delete-generations 0 | grepQuiet -E "error: cannot find current generation of profile '.*local/state/nix/profiles/profile', is it a valid symlink?" + clearProfiles # Query installed: should be empty.