blob: b0bd63f524c74e2faa74230332117aba34e1dfbb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
{ 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.'')
];
options = {
fonts.packages = lib.mkOption {
type = lib.types.listOf lib.types.path;
default = [ ];
example = lib.literalExpression "[ pkgs.dejavu_fonts ]";
description = ''
List of fonts to install into {file}`/Library/Fonts/Nix Fonts`.
'';
};
};
config = {
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/'
'';
};
}
|