1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-29 09:58:32 +02:00

files: minor cleanup

This commit is contained in:
Robert Helgesson 2021-06-27 23:31:20 +02:00
parent 85d67b0a6e
commit 9b7a90daa1
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89

View File

@ -162,7 +162,7 @@ in
# source and target generation. # source and target generation.
home.activation.linkGeneration = hm.dag.entryAfter ["writeBoundary"] ( home.activation.linkGeneration = hm.dag.entryAfter ["writeBoundary"] (
let let
link = pkgs.writeText "link" '' link = pkgs.writeShellScript "link" ''
newGenFiles="$1" newGenFiles="$1"
shift shift
for sourcePath in "$@" ; do for sourcePath in "$@" ; do
@ -177,7 +177,7 @@ in
done done
''; '';
cleanup = pkgs.writeText "cleanup" '' cleanup = pkgs.writeShellScript "cleanup" ''
. ${./lib-bash/color-echo.sh} . ${./lib-bash/color-echo.sh}
# A symbolic link whose target path matches this pattern will be # A symbolic link whose target path matches this pattern will be
@ -257,7 +257,9 @@ in
); );
home.activation.checkFilesChanged = hm.dag.entryBefore ["linkGeneration"] ( home.activation.checkFilesChanged = hm.dag.entryBefore ["linkGeneration"] (
'' let
homeDirArg = escapeShellArg homeDirectory;
in ''
function _cmp() { function _cmp() {
if [[ -d $1 && -d $2 ]]; then if [[ -d $1 && -d $2 ]]; then
diff -rq "$1" "$2" &> /dev/null diff -rq "$1" "$2" &> /dev/null
@ -266,10 +268,14 @@ in
fi fi
} }
declare -A changedFiles declare -A changedFiles
'' + concatMapStrings (v: '' '' + concatMapStrings (v:
_cmp ${escapeShellArg (sourceStorePath v)} ${escapeShellArg homeDirectory}/${escapeShellArg v.target} \ let
&& changedFiles[${escapeShellArg v.target}]=0 \ sourceArg = escapeShellArg (sourceStorePath v);
|| changedFiles[${escapeShellArg v.target}]=1 targetArg = escapeShellArg v.target;
in ''
_cmp ${sourceArg} ${homeDirArg}/${targetArg} \
&& changedFiles[${targetArg}]=0 \
|| changedFiles[${targetArg}]=1
'') (filter (v: v.onChange != "") (attrValues cfg)) '') (filter (v: v.onChange != "") (attrValues cfg))
+ '' + ''
unset -f _cmp unset -f _cmp
@ -286,12 +292,10 @@ in
# Symlink directories and files that have the right execute bit. # Symlink directories and files that have the right execute bit.
# Copy files that need their execute bit changed. # Copy files that need their execute bit changed.
home-files = pkgs.runCommand home-files = pkgs.runCommandLocal
"home-manager-files" "home-manager-files"
{ {
nativeBuildInputs = [ pkgs.xorg.lndir ]; nativeBuildInputs = [ pkgs.xorg.lndir ];
preferLocalBuild = true;
allowSubstitutes = false;
} }
('' (''
mkdir -p $out mkdir -p $out