2018-09-30 13:22:24 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.fonts;
|
2019-02-17 11:21:12 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2022-04-19 10:30:52 -04:00
|
|
|
imports = [
|
2023-08-03 02:11:40 +01:00
|
|
|
(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.")
|
2023-08-03 02:11:40 +01:00
|
|
|
(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.'')
|
2022-04-19 10:30:52 -04:00
|
|
|
];
|
|
|
|
|
2018-09-30 13:22:24 +02:00
|
|
|
options = {
|
2023-08-03 02:11:40 +01:00
|
|
|
fonts.packages = lib.mkOption {
|
2023-08-03 02:28:06 +01:00
|
|
|
type = lib.types.listOf lib.types.path;
|
2022-09-25 14:12:08 -04:00
|
|
|
default = [ ];
|
2023-08-03 02:28:06 +01:00
|
|
|
example = lib.literalExpression "[ pkgs.dejavu_fonts ]";
|
2024-04-14 23:02:32 +02:00
|
|
|
description = ''
|
2023-08-03 02:11:40 +01:00
|
|
|
List of fonts to install into {file}`/Library/Fonts/Nix Fonts`.
|
2023-06-01 22:16:57 +01:00
|
|
|
'';
|
2018-09-30 13:22:24 +02:00
|
|
|
};
|
|
|
|
};
|
2019-02-17 11:21:12 +01:00
|
|
|
|
2018-09-30 14:37:31 +02:00
|
|
|
config = {
|
2019-02-17 11:21:12 +01:00
|
|
|
|
2022-09-25 14:12:08 -04:00
|
|
|
system.build.fonts = pkgs.runCommand "fonts"
|
2023-04-19 16:55:22 -04:00
|
|
|
{ preferLocalBuild = true; }
|
2019-02-17 11:21:12 +01:00
|
|
|
''
|
|
|
|
mkdir -p $out/Library/Fonts
|
2023-08-03 02:11:40 +01:00
|
|
|
store_dir=${lib.escapeShellArg builtins.storeDir}
|
2023-08-03 02:11:40 +01:00
|
|
|
while IFS= read -rd "" f; do
|
2023-08-03 02:11:40 +01:00
|
|
|
dest="$out/Library/Fonts/Nix Fonts/''${f#"$store_dir/"}"
|
|
|
|
mkdir -p "''${dest%/*}"
|
|
|
|
ln -sf "$f" "$dest"
|
2023-08-03 02:11:40 +01:00
|
|
|
done < <(
|
2023-08-03 02:11:40 +01:00
|
|
|
find -L ${lib.escapeShellArgs cfg.packages} \
|
2023-08-03 02:11:40 +01:00
|
|
|
-type f \
|
2023-08-03 02:11:40 +01:00
|
|
|
-regex '.*\.\(ttf\|ttc\|otf\|dfont\)' \
|
2023-08-03 02:11:40 +01:00
|
|
|
-print0
|
|
|
|
)
|
2019-02-17 11:21:12 +01:00
|
|
|
'';
|
|
|
|
|
2023-08-03 02:11:40 +01:00
|
|
|
system.activationScripts.fonts.text = ''
|
2023-08-03 02:11:40 +01:00
|
|
|
printf >&2 'setting up /Library/Fonts/Nix Fonts...\n'
|
2019-02-17 11:21:12 +01:00
|
|
|
|
2023-08-03 02:11:40 +01:00
|
|
|
# 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-10-06 17:55:21 +02:00
|
|
|
'';
|
2019-02-17 11:21:12 +01:00
|
|
|
|
2018-09-30 13:22:24 +02:00
|
|
|
};
|
|
|
|
}
|