1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-16 08:09:45 +01:00

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.
This commit is contained in:
Robert Helgesson 2017-06-29 01:03:39 +02:00
parent 4c85ff7ff2
commit 8af6838869
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -286,6 +286,8 @@ in
home.activation.linkGeneration = dagEntryAfter ["writeBoundary"] ( home.activation.linkGeneration = dagEntryAfter ["writeBoundary"] (
let let
pattern = "-home-manager-files/";
link = pkgs.writeText "link" '' link = pkgs.writeText "link" ''
newGenFiles="$1" newGenFiles="$1"
shift shift
@ -298,6 +300,8 @@ in
''; '';
cleanup = pkgs.writeText "cleanup" '' cleanup = pkgs.writeText "cleanup" ''
. ${./lib-bash/color-echo.sh}
newGenFiles="$1" newGenFiles="$1"
oldGenFiles="$2" oldGenFiles="$2"
shift 2 shift 2
@ -306,6 +310,8 @@ in
targetPath="$HOME/$relativePath" targetPath="$HOME/$relativePath"
if [[ -e "$newGenFiles/$relativePath" ]] ; then if [[ -e "$newGenFiles/$relativePath" ]] ; then
$VERBOSE_ECHO "Checking $targetPath exists" $VERBOSE_ECHO "Checking $targetPath exists"
elif [[ ! "$(readlink -e "$targetPath")" =~ "${pattern}" ]] ; then
warnEcho "Path '$targetPath' not link into Home Manager generation. Skipping delete."
else else
echo "Checking $targetPath gone (deleting)" echo "Checking $targetPath gone (deleting)"
$DRY_RUN_CMD rm $VERBOSE_ARG "$targetPath" $DRY_RUN_CMD rm $VERBOSE_ARG "$targetPath"