1

Modules: Add fonts module

This commit is contained in:
2025-07-08 20:14:26 +02:00
parent df41b0a572
commit b718825670
2 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,55 @@
{
config,
lib,
mylib,
pkgs,
...
}: let
inherit (config.modules) fonts;
in {
options.modules.fonts = import ./options.nix {inherit lib mylib;};
config = lib.mkIf fonts.enable {
fonts = {
# Some default fonts for unicode coverage
enableDefaultPackages = true;
# Puts fonts to /run/current-system/sw/share/X11/fonts
# https://wiki.nixos.org/wiki/Fonts#Flatpak_applications_can.27t_find_system_fonts
fontDir.enable = true;
# Font packages go here.
# They are installed system-wide so they land in fontdir,
# this is required for flatpak to find them.
packages = with pkgs; [
# Monospace fonts
nerd-fonts.jetbrains-mono
nerd-fonts.victor-mono
monolisa
# Sans/Serif fonts
noto-fonts
noto-fonts-emoji
noto-fonts-cjk-sans
lxgw-wenkai
];
fontconfig = {
enable = true;
antialias = true;
hinting.enable = true;
hinting.autohint = true;
cache32Bit = true;
# https://wiki.nixos.org/wiki/Fonts#Noto_Color_Emoji_doesn.27t_render_on_Firefox
useEmbeddedBitmaps = true;
defaultFonts = {
serif = [fonts.defaultSerifFont] ++ fonts.fallbackSerifFonts;
sansSerif = [fonts.defaultSansSerifFont] ++ fonts.fallbackSansSerifFonts;
monospace = [fonts.defaultMonoFont] ++ fonts.fallbackMonoFonts;
};
};
};
};
}

View File

@ -0,0 +1,69 @@
{
lib,
mylib,
...
}: {
enable = lib.mkEnableOption "Enable fonts configuration";
defaultSerifFont = lib.mkOption {
type = lib.types.str;
description = "Select default serif font";
example = ''
"Noto Serif CJK SC"
'';
default = "Noto Serif CJK SC";
};
defaultSansSerifFont = lib.mkOption {
type = lib.types.str;
description = "Select default sans-serif font";
example = ''
"Noto Sans CJK SC"
'';
default = "Noto Sans CJK SC";
};
defaultMonoFont = lib.mkOption {
type = lib.types.str;
description = "Select default monospace font";
example = ''
"MonoLisa Alt Script"
'';
default = "MonoLisa Alt Script";
};
fallbackSerifFonts = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "Select fallback serif fonts";
example = ''
[
"Noto Serif CJK SC"
]
'';
default = [];
};
fallbackSansSerifFonts = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "Select fallback sans-serif fonts";
example = ''
[
"Noto Sans CJK SC"
]
'';
default = [];
};
fallbackMonoFonts = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "Select fallback monospace fonts";
example = ''
[
"JetBrainsMono Nerd Font Mono"
]
'';
default = [
"JetBrainsMono Nerd Font Mono"
];
};
}