diff --git a/home-manager/home-manager b/home-manager/home-manager index 65c54c637120..3acaf1a79836 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -249,6 +249,14 @@ function doRmGenerations() { function doExpireGenerations() { local profileDir="/nix/var/nix/profiles/per-user/$USER" + if ! [[ -d "${profileDir}" ]]; then + if [[ -v VERBOSE ]]; then + echo "No generations to expire" + fi + + return + fi + local generations generations="$( \ find "$profileDir" -name 'home-manager-*-link' -not -newermt "$1" \ diff --git a/modules/lib-bash/activation-init.sh b/modules/lib-bash/activation-init.sh index 5cdb66e5920f..6e67dc3388a5 100755 --- a/modules/lib-bash/activation-init.sh +++ b/modules/lib-bash/activation-init.sh @@ -5,6 +5,14 @@ function setupVars() { local gcPath="/nix/var/nix/gcroots/per-user/$USER" local greatestGenNum + if [[ ! -d "${profilesPath}" ]]; then + mkdir -p "${profilesPath}" + fi + + if [[ ! -d "${gcPath}" ]]; then + mkdir -p "${gcPath}" + fi + greatestGenNum=$( \ find "$profilesPath" -name 'home-manager-*-link' \ | sed 's/^.*-\([0-9]*\)-link$/\1/' \ @@ -13,30 +21,15 @@ function setupVars() { if [[ -n $greatestGenNum ]] ; then oldGenNum=$greatestGenNum - newGenNum=$((oldGenNum + 1)) else - newGenNum=1 + oldGenNum=0 fi + newGenNum=$((oldGenNum + 1)) if [[ -e $gcPath/current-home ]] ; then oldGenPath="$(readlink -e "$gcPath/current-home")" fi - $VERBOSE_ECHO "Sanity checking oldGenNum and oldGenPath" - if [[ -v oldGenNum && ! -v oldGenPath - || ! -v oldGenNum && -v oldGenPath ]]; then - errorEcho "Invalid profile number and GC root values! These must be" - errorEcho "either both empty or both set but are now set to" - errorEcho " '${oldGenNum:-}' and '${oldGenPath:-}'" - errorEcho "If you don't mind losing previous profile generations then" - errorEcho "the easiest solution is probably to run" - errorEcho " rm $profilesPath/home-manager*" - errorEcho " rm $gcPath/current-home" - errorEcho "and trying home-manager switch again. Good luck!" - exit 1 - fi - - genProfilePath="$profilesPath/home-manager" newGenPath="@GENERATION_DIR@"; newGenProfilePath="$profilesPath/home-manager-$newGenNum-link" @@ -69,7 +62,7 @@ if [[ -v VERBOSE ]]; then fi $VERBOSE_ECHO "Activation variables:" -if [[ -v oldGenNum ]] ; then +if [[ -v oldGenNum ]] && [[ "${oldGenNum}" -gt 0 ]] ; then $VERBOSE_ECHO " oldGenNum=$oldGenNum" $VERBOSE_ECHO " oldGenPath=$oldGenPath" else