From 5fc158ff573e54bec90f90bbf1dbad6def6027a1 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Tue, 8 Jul 2025 20:14:26 +0200 Subject: [PATCH] Modules: Add fonts module --- system/modules/fonts/default.nix | 55 +++++++++++++++++++++++++ system/modules/fonts/options.nix | 69 ++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 system/modules/fonts/default.nix create mode 100644 system/modules/fonts/options.nix diff --git a/system/modules/fonts/default.nix b/system/modules/fonts/default.nix new file mode 100644 index 00000000..fcc74528 --- /dev/null +++ b/system/modules/fonts/default.nix @@ -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; + }; + }; + }; + }; +} diff --git a/system/modules/fonts/options.nix b/system/modules/fonts/options.nix new file mode 100644 index 00000000..e32db5bd --- /dev/null +++ b/system/modules/fonts/options.nix @@ -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" + ]; + }; +}