From 1df1305a8a313120219e70ed1f50618b1047963d Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Sun, 30 Nov 2014 13:36:49 -0600 Subject: Rewrite Fontconfig NixOS module Details: * The option `fonts.enableFontConfig` has (finally) been renamed `fonts.fontconfig.enable`. * Configurations are loaded in this order: first the Fontconfig-upstream configuration is loaded, then the NixOS-specific font directories are set, the system-wide default configuration is loaded, and finally the user configuration is loaded (if enabled). * The NixOS options `fonts.fontconfig.defaultFonts.monospace`, `fonts.fontconfig.defaultFonts.sansSerif` and `fonts.fontconfig.defaultFonts.serif` are added to allow setting the default system-wide font used for these generic faces. The defaults are the appropriate faces from the DejaVu collection because of their comprehensive Unicode coverage, clean rendering, and excellent legibility. * The NixOS option `fonts.fontconfig.antialias` can be used to disable antialiasing (it is enabled by default). * The options `fonts.fontconfig.subpixel.rgba` and `fonts.fontconfig.subpixel.lcdfilter` control the system-wide default settings for subpixel order and LCD filtering algorithm, respectively. * `fonts.fontconfig.hinting.enable` can be used to disable TrueType font hinting (it is enabled by default). `fonts.fontconfig.hinting.autohint` controls the FreeType autohinter. `fonts.fontconfig.hinting.style` controls the hint style; it is "full" by default. * User configurations can be disabled system-wide by setting `fonts.fontconfig.includeUserConf = false`. They are enabled by default so users can set Fontconfig options in the desktop environment of their choice. --- nixos/modules/config/fonts/fontconfig.nix | 327 +++++++++++++++++++++++++----- nixos/modules/config/no-x-libs.nix | 2 +- nixos/modules/rename.nix | 1 + 3 files changed, 280 insertions(+), 50 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/config/fonts/fontconfig.nix b/nixos/modules/config/fonts/fontconfig.nix index 4b6f9325fda0..ca8313e017b1 100644 --- a/nixos/modules/config/fonts/fontconfig.nix +++ b/nixos/modules/config/fonts/fontconfig.nix @@ -8,72 +8,301 @@ with lib; fonts = { - enableFontConfig = mkOption { # !!! should be enableFontconfig - 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. - ''; + 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.str; + default = "DejaVu Sans Mono"; + description = '' + System-wide default monospace font. The default is not set if the + option is set to "". + ''; + }; + + sansSerif = mkOption { + type = types.str; + default = "DejaVu Sans"; + description = '' + System-wide default sans serif font. The default is not set if the + option is set to "". + ''; + }; + + serif = mkOption { + type = types.str; + default = "DejaVu Serif"; + description = '' + System-wide default serif font. The default is not set if the + option is set to "". + ''; + }; + }; + + 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 { + type = types.string // { + check = flip elem ["rgb" "bgr" "vrgb" "vbgr" "none"]; + }; + default = "rgb"; + description = '' + Subpixel order, one of none, + rgb, bgr, + vrgb, or vbgr. + ''; + }; + + lcdfilter = mkOption { + type = types.str // { + check = flip elem ["none" "default" "light" "legacy"]; + }; + default = "default"; + 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") + ""; + in mkIf fontconfig.enable { - config = mkIf config.fonts.enableFontConfig { + # Fontconfig 2.10 backward compatibility - # 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; }; - # 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/98-nixos.conf".text = + '' + + + - environment.etc."fonts/conf.d/00-nixos.conf".text = - '' - - - + + + + ${fcBool fontconfig.hinting.enable} + + + ${fcBool fontconfig.hinting.autohint} + + + hint${fontconfig.hinting.style} + + + ${fcBool fontconfig.antialias} + + + ${fontconfig.subpixel.rgba} + + + lcd${fontconfig.subpixel.lcdfilter} + + - - - - hintslight - - + + ${optionalString (fontconfig.defaultFonts.sansSerif != "") '' + + sans-serif + + ${fontconfig.defaultFonts.sansSerif} + + + ''} + ${optionalString (fontconfig.defaultFonts.serif != "") '' + + serif + + ${fontconfig.defaultFonts.serif} + + + ''} + ${optionalString (fontconfig.defaultFonts.monospace != "") '' + + monospace + + ${fontconfig.defaultFonts.monospace} + + + ''} - - ''; + ${optionalString (fontconfig.dpi != 0) '' + + + ${fontconfig.dpi} + + + ''} - # 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}/etc/fonts/fonts.conf"; - environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/00-nixos.conf".text = - '' - - - + + ''; - - - - hintslight - - + # 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}/etc/fonts/fonts.conf"; - - ${concatStringsSep "\n" (map (font: "${font}") config.fonts.fonts)} + 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/98-nixos.conf".text = + '' + + + - environment.systemPackages = [ pkgs.fontconfig ]; + + + + ${fcBool fontconfig.hinting.enable} + + + ${fcBool fontconfig.hinting.autohint} + + + hint${fontconfig.hinting.style} + + + ${fcBool fontconfig.antialias} + + + ${fontconfig.subpixel.rgba} + + + lcd${fontconfig.subpixel.lcdfilter} + + - }; + + + sans-serif + + ${fontconfig.defaultFonts.sansSerif} + + + + serif + + ${fontconfig.defaultFonts.serif} + + + + monospace + + ${fontconfig.defaultFonts.monospace} + + + + ${optionalString (fontconfig.dpi != 0) '' + + + ${fontconfig.dpi} + + + ''} + + + ''; + + 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 ]; + + }; } diff --git a/nixos/modules/config/no-x-libs.nix b/nixos/modules/config/no-x-libs.nix index f91dbb4cc281..47393c9d3f5c 100644 --- a/nixos/modules/config/no-x-libs.nix +++ b/nixos/modules/config/no-x-libs.nix @@ -24,7 +24,7 @@ with lib; programs.ssh.setXAuthLocation = false; security.pam.services.su.forwardXAuth = lib.mkForce false; - fonts.enableFontConfig = false; + fonts.fontconfig.enable = false; nixpkgs.config.packageOverrides = pkgs: { dbus = pkgs.dbus.override { useX11 = false; }; }; diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index b29a3d0354c9..cb1b92e78d62 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -74,6 +74,7 @@ in zipModules ([] ++ obsolete [ "environment" "x11Packages" ] [ "environment" "systemPackages" ] ++ obsolete [ "environment" "enableBashCompletion" ] [ "programs" "bash" "enableCompletion" ] ++ obsolete [ "environment" "nix" ] [ "nix" "package" ] +++ obsolete [ "fonts" "enableFontConfig" ] [ "fonts" "fontconfig" "enable" ] ++ obsolete [ "fonts" "extraFonts" ] [ "fonts" "fonts" ] ++ obsolete [ "security" "extraSetuidPrograms" ] [ "security" "setuidPrograms" ] -- cgit 1.4.1