diff --git a/nixos/modules/config/fonts/fontconfig.nix b/nixos/modules/config/fonts/fontconfig.nix index 62214cacc101..16b22841ac14 100644 --- a/nixos/modules/config/fonts/fontconfig.nix +++ b/nixos/modules/config/fonts/fontconfig.nix @@ -127,6 +127,38 @@ let ''; + # user defined font aliases + # priority 53 + aliases = + let + mkFontBlock = + key: fonts: + lib.optionalString ((builtins.length fonts) > 0) '' + <${key}> + ${lib.concatMapStrings (font: "${font}") fonts} + + ''; + + mkAliasBlock = family: opts: '' + + ${family} + ${mkFontBlock "prefer" opts.prefer} + ${mkFontBlock "accept" opts.accept} + ${mkFontBlock "default" opts.default} + + ''; + in + pkgs.writeText "fc-53-user-aliases.conf" '' + + + + + + ${lib.concatStrings (lib.mapAttrsToList mkAliasBlock cfg.aliases)} + + + ''; + # bitmap font options # priority 53 rejectBitmaps = pkgs.writeText "fc-53-no-bitmaps.conf" '' @@ -245,6 +277,9 @@ let # 53-no-bitmaps.conf ln -s ${rejectBitmaps} $dst/53-no-bitmaps.conf + # 53-user-aliases.conf + ln -s ${aliases} $dst/53-user-aliases.conf + ${lib.optionalString (!cfg.allowType1) '' # 53-nixos-reject-type1.conf ln -s ${rejectType1} $dst/53-nixos-reject-type1.conf @@ -522,6 +557,69 @@ in description = "Use embedded bitmaps in fonts like Calibri."; }; + aliases = lib.mkOption { + type = lib.types.attrsOf ( + lib.types.submodule { + options = { + binding = lib.mkOption { + type = lib.types.enum [ + "same" + "weak" + "strong" + ]; + default = "same"; + description = '' + Binding precedence for this font family. See + fontconfig "Font Matching" section for details. + ''; + }; + + prefer = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = '' + Fonts whose glyphs are chosen preferentially prior + to fonts which match the alias family. + ''; + }; + + accept = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = '' + Fonts that are chosen if none of the preferred + fonts, nor the alias family could provide the + desired glyph. + ''; + }; + + default = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = '' + Last chance fallback fonts which are chosen by + default if none of the other options could + provide the desired glyph. + ''; + }; + }; + } + ); + default = { }; + example = lib.literalExpression '' + { + # use FreeSans for Greek symbols missing in Helvetica + "Helvetica" = { + default = [ "FreeSans" ]; + }; + }; + ''; + description = '' + Font aliases that can substitute preferential fonts, + or specify custom fallback fonts. + ''; + }; + }; }; @@ -557,6 +655,9 @@ in # 52-nixos-default-fonts.conf r ${defaultFontsConf}, + # 53-user-aliases.conf + r ${aliases}, + # 53-no-bitmaps.conf r ${rejectBitmaps},