mirror of
https://github.com/nix-community/home-manager
synced 2024-12-02 16:09:46 +01:00
files: extract common variable
Also improve the pattern used to determine whether a symlink target points to a Home Manager file path.
This commit is contained in:
parent
ccb291ce66
commit
811bc1b8e5
1 changed files with 6 additions and 5 deletions
|
@ -31,6 +31,10 @@ let
|
||||||
in
|
in
|
||||||
"home_file_" + safeName;
|
"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
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -140,7 +144,6 @@ in
|
||||||
# overwrite an existing file.
|
# overwrite an existing file.
|
||||||
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
||||||
let
|
let
|
||||||
pattern = "-home-manager-files/";
|
|
||||||
check = pkgs.writeText "check" ''
|
check = pkgs.writeText "check" ''
|
||||||
. ${./lib-bash/color-echo.sh}
|
. ${./lib-bash/color-echo.sh}
|
||||||
|
|
||||||
|
@ -150,7 +153,7 @@ in
|
||||||
relativePath="''${sourcePath#$newGenFiles/}"
|
relativePath="''${sourcePath#$newGenFiles/}"
|
||||||
targetPath="$HOME/$relativePath"
|
targetPath="$HOME/$relativePath"
|
||||||
if [[ -e "$targetPath" \
|
if [[ -e "$targetPath" \
|
||||||
&& ! "$(readlink "$targetPath")" =~ "${pattern}" ]] ; then
|
&& ! "$(readlink "$targetPath")" == ${homeFilePattern} ]] ; then
|
||||||
errorEcho "Existing file '$targetPath' is in the way"
|
errorEcho "Existing file '$targetPath' is in the way"
|
||||||
collision=1
|
collision=1
|
||||||
fi
|
fi
|
||||||
|
@ -176,8 +179,6 @@ 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
|
||||||
|
@ -200,7 +201,7 @@ 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 "$targetPath")" =~ "${pattern}" ]] ; then
|
elif [[ ! "$(readlink "$targetPath")" == ${homeFilePattern} ]] ; then
|
||||||
warnEcho "Path '$targetPath' not link into Home Manager generation. Skipping delete."
|
warnEcho "Path '$targetPath' not link into Home Manager generation. Skipping delete."
|
||||||
else
|
else
|
||||||
$VERBOSE_ECHO "Checking $targetPath: gone (deleting)"
|
$VERBOSE_ECHO "Checking $targetPath: gone (deleting)"
|
||||||
|
|
Loading…
Reference in a new issue