{ config, pkgs, lib, ... }:
with lib;
let fcBool = x: if x then "true" else "false";
in
{
options = {
fonts = {
fontconfig = {
ultimate = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Enable fontconfig-ultimate settings (formerly known as
Infinality). Besides the customizable settings in this NixOS
module, fontconfig-ultimate also provides many font-specific
rendering tweaks.
'';
};
allowBitmaps = mkOption {
type = types.bool;
default = true;
description = ''
Allow bitmap fonts. Set to false to ban all
bitmap fonts.
'';
};
allowType1 = mkOption {
type = types.bool;
default = false;
description = ''
Allow Type-1 fonts. Default is false because of
poor rendering.
'';
};
useEmbeddedBitmaps = mkOption {
type = types.bool;
default = false;
description = ''Use embedded bitmaps in fonts like Calibri.'';
};
forceAutohint = mkOption {
type = types.bool;
default = false;
description = ''
Force use of the TrueType Autohinter. Useful for debugging or
free-software purists.
'';
};
renderMonoTTFAsBitmap = mkOption {
type = types.bool;
default = false;
description = ''Render some monospace TTF fonts as bitmaps.'';
};
substitutions = mkOption {
type = types.str // {
check = flip elem ["none" "free" "combi" "ms"];
};
default = "free";
description = ''
Font substitutions to replace common Type 1 fonts with nicer
TrueType fonts. free uses free fonts,
ms uses Microsoft fonts,
combi uses a combination, and
none disables the substitutions.
'';
};
rendering = mkOption {
type = types.attrs;
default = pkgs.fontconfig-ultimate.rendering.ultimate;
description = ''
FreeType rendering settings presets. The default is
pkgs.fontconfig-ultimate.rendering.ultimate.
The other available styles are:
ultimate-lighter,
ultimate-darker,
ultimate-lightest,
ultimate-darkest,
default (the original Infinality default),
osx,
ipad,
ubuntu,
linux,
winxplight,
win7light,
winxp,
win7,
vanilla,
classic,
nudge,
push,
shove,
sharpened,
infinality. Any of the presets may be
customized by editing the attributes. To disable, set this option
to the empty attribute set {}.
'';
};
};
};
};
};
config =
let ultimate = config.fonts.fontconfig.ultimate;
fontconfigUltimateConf = ''
${optionalString (!ultimate.allowBitmaps) ''
false
''}
${optionalString ultimate.allowType1 ''
Type 1
''}
${fcBool ultimate.useEmbeddedBitmaps}
${fcBool ultimate.forceAutohint}
${fcBool ultimate.renderMonoTTFAsBitmap}
${optionalString (ultimate.substitutions != "none") ''
${pkgs.fontconfig-ultimate.confd}/etc/fonts/presets/${ultimate.substitutions}
''}
${pkgs.fontconfig-ultimate.confd}/etc/fonts/conf.d
'';
in mkIf (config.fonts.fontconfig.enable && ultimate.enable) {
environment.etc."fonts/conf.d/52-fontconfig-ultimate.conf" = {
text = fontconfigUltimateConf;
};
environment.etc."fonts/${pkgs.fontconfig.configVersion}/conf.d/52-fontconfig-ultimate.conf" = {
text = fontconfigUltimateConf;
};
environment.variables = ultimate.rendering;
};
}