From f44b2077f5a10d1b4c6097c8389289e0467617ea Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Sun, 2 Dec 2018 01:08:59 -0800 Subject: [PATCH 1/5] home-manager: fix error attempting to expire generations This happens only when the user does not have a profile directory yet. --- home-manager/home-manager | 8 ++++++++ 1 file changed, 8 insertions(+) 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" \ From 99b6f637c042347ec5d8336b937403baa240dc27 Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Sun, 2 Dec 2018 02:17:44 -0800 Subject: [PATCH 2/5] activation: do not error out if the user has no profile yet --- modules/lib-bash/activation-init.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/lib-bash/activation-init.sh b/modules/lib-bash/activation-init.sh index 5cdb66e5920f..89080b78349a 100755 --- a/modules/lib-bash/activation-init.sh +++ b/modules/lib-bash/activation-init.sh @@ -5,17 +5,19 @@ function setupVars() { local gcPath="/nix/var/nix/gcroots/per-user/$USER" local greatestGenNum - greatestGenNum=$( \ - find "$profilesPath" -name 'home-manager-*-link' \ - | sed 's/^.*-\([0-9]*\)-link$/\1/' \ - | sort -rn \ - | head -1) + newGenNum=1 - if [[ -n $greatestGenNum ]] ; then - oldGenNum=$greatestGenNum - newGenNum=$((oldGenNum + 1)) - else - newGenNum=1 + if [[ -d "${profilesPath}" ]]; then + greatestGenNum=$( \ + find "$profilesPath" -name 'home-manager-*-link' \ + | sed 's/^.*-\([0-9]*\)-link$/\1/' \ + | sort -rn \ + | head -1) + + if [[ -n $greatestGenNum ]] ; then + oldGenNum=$greatestGenNum + newGenNum=$((oldGenNum + 1)) + fi fi if [[ -e $gcPath/current-home ]] ; then From 47f93faf344691fb9dcf7f04218da22a7d13b10e Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Wed, 20 Feb 2019 22:53:35 -0800 Subject: [PATCH 3/5] create the profile/gc-root --- modules/lib-bash/activation-init.sh | 43 ++++++++++++----------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/modules/lib-bash/activation-init.sh b/modules/lib-bash/activation-init.sh index 89080b78349a..e0dbd7f277b7 100755 --- a/modules/lib-bash/activation-init.sh +++ b/modules/lib-bash/activation-init.sh @@ -5,40 +5,31 @@ function setupVars() { local gcPath="/nix/var/nix/gcroots/per-user/$USER" local greatestGenNum - newGenNum=1 + if [[ ! -d "${profilesPath}" ]]; then + mkdir -p "${profilesPath}" + fi + + if [[ ! -d "${gcPath}" ]]; then + mkdir -p "${gcPath}" + fi - if [[ -d "${profilesPath}" ]]; then - greatestGenNum=$( \ - find "$profilesPath" -name 'home-manager-*-link' \ - | sed 's/^.*-\([0-9]*\)-link$/\1/' \ - | sort -rn \ - | head -1) + greatestGenNum=$( \ + find "$profilesPath" -name 'home-manager-*-link' \ + | sed 's/^.*-\([0-9]*\)-link$/\1/' \ + | sort -rn \ + | head -1) - if [[ -n $greatestGenNum ]] ; then - oldGenNum=$greatestGenNum - newGenNum=$((oldGenNum + 1)) - fi + if [[ -n $greatestGenNum ]] ; then + oldGenNum=$greatestGenNum + else + 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" From 82a4c3250fd3a30c8c214182d2f5e7081360055f Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Wed, 20 Feb 2019 23:29:08 -0800 Subject: [PATCH 4/5] protect aginst an unbound variable --- modules/lib-bash/activation-init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lib-bash/activation-init.sh b/modules/lib-bash/activation-init.sh index e0dbd7f277b7..6e67dc3388a5 100755 --- a/modules/lib-bash/activation-init.sh +++ b/modules/lib-bash/activation-init.sh @@ -62,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 From 4f240a7f2895fad57b7c5040ceedd472f94f1157 Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Thu, 21 Feb 2019 00:21:23 -0800 Subject: [PATCH 5/5] run the tests