From 6ade7aed9046f168111230ec68be4257bf12a263 Mon Sep 17 00:00:00 2001 From: Albert Peschar Date: Mon, 19 Feb 2024 00:09:58 +0200 Subject: [PATCH] darwin: fonts: speed up font installation * Skip font installation if the derivation hasn't changed. * Use `rsync` instead of `install` to copy font files, to avoid useless copying of pre-existent identical files. --- modules/targets/darwin/fonts.nix | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/modules/targets/darwin/fonts.nix b/modules/targets/darwin/fonts.nix index 78723c43d..988c5edc9 100644 --- a/modules/targets/darwin/fonts.nix +++ b/modules/targets/darwin/fonts.nix @@ -10,20 +10,17 @@ let pathsToLink = "/share/fonts"; }; fonts = "${fontsEnv}/share/fonts"; + installDir = "${homeDir}/Library/Fonts/HomeManager"; in { # macOS won't recognize symlinked fonts config = mkIf pkgs.stdenv.hostPlatform.isDarwin { - home.activation.copyFonts = hm.dag.entryAfter [ "writeBoundary" ] '' - copyFonts() { - rm -rf ${homeDir}/Library/Fonts/HomeManager || : - - local f - find -L "${fonts}" -type f -printf '%P\0' | while IFS= read -rd "" f; do - run install $VERBOSE_ARG -Dm644 -T \ - "${fonts}/$f" "${homeDir}/Library/Fonts/HomeManager/$f" - done - } - copyFonts - ''; + home.file."Library/Fonts/.home-manager-fonts-version" = { + text = "${fontsEnv}"; + onChange = '' + run mkdir -p ${escapeShellArg installDir} + run ${pkgs.rsync}/bin/rsync $VERBOSE_ARG -acL --chmod=u+w --delete \ + ${escapeShellArgs [ "${fonts}/" installDir ]} + ''; + }; }; }