1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8
9 cfg = config.fonts.fontDir;
10
11 x11Fonts = pkgs.callPackage (
12 {
13 runCommand,
14 gzip,
15 xorg,
16 }:
17 runCommand "X11-fonts"
18 {
19 preferLocalBuild = true;
20 nativeBuildInputs = [
21 gzip
22 xorg.mkfontscale
23 xorg.mkfontdir
24 ];
25 }
26 ''
27 mkdir -p "$out/share/X11/fonts"
28 font_regexp='.*\.\(ttf\|ttc\|otb\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?'
29 find ${toString config.fonts.packages} -regex "$font_regexp" \
30 -exec ln -sf -t "$out/share/X11/fonts" '{}' \;
31 cd "$out/share/X11/fonts"
32 ${lib.optionalString cfg.decompressFonts ''
33 gunzip -f *.gz
34 ''}
35 mkfontscale
36 mkfontdir
37 cat $(find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias
38 ''
39 ) { };
40
41in
42
43{
44
45 options = {
46 fonts.fontDir = {
47
48 enable = lib.mkOption {
49 type = lib.types.bool;
50 default = false;
51 description = ''
52 Whether to create a directory with links to all fonts in
53 {file}`/run/current-system/sw/share/X11/fonts`.
54 '';
55 };
56
57 decompressFonts = lib.mkOption {
58 type = lib.types.bool;
59 default = config.programs.xwayland.enable;
60 defaultText = lib.literalExpression "config.programs.xwayland.enable";
61 description = ''
62 Whether to decompress fonts in
63 {file}`/run/current-system/sw/share/X11/fonts`.
64 '';
65 };
66
67 };
68 };
69
70 config = lib.mkIf cfg.enable {
71
72 environment.systemPackages = [ x11Fonts ];
73 environment.pathsToLink = [ "/share/X11/fonts" ];
74
75 services.xserver.filesSection = ''
76 FontPath "${x11Fonts}/share/X11/fonts"
77 '';
78
79 };
80
81 imports = [
82 (lib.mkRenamedOptionModule [ "fonts" "enableFontDir" ] [ "fonts" "fontDir" "enable" ])
83 ];
84
85}