mirror of
https://github.com/nix-community/home-manager
synced 2024-11-05 02:39:45 +01:00
files: fix use of onChange with directory source
Previously, the comparison would not handle directory comparison correctly, always finding that the source and target differed. This would trigger the `onChange` script on each activation. Fixes #2004
This commit is contained in:
parent
ab64dc3249
commit
07ad6a4f76
2 changed files with 25 additions and 1 deletions
|
@ -39,6 +39,17 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
assertions = [(
|
||||||
|
let
|
||||||
|
conflicts = mapAttrsToList (n: v: n)
|
||||||
|
(filterAttrs (n: v: v.recursive && v.onChange != "") cfg);
|
||||||
|
in {
|
||||||
|
assertion = conflicts == [];
|
||||||
|
message = ''
|
||||||
|
Cannot use 'home.file.<name>.onChange' when 'home.file.<name>.recursive' is enabled:
|
||||||
|
${concatStringsSep ", " conflicts}'';
|
||||||
|
})];
|
||||||
|
|
||||||
lib.file.mkOutOfStoreSymlink = path:
|
lib.file.mkOutOfStoreSymlink = path:
|
||||||
let
|
let
|
||||||
pathStr = toString path;
|
pathStr = toString path;
|
||||||
|
@ -236,12 +247,22 @@ in
|
||||||
|
|
||||||
home.activation.checkFilesChanged = hm.dag.entryBefore ["linkGeneration"] (
|
home.activation.checkFilesChanged = hm.dag.entryBefore ["linkGeneration"] (
|
||||||
''
|
''
|
||||||
|
function _cmp() {
|
||||||
|
if [[ -d $1 && -d $2 ]]; then
|
||||||
|
diff -rq "$1" "$2" &> /dev/null
|
||||||
|
else
|
||||||
|
cmp --quiet "$1" "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
declare -A changedFiles
|
declare -A changedFiles
|
||||||
'' + concatMapStrings (v: ''
|
'' + concatMapStrings (v: ''
|
||||||
cmp --quiet "${sourceStorePath v}" "${homeDirectory}/${v.target}" \
|
_cmp "${sourceStorePath v}" "${homeDirectory}/${v.target}" \
|
||||||
&& changedFiles["${v.target}"]=0 \
|
&& changedFiles["${v.target}"]=0 \
|
||||||
|| changedFiles["${v.target}"]=1
|
|| changedFiles["${v.target}"]=1
|
||||||
'') (filter (v: v.onChange != "") (attrValues cfg))
|
'') (filter (v: v.onChange != "") (attrValues cfg))
|
||||||
|
+ ''
|
||||||
|
unset -f _cmp
|
||||||
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
home.activation.onFilesChange = hm.dag.entryAfter ["linkGeneration"] (
|
home.activation.onFilesChange = hm.dag.entryAfter ["linkGeneration"] (
|
||||||
|
|
|
@ -82,6 +82,9 @@ with lib;
|
||||||
generations. The script will be run
|
generations. The script will be run
|
||||||
<emphasis>after</emphasis> the new files have been linked
|
<emphasis>after</emphasis> the new files have been linked
|
||||||
into place.
|
into place.
|
||||||
|
</para><para>
|
||||||
|
Note, this option cannot be used when <literal>recursive</literal>
|
||||||
|
is enabled.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue