From 2b7a73071a2810726edf39b8e57d47b5e3844b9e Mon Sep 17 00:00:00 2001 From: midchildan Date: Sun, 21 Feb 2021 14:34:56 +0900 Subject: [PATCH] targets/darwin: copy fonts to ~/Library/Fonts/HomeManager (#1817) Fonts are copied instead of being symlinked because macOS won't recognize symlinked fonts. --- modules/targets/darwin/default.nix | 2 +- modules/targets/darwin/fonts.nix | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 modules/targets/darwin/fonts.nix diff --git a/modules/targets/darwin/default.nix b/modules/targets/darwin/default.nix index 961c8667e..b971e18d2 100644 --- a/modules/targets/darwin/default.nix +++ b/modules/targets/darwin/default.nix @@ -19,7 +19,7 @@ let writableDefaults = filterAttrs (domain: attrs: attrs != { }) nonNullDefaults; activationCmds = mapAttrsToList toActivationCmd writableDefaults; in { - imports = [ ./keybindings.nix ./linkapps.nix ./search.nix ]; + imports = [ ./fonts.nix ./keybindings.nix ./linkapps.nix ./search.nix ]; options.targets.darwin.defaults = mkOption { type = types.submodule ./options.nix; diff --git a/modules/targets/darwin/fonts.nix b/modules/targets/darwin/fonts.nix new file mode 100644 index 000000000..bc4042a8d --- /dev/null +++ b/modules/targets/darwin/fonts.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + homeDir = config.home.homeDirectory; + fontsEnv = pkgs.buildEnv { + name = "home-manager-fonts"; + paths = config.home.packages; + pathsToLink = "/share/fonts"; + }; + fonts = "${fontsEnv}/share/fonts"; +in { + # macOS won't recognize symlinked fonts + config.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 + $DRY_RUN_CMD install $VERBOSE_ARG -Dm644 -T \ + "${fonts}/$f" "${homeDir}/Library/Fonts/HomeManager/$f" + done + } + copyFonts + ''; +}