aboutsummaryrefslogtreecommitdiff
path: root/home-manager
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2019-04-28 00:33:41 +0200
committerRobert Helgesson <robert@rycee.net>2019-04-28 18:40:41 +0200
commit3bb7c75db3bfa229fc71ce381f95447fcd46a4f9 (patch)
tree997f1a1459a000b7872d9389e14f22213e9bb260 /home-manager
parentc94eaa0e6c2cba37e38ff5e137d87b97d67b79b9 (diff)
home-manager: add uninstall command
Diffstat (limited to 'home-manager')
-rw-r--r--home-manager/home-manager86
1 files changed, 75 insertions, 11 deletions
diff --git a/home-manager/home-manager b/home-manager/home-manager
index 0cf65676cfd..85feaae400d 100644
--- a/home-manager/home-manager
+++ b/home-manager/home-manager
@@ -10,6 +10,20 @@ function errorEcho() {
echo $* >&2
}
+function setVerboseAndDryRun() {
+ 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
+}
+
function setWorkDir() {
if [[ ! -v WORK_DIR ]]; then
WORK_DIR="$(mktemp --tmpdir -d home-manager-build.XXXXXXXXXX)"
@@ -216,17 +230,7 @@ function doListGens() {
# 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
+ setVerboseAndDryRun
pushd "/nix/var/nix/profiles/per-user/$USER" > /dev/null
@@ -246,6 +250,11 @@ function doRmGenerations() {
popd > /dev/null
}
+function doRmAllGenerations() {
+ $DRY_RUN_CMD rm $VERBOSE_ARG \
+ "/nix/var/nix/profiles/per-user/$USER/home-manager"*
+}
+
function doExpireGenerations() {
local profileDir="/nix/var/nix/profiles/per-user/$USER"
@@ -347,6 +356,56 @@ function doShowNews() {
fi
}
+function doUninstall() {
+ setVerboseAndDryRun
+
+ echo "This will remove Home Manager from your system."
+
+ if [[ -v DRY_RUN ]]; then
+ echo "This is a dry run, nothing will actually be uninstalled."
+ fi
+
+ local confirmation
+ read -r -n 1 -p "Really uninstall Home Manager? [y/n] " confirmation
+ echo
+
+ case $confirmation in
+ y|Y)
+ echo "Switching to empty Home Manager configuration..."
+ HOME_MANAGER_CONFIG="$(mktemp --tmpdir home-manager.XXXXXXXXXX)"
+ echo "{}" > "$HOME_MANAGER_CONFIG"
+ doSwitch
+ rm "$HOME_MANAGER_CONFIG"
+ $DRY_RUN_CMD rm $VERBOSE_ARG -r \
+ "${XDG_DATA_HOME:-$HOME/.local/share}/home-manager"
+ $DRY_RUN_CMD rm $VERBOSE_ARG \
+ "/nix/var/nix/gcroots/per-user/$USER/current-home"
+ ;;
+ *)
+ echo "Yay!"
+ exit 0
+ ;;
+ esac
+
+ local deleteProfiles
+ read -r -n 1 \
+ -p 'Remove all Home Manager generations? [y/n] ' \
+ deleteProfiles
+ echo
+
+ case $deleteProfiles in
+ y|Y)
+ doRmAllGenerations
+ echo "All generations are now eligible for garbage collection."
+ ;;
+ *)
+ echo "Leaving generations but they may still be garbage collected."
+ ;;
+ esac
+
+ echo "Home Manager is uninstalled but your home.nix is left untouched."
+}
+
function doHelp() {
echo "Usage: $0 [OPTION] COMMAND"
echo
@@ -385,6 +444,8 @@ function doHelp() {
echo " packages List all packages installed in home-manager-path"
echo
echo " news Show news entries in a pager"
+ echo
+ echo " uninstall Remove Home Manager"
}
EXTRA_NIX_PATH=()
@@ -466,6 +527,9 @@ case "$cmd" in
news)
doShowNews --all
;;
+ uninstall)
+ doUninstall
+ ;;
help|--help)
doHelp
;;