{ config, lib, pkgs, ... }: with lib; { options = { fonts = { fontconfig = { enable = mkOption { type = types.bool; default = true; description = '' If enabled, a Fontconfig configuration file will be built pointing to a set of default fonts. If you don't care about running X11 applications or any other program that uses Fontconfig, you can turn this option off and prevent a dependency on all those fonts. ''; }; antialias = mkOption { type = types.bool; default = true; description = "Enable font antialiasing."; }; dpi = mkOption { type = types.int; default = 0; description = '' Force DPI setting. Setting to 0 disables DPI forcing; the DPI detected for the display will be used. ''; }; defaultFonts = { monospace = mkOption { type = types.listOf types.str; default = ["DejaVu Sans Mono"]; description = '' System-wide default monospace font(s). Multiple fonts may be listed in case multiple languages must be supported. ''; }; sansSerif = mkOption { type = types.listOf types.str; default = ["DejaVu Sans"]; description = '' System-wide default sans serif font(s). Multiple fonts may be listed in case multiple languages must be supported. ''; }; serif = mkOption { type = types.listOf types.str; default = ["DejaVu Serif"]; description = '' System-wide default serif font(s). Multiple fonts may be listed in case multiple languages must be supported. ''; }; }; hinting = { enable = mkOption { type = types.bool; default = true; description = "Enable TrueType hinting."; }; autohint = mkOption { type = types.bool; default = true; description = '' Enable the autohinter, which provides hinting for otherwise un-hinted fonts. The results are usually lower quality than correctly-hinted fonts. ''; }; style = mkOption { type = types.str // { check = flip elem ["none" "slight" "medium" "full"]; }; default = "full"; description = '' TrueType hinting style, one of none, slight, medium, or full. ''; }; }; includeUserConf = mkOption { type = types.bool; default = true; description = '' Include the user configuration from ~/.config/fontconfig/fonts.conf or ~/.config/fontconfig/conf.d. ''; }; subpixel = { rgba = mkOption { default = "rgb"; type = types.enum ["rgb" "bgr" "vrgb" "vbgr" "none"]; description = '' Subpixel order, one of none, rgb, bgr, vrgb, or vbgr. ''; }; lcdfilter = mkOption { default = "default"; type = types.enum ["none" "default" "light" "legacy"]; description = '' FreeType LCD filter, one of none, default, light, or legacy. ''; }; }; }; }; }; config = let fontconfig = config.fonts.fontconfig; fcBool = x: "" + (if x then "true" else "false") + ""; renderConf = '' ${fcBool fontconfig.hinting.enable} ${fcBool fontconfig.hinting.autohint} hint${fontconfig.hinting.style} ${fcBool fontconfig.antialias} ${fontconfig.subpixel.rgba} lcd${fontconfig.subpixel.lcdfilter} ${optionalString (fontconfig.dpi != 0) '' ${toString fontconfig.dpi} ''} ''; genericAliasConf = '' ${optionalString (fontconfig.defaultFonts.sansSerif != []) '' sans-serif ${concatStringsSep "\n" (map (font: "${font}") fontconfig.defaultFonts.sansSerif)} ''} ${optionalString (fontconfig.defaultFonts.serif != []) '' serif ${concatStringsSep "\n" (map (font: "${font}") fontconfig.defaultFonts.serif)} ''} ${optionalString (fontconfig.defaultFonts.monospace != []) '' monospace ${concatStringsSep "\n" (map (font: "${font}") fontconfig.defaultFonts.monospace)} ''} ''; in mkIf fontconfig.enable { # Fontconfig 2.10 backward compatibility # Bring in the default (upstream) fontconfig configuration, only for fontconfig 2.10 environment.etc."fonts/fonts.conf".source = pkgs.makeFontsConf { fontconfig = pkgs.fontconfig_210; fontDirectories = config.fonts.fonts; }; environment.etc."fonts/conf.d/10-nixos-rendering.conf".text = renderConf; environment.etc."fonts/conf.d/60-nixos-generic-alias.conf".text = genericAliasConf; # Versioned fontconfig > 2.10. Take shared fonts.conf from fontconfig. # Otherwise specify only font directories. environment.etc."fonts/${pkgs.fontconfig.configVersion}/fonts.conf".source = "${pkgs.fontconfig.out}/etc/fonts/fonts.conf"; environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/00-nixos.conf".text = '' ${concatStringsSep "\n" (map (font: "${font}") config.fonts.fonts)} ''; environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/10-nixos-rendering.conf".text = renderConf; environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/60-nixos-generic-alias.conf".text = genericAliasConf; environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/99-user.conf" = { enable = fontconfig.includeUserConf; text = '' fontconfig/conf.d fontconfig/fonts.conf ''; }; environment.systemPackages = [ pkgs.fontconfig ]; }; }