From 811bc1b8e514e46da7de5ab250c94b9a31657157 Mon Sep 17 00:00:00 2001 From: Cornelius Mika Date: Mon, 6 Nov 2017 10:28:47 +0100 Subject: [PATCH] files: extract common variable Also improve the pattern used to determine whether a symlink target points to a Home Manager file path. --- modules/files.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/files.nix b/modules/files.nix index 011f685e3..8871aa1a2 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -31,6 +31,10 @@ let in "home_file_" + safeName; + # A symbolic link whose target path matches this pattern will be + # considered part of a Home Manager generation. + homeFilePattern = "${builtins.storeDir}/*-home-manager-files/*"; + in { @@ -140,7 +144,6 @@ in # overwrite an existing file. home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] ( let - pattern = "-home-manager-files/"; check = pkgs.writeText "check" '' . ${./lib-bash/color-echo.sh} @@ -150,7 +153,7 @@ in relativePath="''${sourcePath#$newGenFiles/}" targetPath="$HOME/$relativePath" if [[ -e "$targetPath" \ - && ! "$(readlink "$targetPath")" =~ "${pattern}" ]] ; then + && ! "$(readlink "$targetPath")" == ${homeFilePattern} ]] ; then errorEcho "Existing file '$targetPath' is in the way" collision=1 fi @@ -176,8 +179,6 @@ in home.activation.linkGeneration = dagEntryAfter ["writeBoundary"] ( let - pattern = "-home-manager-files/"; - link = pkgs.writeText "link" '' newGenFiles="$1" shift @@ -200,7 +201,7 @@ in targetPath="$HOME/$relativePath" if [[ -e "$newGenFiles/$relativePath" ]] ; then $VERBOSE_ECHO "Checking $targetPath: exists" - elif [[ ! "$(readlink "$targetPath")" =~ "${pattern}" ]] ; then + elif [[ ! "$(readlink "$targetPath")" == ${homeFilePattern} ]] ; then warnEcho "Path '$targetPath' not link into Home Manager generation. Skipping delete." else $VERBOSE_ECHO "Checking $targetPath: gone (deleting)"