files: add force
flag
Enabling this flag for a `home.file` entry causes the target to be
unconditionally overwritten. The option is not visible in
documentation for now and shouldn't be relied on for general use.
(cherry picked from commit 37694e9f51
)
This commit is contained in:
parent
0d1ca254d0
commit
57f3b72d3a
|
@ -45,6 +45,13 @@ in
|
||||||
# overwrite an existing file.
|
# overwrite an existing file.
|
||||||
home.activation.checkLinkTargets = dag.entryBefore ["writeBoundary"] (
|
home.activation.checkLinkTargets = dag.entryBefore ["writeBoundary"] (
|
||||||
let
|
let
|
||||||
|
# Paths that should be forcibly overwritten by Home Manager.
|
||||||
|
# Caveat emptor!
|
||||||
|
forcedPaths =
|
||||||
|
concatMapStringsSep " " (p: ''"$HOME/${p}"'')
|
||||||
|
(mapAttrsToList (n: v: v.target)
|
||||||
|
(filterAttrs (n: v: v.force) cfg));
|
||||||
|
|
||||||
check = pkgs.writeText "check" ''
|
check = pkgs.writeText "check" ''
|
||||||
. ${./lib-bash/color-echo.sh}
|
. ${./lib-bash/color-echo.sh}
|
||||||
|
|
||||||
|
@ -52,12 +59,25 @@ in
|
||||||
# considered part of a Home Manager generation.
|
# considered part of a Home Manager generation.
|
||||||
homeFilePattern="$(readlink -e "${builtins.storeDir}")/*-home-manager-files/*"
|
homeFilePattern="$(readlink -e "${builtins.storeDir}")/*-home-manager-files/*"
|
||||||
|
|
||||||
|
forcedPaths=(${forcedPaths})
|
||||||
|
|
||||||
newGenFiles="$1"
|
newGenFiles="$1"
|
||||||
shift
|
shift
|
||||||
for sourcePath in "$@" ; do
|
for sourcePath in "$@" ; do
|
||||||
relativePath="''${sourcePath#$newGenFiles/}"
|
relativePath="''${sourcePath#$newGenFiles/}"
|
||||||
targetPath="$HOME/$relativePath"
|
targetPath="$HOME/$relativePath"
|
||||||
if [[ -e "$targetPath" \
|
|
||||||
|
forced=""
|
||||||
|
for forcedPath in "''${forcedPaths[@]}"; do
|
||||||
|
if [[ $targetPath == $forcedPath* ]]; then
|
||||||
|
forced="yeah"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -n $forced ]]; then
|
||||||
|
$VERBOSE_ECHO "Skipping collision check for $targetPath"
|
||||||
|
elif [[ -e "$targetPath" \
|
||||||
&& ! "$(readlink "$targetPath")" == $homeFilePattern ]] ; then
|
&& ! "$(readlink "$targetPath")" == $homeFilePattern ]] ; then
|
||||||
if [[ ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
|
if [[ ! -L "$targetPath" && -n "$HOME_MANAGER_BACKUP_EXT" ]] ; then
|
||||||
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
|
backup="$targetPath.$HOME_MANAGER_BACKUP_EXT"
|
||||||
|
|
|
@ -86,6 +86,18 @@ in
|
||||||
into place.
|
into place.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
force = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
visible = false;
|
||||||
|
description = ''
|
||||||
|
Whether the target path should be unconditionally replaced
|
||||||
|
by the managed file source. Warning, this will silently
|
||||||
|
delete the target regardless of whether it is a file or
|
||||||
|
link.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
Loading…
Reference in a new issue