1 { config, lib, pkgs, ... }:
4 cfg = config.fonts.fontDir;
6 x11Fonts = pkgs.runCommand "X11-fonts" { preferLocalBuild = true; } ''
7 mkdir -p "$out/share/X11/fonts"
8 font_regexp='.*\.\(ttf\|ttc\|otb\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?'
9 find ${toString config.fonts.packages} -regex "$font_regexp" \
10 -exec ln -sf -t "$out/share/X11/fonts" '{}' \;
11 cd "$out/share/X11/fonts"
12 ${lib.optionalString cfg.decompressFonts ''
13 ${pkgs.gzip}/bin/gunzip -f *.gz
15 ${pkgs.xorg.mkfontscale}/bin/mkfontscale
16 ${pkgs.xorg.mkfontdir}/bin/mkfontdir
17 cat $(find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias
27 enable = lib.mkOption {
28 type = lib.types.bool;
31 Whether to create a directory with links to all fonts in
32 {file}`/run/current-system/sw/share/X11/fonts`.
36 decompressFonts = lib.mkOption {
37 type = lib.types.bool;
38 default = config.programs.xwayland.enable;
39 defaultText = lib.literalExpression "config.programs.xwayland.enable";
41 Whether to decompress fonts in
42 {file}`/run/current-system/sw/share/X11/fonts`.
49 config = lib.mkIf cfg.enable {
51 environment.systemPackages = [ x11Fonts ];
52 environment.pathsToLink = [ "/share/X11/fonts" ];
54 services.xserver.filesSection = ''
55 FontPath "${x11Fonts}/share/X11/fonts"
61 (lib.mkRenamedOptionModule [ "fonts" "enableFontDir" ] [ "fonts" "fontDir" "enable" ])