1
1
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-09-11 12:49:18 +03:00
nix-darwin/modules/fonts/default.nix

68 lines
2.4 KiB
Nix
Raw Permalink Normal View History

2018-09-30 14:22:24 +03:00
{ config, lib, pkgs, ... }:
let
cfg = config.fonts;
in
{
imports = [
(lib.mkRemovedOptionModule [ "fonts" "enableFontDir" ] "No nix-darwin equivalent to this NixOS option. This is not required to install fonts.")
(lib.mkRemovedOptionModule [ "fonts" "fontDir" "enable" ] "No nix-darwin equivalent to this NixOS option. This is not required to install fonts.")
(lib.mkRemovedOptionModule [ "fonts" "fonts" ] ''
This option has been renamed to `fonts.packages' for consistency with NixOS.
Note that the implementation now keeps fonts in `/Library/Fonts/Nix Fonts' to allow them to coexist with fonts not managed by nix-darwin; existing fonts will be left directly in `/Library/Fonts' without getting updates and should be manually removed.'')
];
2018-09-30 14:22:24 +03:00
options = {
fonts.packages = lib.mkOption {
2023-08-03 04:28:06 +03:00
type = lib.types.listOf lib.types.path;
2022-09-25 21:12:08 +03:00
default = [ ];
2023-08-03 04:28:06 +03:00
example = lib.literalExpression "[ pkgs.dejavu_fonts ]";
2024-04-15 00:02:32 +03:00
description = ''
List of fonts to install into {file}`/Library/Fonts/Nix Fonts`.
2023-06-02 00:16:57 +03:00
'';
2018-09-30 14:22:24 +03:00
};
};
2018-09-30 15:37:31 +03:00
config = {
2022-09-25 21:12:08 +03:00
system.build.fonts = pkgs.runCommand "fonts"
{ preferLocalBuild = true; }
''
mkdir -p $out/Library/Fonts
store_dir=${lib.escapeShellArg builtins.storeDir}
while IFS= read -rd "" f; do
dest="$out/Library/Fonts/Nix Fonts/''${f#"$store_dir/"}"
mkdir -p "''${dest%/*}"
ln -sf "$f" "$dest"
done < <(
find -L ${lib.escapeShellArgs cfg.packages} \
-type f \
-regex '.*\.\(ttf\|ttc\|otf\|dfont\)' \
-print0
)
'';
system.activationScripts.fonts.text = ''
printf >&2 'setting up /Library/Fonts/Nix Fonts...\n'
# rsync uses the mtime + size of files to determine whether they
# need to be copied by default. This is inadequate for Nix store
# paths, but we don't want to use `--checksum` as it makes
# activation consistently slow when you have large fonts
# installed. Instead, we ensure that fonts are linked according to
# their full store paths in `system.build.fonts`, so that any
# given font path should only ever have one possible content.
${pkgs.rsync}/bin/rsync \
--archive \
--copy-links \
--delete-during \
--delete-missing-args \
"$systemConfig/Library/Fonts/Nix Fonts" \
'/Library/Fonts/'
'';
2018-09-30 14:22:24 +03:00
};
}