mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 14:40:29 +00: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:
parent
4c85ff7ff2
commit
8af6838869
1 changed files with 6 additions and 0 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue