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.
This commit is contained in:
parent
d75485c945
commit
1df1305a8a
|
@ -8,72 +8,301 @@ with lib;
|
||||||
|
|
||||||
fonts = {
|
fonts = {
|
||||||
|
|
||||||
enableFontConfig = mkOption { # !!! should be enableFontconfig
|
fontconfig = {
|
||||||
type = types.bool;
|
enable = mkOption {
|
||||||
default = true;
|
type = types.bool;
|
||||||
description = ''
|
default = true;
|
||||||
If enabled, a Fontconfig configuration file will be built
|
description = ''
|
||||||
pointing to a set of default fonts. If you don't care about
|
If enabled, a Fontconfig configuration file will be built
|
||||||
running X11 applications or any other program that uses
|
pointing to a set of default fonts. If you don't care about
|
||||||
Fontconfig, you can turn this option off and prevent a
|
running X11 applications or any other program that uses
|
||||||
dependency on all those fonts.
|
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 <literal>0</literal> 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 <literal>""</literal>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
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 <literal>""</literal>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
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 <literal>""</literal>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
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 <literal>none</literal>,
|
||||||
|
<literal>slight</literal>, <literal>medium</literal>, or
|
||||||
|
<literal>full</literal>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
includeUserConf = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Include the user configuration from
|
||||||
|
<filename>~/.config/fontconfig/fonts.conf</filename> or
|
||||||
|
<filename>~/.config/fontconfig/conf.d</filename>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
subpixel = {
|
||||||
|
|
||||||
|
rgba = mkOption {
|
||||||
|
type = types.string // {
|
||||||
|
check = flip elem ["rgb" "bgr" "vrgb" "vbgr" "none"];
|
||||||
|
};
|
||||||
|
default = "rgb";
|
||||||
|
description = ''
|
||||||
|
Subpixel order, one of <literal>none</literal>,
|
||||||
|
<literal>rgb</literal>, <literal>bgr</literal>,
|
||||||
|
<literal>vrgb</literal>, or <literal>vbgr</literal>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
lcdfilter = mkOption {
|
||||||
|
type = types.str // {
|
||||||
|
check = flip elem ["none" "default" "light" "legacy"];
|
||||||
|
};
|
||||||
|
default = "default";
|
||||||
|
description = ''
|
||||||
|
FreeType LCD filter, one of <literal>none</literal>,
|
||||||
|
<literal>default</literal>, <literal>light</literal>, or
|
||||||
|
<literal>legacy</literal>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config =
|
||||||
|
let fontconfig = config.fonts.fontconfig;
|
||||||
|
fcBool = x: "<bool>" + (if x then "true" else "false") + "</bool>";
|
||||||
|
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/conf.d/98-nixos.conf".text =
|
||||||
environment.etc."fonts/fonts.conf".source =
|
''
|
||||||
pkgs.makeFontsConf { fontconfig = pkgs.fontconfig_210; fontDirectories = config.fonts.fonts; };
|
<?xml version='1.0'?>
|
||||||
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
||||||
|
<fontconfig>
|
||||||
|
|
||||||
environment.etc."fonts/conf.d/00-nixos.conf".text =
|
<!-- Default rendering settings -->
|
||||||
''
|
<match target="font">
|
||||||
<?xml version='1.0'?>
|
<edit mode="assign" name="hinting">
|
||||||
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
${fcBool fontconfig.hinting.enable}
|
||||||
<fontconfig>
|
</edit>
|
||||||
|
<edit mode="assign" name="autohint">
|
||||||
|
${fcBool fontconfig.hinting.autohint}
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="hintstyle">
|
||||||
|
<const>hint${fontconfig.hinting.style}</const>
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="antialias">
|
||||||
|
${fcBool fontconfig.antialias}
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="rgba">
|
||||||
|
<const>${fontconfig.subpixel.rgba}</const>
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="lcdfilter">
|
||||||
|
<const>lcd${fontconfig.subpixel.lcdfilter}</const>
|
||||||
|
</edit>
|
||||||
|
</match>
|
||||||
|
|
||||||
<!-- Set the default hinting style to "slight". -->
|
<!-- Default fonts -->
|
||||||
<match target="font">
|
${optionalString (fontconfig.defaultFonts.sansSerif != "") ''
|
||||||
<edit mode="assign" name="hintstyle">
|
<alias>
|
||||||
<const>hintslight</const>
|
<family>sans-serif</family>
|
||||||
</edit>
|
<prefer>
|
||||||
</match>
|
<family>${fontconfig.defaultFonts.sansSerif}</family>
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
''}
|
||||||
|
${optionalString (fontconfig.defaultFonts.serif != "") ''
|
||||||
|
<alias>
|
||||||
|
<family>serif</family>
|
||||||
|
<prefer>
|
||||||
|
<family>${fontconfig.defaultFonts.serif}</family>
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
''}
|
||||||
|
${optionalString (fontconfig.defaultFonts.monospace != "") ''
|
||||||
|
<alias>
|
||||||
|
<family>monospace</family>
|
||||||
|
<prefer>
|
||||||
|
<family>${fontconfig.defaultFonts.monospace}</family>
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
''}
|
||||||
|
|
||||||
</fontconfig>
|
${optionalString (fontconfig.dpi != 0) ''
|
||||||
'';
|
<match target="pattern">
|
||||||
|
<edit name="dpi" mode="assign">
|
||||||
|
<double>${fontconfig.dpi}</double>
|
||||||
|
</edit>
|
||||||
|
</match>
|
||||||
|
''}
|
||||||
|
|
||||||
# Versioned fontconfig > 2.10. Take shared fonts.conf from fontconfig.
|
</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 =
|
|
||||||
''
|
|
||||||
<?xml version='1.0'?>
|
|
||||||
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
||||||
<fontconfig>
|
|
||||||
|
|
||||||
<!-- Set the default hinting style to "slight". -->
|
# Versioned fontconfig > 2.10. Take shared fonts.conf from fontconfig.
|
||||||
<match target="font">
|
# Otherwise specify only font directories.
|
||||||
<edit mode="assign" name="hintstyle">
|
environment.etc."fonts/${pkgs.fontconfig.configVersion}/fonts.conf".source =
|
||||||
<const>hintslight</const>
|
"${pkgs.fontconfig}/etc/fonts/fonts.conf";
|
||||||
</edit>
|
|
||||||
</match>
|
|
||||||
|
|
||||||
<!-- Font directories -->
|
environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/00-nixos.conf".text =
|
||||||
${concatStringsSep "\n" (map (font: "<dir>${font}</dir>") config.fonts.fonts)}
|
''
|
||||||
|
<?xml version='1.0'?>
|
||||||
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
||||||
|
<fontconfig>
|
||||||
|
<!-- Font directories -->
|
||||||
|
${concatStringsSep "\n" (map (font: "<dir>${font}</dir>") config.fonts.fonts)}
|
||||||
|
</fontconfig>
|
||||||
|
'';
|
||||||
|
|
||||||
</fontconfig>
|
environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/98-nixos.conf".text =
|
||||||
'';
|
''
|
||||||
|
<?xml version='1.0'?>
|
||||||
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
||||||
|
<fontconfig>
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.fontconfig ];
|
<!-- Default rendering settings -->
|
||||||
|
<match target="font">
|
||||||
|
<edit mode="assign" name="hinting">
|
||||||
|
${fcBool fontconfig.hinting.enable}
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="autohint">
|
||||||
|
${fcBool fontconfig.hinting.autohint}
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="hintstyle">
|
||||||
|
<const>hint${fontconfig.hinting.style}</const>
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="antialias">
|
||||||
|
${fcBool fontconfig.antialias}
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="rgba">
|
||||||
|
<const>${fontconfig.subpixel.rgba}</const>
|
||||||
|
</edit>
|
||||||
|
<edit mode="assign" name="lcdfilter">
|
||||||
|
<const>lcd${fontconfig.subpixel.lcdfilter}</const>
|
||||||
|
</edit>
|
||||||
|
</match>
|
||||||
|
|
||||||
};
|
<!-- Default fonts -->
|
||||||
|
<alias>
|
||||||
|
<family>sans-serif</family>
|
||||||
|
<prefer>
|
||||||
|
<family>${fontconfig.defaultFonts.sansSerif}</family>
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
<alias>
|
||||||
|
<family>serif</family>
|
||||||
|
<prefer>
|
||||||
|
<family>${fontconfig.defaultFonts.serif}</family>
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
<alias>
|
||||||
|
<family>monospace</family>
|
||||||
|
<prefer>
|
||||||
|
<family>${fontconfig.defaultFonts.monospace}</family>
|
||||||
|
</prefer>
|
||||||
|
</alias>
|
||||||
|
|
||||||
|
${optionalString (fontconfig.dpi != 0) ''
|
||||||
|
<match target="pattern">
|
||||||
|
<edit name="dpi" mode="assign">
|
||||||
|
<double>${fontconfig.dpi}</double>
|
||||||
|
</edit>
|
||||||
|
</match>
|
||||||
|
''}
|
||||||
|
|
||||||
|
</fontconfig>
|
||||||
|
'';
|
||||||
|
|
||||||
|
environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/99-user.conf" = {
|
||||||
|
enable = fontconfig.includeUserConf;
|
||||||
|
text = ''
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
||||||
|
<fontconfig>
|
||||||
|
<include ignore_missing="yes" prefix="xdg">fontconfig/conf.d</include>
|
||||||
|
<include ignore_missing="yes" prefix="xdg">fontconfig/fonts.conf</include>
|
||||||
|
</fontconfig>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = [ pkgs.fontconfig ];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ with lib;
|
||||||
programs.ssh.setXAuthLocation = false;
|
programs.ssh.setXAuthLocation = false;
|
||||||
security.pam.services.su.forwardXAuth = lib.mkForce false;
|
security.pam.services.su.forwardXAuth = lib.mkForce false;
|
||||||
|
|
||||||
fonts.enableFontConfig = false;
|
fonts.fontconfig.enable = false;
|
||||||
|
|
||||||
nixpkgs.config.packageOverrides = pkgs:
|
nixpkgs.config.packageOverrides = pkgs:
|
||||||
{ dbus = pkgs.dbus.override { useX11 = false; }; };
|
{ dbus = pkgs.dbus.override { useX11 = false; }; };
|
||||||
|
|
|
@ -74,6 +74,7 @@ in zipModules ([]
|
||||||
++ obsolete [ "environment" "x11Packages" ] [ "environment" "systemPackages" ]
|
++ obsolete [ "environment" "x11Packages" ] [ "environment" "systemPackages" ]
|
||||||
++ obsolete [ "environment" "enableBashCompletion" ] [ "programs" "bash" "enableCompletion" ]
|
++ obsolete [ "environment" "enableBashCompletion" ] [ "programs" "bash" "enableCompletion" ]
|
||||||
++ obsolete [ "environment" "nix" ] [ "nix" "package" ]
|
++ obsolete [ "environment" "nix" ] [ "nix" "package" ]
|
||||||
|
++ obsolete [ "fonts" "enableFontConfig" ] [ "fonts" "fontconfig" "enable" ]
|
||||||
++ obsolete [ "fonts" "extraFonts" ] [ "fonts" "fonts" ]
|
++ obsolete [ "fonts" "extraFonts" ] [ "fonts" "fonts" ]
|
||||||
|
|
||||||
++ obsolete [ "security" "extraSetuidPrograms" ] [ "security" "setuidPrograms" ]
|
++ obsolete [ "security" "extraSetuidPrograms" ] [ "security" "setuidPrograms" ]
|
||||||
|
|
Loading…
Reference in New Issue