targets/darwin: copy fonts to ~/Library/Fonts/HomeManager (#1817)

Fonts are copied instead of being symlinked because macOS won't
recognize symlinked fonts.
This commit is contained in:
midchildan 2021-02-21 14:34:56 +09:00 committed by GitHub
parent da92360208
commit 2b7a73071a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -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;

View file

@ -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
'';
}