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