2018-02-27 19:31:03 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-01-16 19:26:42 +00:00
|
|
|
function setupVars() {
|
2020-04-25 16:24:13 +00:00
|
|
|
local nixStateDir="${NIX_STATE_DIR:-/nix/var/nix}"
|
|
|
|
local profilesPath="$nixStateDir/profiles/per-user/$USER"
|
|
|
|
local gcPath="$nixStateDir/gcroots/per-user/$USER"
|
2017-01-16 19:26:42 +00:00
|
|
|
|
2020-05-16 16:09:09 +00:00
|
|
|
genProfilePath="$profilesPath/home-manager"
|
|
|
|
newGenPath="@GENERATION_DIR@";
|
|
|
|
newGenGcPath="$gcPath/current-home"
|
|
|
|
|
|
|
|
local greatestGenNum
|
2017-01-16 19:26:42 +00:00
|
|
|
greatestGenNum=$( \
|
2020-05-16 16:09:09 +00:00
|
|
|
nix-env --list-generations --profile "$genProfilePath" \
|
|
|
|
| tail -1 \
|
|
|
|
| sed -E 's/ *([[:digit:]]+) .*/\1/')
|
2017-01-16 19:26:42 +00:00
|
|
|
|
2018-03-13 19:49:45 +00:00
|
|
|
if [[ -n $greatestGenNum ]] ; then
|
2017-01-16 19:26:42 +00:00
|
|
|
oldGenNum=$greatestGenNum
|
|
|
|
newGenNum=$((oldGenNum + 1))
|
|
|
|
else
|
|
|
|
newGenNum=1
|
|
|
|
fi
|
|
|
|
|
2020-05-16 16:09:09 +00:00
|
|
|
if [[ -e $profilesPath/home-manager ]] ; then
|
|
|
|
oldGenPath="$(readlink -e "$profilesPath/home-manager")"
|
2017-01-16 19:26:42 +00:00
|
|
|
fi
|
|
|
|
|
2018-03-13 19:49:45 +00:00
|
|
|
$VERBOSE_ECHO "Sanity checking oldGenNum and oldGenPath"
|
|
|
|
if [[ -v oldGenNum && ! -v oldGenPath
|
|
|
|
|| ! -v oldGenNum && -v oldGenPath ]]; then
|
2020-05-16 16:09:09 +00:00
|
|
|
errorEcho "Invalid profile number and current profile values! These"
|
|
|
|
errorEcho "must be either both empty or both set but are now set to"
|
2018-03-13 19:49:45 +00:00
|
|
|
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
|
2017-01-16 19:26:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 20:48:17 +00:00
|
|
|
if [[ -v VERBOSE ]]; then
|
2017-01-21 11:27:50 +00:00
|
|
|
export VERBOSE_ECHO=echo
|
|
|
|
export VERBOSE_ARG="--verbose"
|
|
|
|
else
|
|
|
|
export VERBOSE_ECHO=true
|
2017-03-25 20:48:17 +00:00
|
|
|
export VERBOSE_ARG=""
|
2017-01-21 11:27:50 +00:00
|
|
|
fi
|
|
|
|
|
2018-03-13 19:49:45 +00:00
|
|
|
echo "Starting home manager activation"
|
|
|
|
|
2020-05-20 20:17:37 +00:00
|
|
|
# Verify that we can connect to the Nix store and/or daemon. This will
|
|
|
|
# also create the necessary directories in profiles and gcroots.
|
|
|
|
$VERBOSE_ECHO "Sanity checking Nix"
|
|
|
|
nix-build --expr '{}' --no-out-link
|
|
|
|
|
2018-03-13 19:49:45 +00:00
|
|
|
setupVars
|
|
|
|
|
2017-03-25 20:48:17 +00:00
|
|
|
if [[ -v DRY_RUN ]] ; then
|
2017-08-17 08:16:30 +00:00
|
|
|
echo "This is a dry run"
|
2017-01-21 11:27:50 +00:00
|
|
|
export DRY_RUN_CMD=echo
|
2017-01-16 19:26:42 +00:00
|
|
|
else
|
2017-01-21 11:27:50 +00:00
|
|
|
$VERBOSE_ECHO "This is a live run"
|
2017-03-25 20:48:17 +00:00
|
|
|
export DRY_RUN_CMD=""
|
2017-01-16 19:26:42 +00:00
|
|
|
fi
|
|
|
|
|
2018-02-27 19:31:03 +00:00
|
|
|
if [[ -v VERBOSE ]]; then
|
|
|
|
echo -n "Using Nix version: "
|
|
|
|
nix-env --version
|
|
|
|
fi
|
|
|
|
|
2017-01-21 11:27:50 +00:00
|
|
|
$VERBOSE_ECHO "Activation variables:"
|
2017-03-28 22:10:30 +00:00
|
|
|
if [[ -v oldGenNum ]] ; then
|
|
|
|
$VERBOSE_ECHO " oldGenNum=$oldGenNum"
|
|
|
|
$VERBOSE_ECHO " oldGenPath=$oldGenPath"
|
|
|
|
else
|
|
|
|
$VERBOSE_ECHO " oldGenNum undefined (first run?)"
|
|
|
|
$VERBOSE_ECHO " oldGenPath undefined (first run?)"
|
|
|
|
fi
|
2017-01-21 11:27:50 +00:00
|
|
|
$VERBOSE_ECHO " newGenPath=$newGenPath"
|
2017-03-28 22:10:30 +00:00
|
|
|
$VERBOSE_ECHO " newGenNum=$newGenNum"
|
2017-01-21 11:27:50 +00:00
|
|
|
$VERBOSE_ECHO " newGenGcPath=$newGenGcPath"
|
2017-02-05 22:00:04 +00:00
|
|
|
$VERBOSE_ECHO " genProfilePath=$genProfilePath"
|