Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for switching when no previous generation has existed #474

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions home-manager/home-manager
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
29 changes: 11 additions & 18 deletions modules/lib-bash/activation-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/' \
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down