1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

home-manager: add 'remove-generations' command

This command allows the user to immediately remove specific
generations from the profiles directory.
This commit is contained in:
Robert Helgesson 2017-11-12 14:07:41 +01:00
parent 187a12e90a
commit 66219f23bb
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -163,6 +163,39 @@ function doListGens() {
popd > /dev/null
}
# Removes linked generations. Takes as arguments identifiers of
# generations to remove.
function doRmGenerations() {
if [[ -v VERBOSE ]]; then
export VERBOSE_ARG="--verbose"
else
export VERBOSE_ARG=""
fi
if [[ -v DRY_RUN ]] ; then
export DRY_RUN_CMD=echo
else
export DRY_RUN_CMD=""
fi
pushd "/nix/var/nix/profiles/per-user/$USER" > /dev/null
for generationId in "$@"; do
local linkName="home-manager-$generationId-link"
if [[ ! -e $linkName ]]; then
errorEcho "No generation with ID $generationId"
elif [[ $linkName == $(readlink home-manager) ]]; then
errorEcho "Cannot remove the current generation $generationId"
else
echo Removing generation $generationId
$DRY_RUN_CMD rm $VERBOSE_ARG $linkName
fi
done
popd > /dev/null
}
function doListPackages() {
local outPath
outPath="$(nix-env -q --out-path | grep -o '/.*home-manager-path$')"
@ -242,11 +275,21 @@ function doHelp() {
echo " -h Print this help"
echo
echo "Commands"
echo
echo " help Print this help"
echo
echo " build Build configuration into result directory"
echo
echo " switch Build and activate configuration"
echo
echo " generations List all home environment generations"
echo
echo " remove-generations ID..."
echo " Remove indicated generations. Use 'generations' command to"
echo " find suitable generation numbers."
echo
echo " packages List all packages installed in home-manager-path"
echo
echo " news Show news entries in a pager"
}
@ -285,7 +328,8 @@ done
# Get rid of the options.
shift "$((OPTIND-1))"
cmd="$*"
cmd="$1"
shift 1
case "$cmd" in
build)
@ -297,6 +341,9 @@ case "$cmd" in
generations)
doListGens
;;
remove-generations)
doRmGenerations "$@"
;;
packages)
doListPackages
;;