From 8af68388699185227295a077a4dd3a50440f5d88 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 29 Jun 2017 01:03:39 +0200 Subject: [PATCH] home-environment: prevent delete of non-managed files When a file has disappeared between the previous and the next generations then its symlink in `$HOME` is typically deleted. With this commit we refuse to delete the path unless we are reasonably certain it is a symlink into a Home Manager generation. --- modules/home-environment.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index f665833f1..79b4f3444 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -286,6 +286,8 @@ in home.activation.linkGeneration = dagEntryAfter ["writeBoundary"] ( let + pattern = "-home-manager-files/"; + link = pkgs.writeText "link" '' newGenFiles="$1" shift @@ -298,6 +300,8 @@ in ''; cleanup = pkgs.writeText "cleanup" '' + . ${./lib-bash/color-echo.sh} + newGenFiles="$1" oldGenFiles="$2" shift 2 @@ -306,6 +310,8 @@ in targetPath="$HOME/$relativePath" if [[ -e "$newGenFiles/$relativePath" ]] ; then $VERBOSE_ECHO "Checking $targetPath exists" + elif [[ ! "$(readlink -e "$targetPath")" =~ "${pattern}" ]] ; then + warnEcho "Path '$targetPath' not link into Home Manager generation. Skipping delete." else echo "Checking $targetPath gone (deleting)" $DRY_RUN_CMD rm $VERBOSE_ARG "$targetPath"