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