diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 406dea32b..82091d55e 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -76,25 +76,25 @@ The default combination of fonts is: ```nix { stylix.fonts = { - serif = { + serif = [{ package = pkgs.dejavu_fonts; name = "DejaVu Serif"; - }; + }]; - sansSerif = { + sansSerif = [{ package = pkgs.dejavu_fonts; name = "DejaVu Sans"; - }; + }]; - monospace = { + monospace = [{ package = pkgs.dejavu_fonts; name = "DejaVu Sans Mono"; - }; + }]; - emoji = { + emoji = [{ package = pkgs.noto-fonts-emoji; name = "Noto Color Emoji"; - }; + }]; }; } ``` diff --git a/modules/alacritty/hm.nix b/modules/alacritty/hm.nix index a9cd2780b..cd4e6ca87 100644 --- a/modules/alacritty/hm.nix +++ b/modules/alacritty/hm.nix @@ -1,8 +1,11 @@ {pkgs, config, lib, ... }: -with config.stylix.fonts; - let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + + monospace = builtins.head fonts.monospace; + themeFile = config.lib.stylix.colors { templateRepo = config.lib.stylix.templates.base16-alacritty; }; diff --git a/modules/avizo/hm.nix b/modules/avizo/hm.nix index 07ff31944..4ec9a1fc7 100644 --- a/modules/avizo/hm.nix +++ b/modules/avizo/hm.nix @@ -1,7 +1,6 @@ { config, lib, options, ... }: with config.lib.stylix.colors; -with config.stylix.fonts; let aviOpacity = toString config.stylix.opacity.popups; in diff --git a/modules/bemenu/hm.nix b/modules/bemenu/hm.nix index f69e74915..6f3c15fbd 100644 --- a/modules/bemenu/hm.nix +++ b/modules/bemenu/hm.nix @@ -1,8 +1,10 @@ -{pkgs, config, lib, ... }: +{ pkgs, config, lib, ... }: with config.lib.stylix.colors.withHashtag; -with config.stylix.fonts; let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + sansSerif = builtins.head fonts.sansSerif; bemenuOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); in { options.stylix.targets.bemenu = { @@ -42,7 +44,7 @@ in { "--scf '${base03}'" "--ab '${if alternate then base00 else base01}'" "--af '${if alternate then base04 else base05}'" - "--fn '${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}'" + "--fn '${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}'" ]; }; } diff --git a/modules/dunst/hm.nix b/modules/dunst/hm.nix index 3d8c8fa9b..341a69cc4 100644 --- a/modules/dunst/hm.nix +++ b/modules/dunst/hm.nix @@ -1,9 +1,11 @@ { config, lib, ... }: with config.lib.stylix.colors.withHashtag; -with config.stylix.fonts; let dunstOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); + inherit (config.stylix) fonts; + inherit (fonts) sizes; + sansSerif = builtins.head sansSerif; in { options.stylix.targets.dunst.enable = config.lib.stylix.mkEnableTarget "Dunst" true; diff --git a/modules/emacs/hm.nix b/modules/emacs/hm.nix index f97f18fc8..d3416f155 100644 --- a/modules/emacs/hm.nix +++ b/modules/emacs/hm.nix @@ -1,9 +1,10 @@ { pkgs, config, lib, ... }: with config.lib.stylix.colors.withHashtag; -with config.stylix.fonts; let + inherit (config.stylix) fonts; + monospace = builtins.head fonts.monospace; emacsOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.applications * 100)); in { diff --git a/modules/foot/hm.nix b/modules/foot/hm.nix index 8a4865f48..01defed20 100644 --- a/modules/foot/hm.nix +++ b/modules/foot/hm.nix @@ -14,8 +14,11 @@ in { config.programs.foot.settings = lib.mkIf cfg.enable { main = { include = theme; - font = - with config.stylix.fonts; + font = let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + monospace = builtins.head fonts.monospace; + in "${monospace.name}:size=${toString sizes.terminal}"; dpi-aware = "no"; }; diff --git a/modules/fuzzel/hm.nix b/modules/fuzzel/hm.nix index fce4d2d02..1a5b08ac9 100644 --- a/modules/fuzzel/hm.nix +++ b/modules/fuzzel/hm.nix @@ -21,8 +21,11 @@ in { border = "${base0D-hex}ff"; }; - main = { - font = "${config.stylix.fonts.sansSerif.name}:size=${toString config.stylix.fonts.sizes.popups}"; + main = let + inherit (config.stylix) fonts; + sansSerif = builtins.head fonts.sansSerif; + in { + font = "${sansSerif.name}:size=${toString fonts.sizes.popups}"; dpi-aware = "no"; }; }; diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index e66d6741d..7b3daa5be 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -15,7 +15,13 @@ with lib; picture-uri-dark = "file://${config.stylix.image}"; }; - "org/gnome/desktop/interface" = with config.stylix.fonts ; { + "org/gnome/desktop/interface" = let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + serif = builtins.head fonts.serif; + sansSerif = builtins.head fonts.sansSerif; + monospace = builtins.head fonts.monospace; + in { # We show the same colours regardless of this setting, and the quick # settings tile is removed. The value is still used by Epiphany to # request dark mode for websites which support it. diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix index 218253418..fd54a2ef8 100644 --- a/modules/grub/nixos.nix +++ b/modules/grub/nixos.nix @@ -1,10 +1,14 @@ { pkgs, config, lib, ... }: with config.lib.stylix; -with config.stylix.fonts; with config.lib.stylix.colors.withHashtag; let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + monospace = builtins.head fonts.monospace; + sansSerif = builtins.head fonts.sansSerif; + # Grub requires fonts to be converted to "PFF2 format" # This function takes a font { name, package } and produces a .pf2 file mkGrubFont = font: diff --git a/modules/gtk/hm.nix b/modules/gtk/hm.nix index 9657dbd26..12c81036e 100644 --- a/modules/gtk/hm.nix +++ b/modules/gtk/hm.nix @@ -37,10 +37,13 @@ in { # programs.dconf.enable = true; required in system config gtk = { enable = true; - font = { - inherit (config.stylix.fonts.sansSerif) package name; - size = config.stylix.fonts.sizes.applications; - }; + font = let + inherit (config.stylix) fonts; + sansSerif = builtins.head fonts.sansSerif; + in { + inherit (sansSerif) package name; + size = fonts.sizes.applications; + }; theme = { package = pkgs.adw-gtk3; name = "adw-gtk3"; diff --git a/modules/i3/hm.nix b/modules/i3/hm.nix index 96ccc1da4..fe3b1ba5c 100644 --- a/modules/i3/hm.nix +++ b/modules/i3/hm.nix @@ -9,9 +9,9 @@ let unfocused = base03; fonts = let - fonts = config.stylix.fonts; + inherit (config.stylix) fonts; in { - names = [ fonts.sansSerif.name ]; + names = fonts.sansSerif; size = fonts.sizes.desktop * 1.0; }; diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index 9f545709f..7bcd2d85c 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -1,9 +1,12 @@ { pkgs, config, lib, ... }: -with config.stylix.fonts; with config.lib.stylix.colors; let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + sansSerif = builtins.head fonts.sansSerif; + monospace = builtins.head fonts.monospace; colors = { BackgroundNormal = "${base00-rgb-r},${base00-rgb-g},${base00-rgb-b}"; BackgroundAlternate = "${base01-rgb-r},${base01-rgb-g},${base01-rgb-b}"; diff --git a/modules/kitty/hm.nix b/modules/kitty/hm.nix index 240caa289..fd2de1642 100644 --- a/modules/kitty/hm.nix +++ b/modules/kitty/hm.nix @@ -22,9 +22,12 @@ in { config = lib.mkIf cfg.enable { programs.kitty = { - font = { - inherit (config.stylix.fonts.monospace) package name; - size = config.stylix.fonts.sizes.terminal; + font = let + inherit (config.stylix) fonts; + monospace = builtins.head fonts.monospace; + in { + inherit (monospace) package name; + size = fonts.sizes.terminal; }; settings.background_opacity = with config.stylix.opacity; "${builtins.toString terminal}"; extraConfig = '' diff --git a/modules/mako/hm.nix b/modules/mako/hm.nix index f3847a21c..67a6b4d20 100644 --- a/modules/mako/hm.nix +++ b/modules/mako/hm.nix @@ -1,8 +1,10 @@ {pkgs, config, lib, options, ... }: with config.lib.stylix.colors.withHashtag; -with config.stylix.fonts; let + inherit (config.stylix) fonts; + inherit(fonts) sizes; + sansSerif = builtins.head fonts.sansSerif; makoOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); in { options.stylix.targets.mako.enable = diff --git a/modules/qutebrowser/hm.nix b/modules/qutebrowser/hm.nix index c7eb440ec..7fdc3f7ad 100644 --- a/modules/qutebrowser/hm.nix +++ b/modules/qutebrowser/hm.nix @@ -1,6 +1,5 @@ { config, lib, ... }: -with config.stylix.fonts; with config.lib.stylix.colors.withHashtag; let @@ -14,6 +13,11 @@ let warning = base0E; error = base08; + inherit (config.stylix) fonts; + inherit (fonts) sizes; + serif = builtins.head fonts.serif; + sansSerif = builtins.head fonts.sansSerif; + monospace = builtins.head fonts.monospace; in { options.stylix.targets.qutebrowser.enable = config.lib.stylix.mkEnableTarget "Qutebrowser" true; diff --git a/modules/rofi/hm.nix b/modules/rofi/hm.nix index a6d8141c2..0f41d8bcf 100644 --- a/modules/rofi/hm.nix +++ b/modules/rofi/hm.nix @@ -1,8 +1,10 @@ { pkgs, config, lib, ... }: -with config.stylix.fonts; - let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + monospace = builtins.head fonts.monospace; + rofiOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.popups * 100)); finalString = '' * { background: rgba ( {{base00-rgb-r}}, {{base00-rgb-g}}, {{base00-rgb-b}}, ${rofiOpacity} % ); diff --git a/modules/sway/hm.nix b/modules/sway/hm.nix index 10e5e8775..e7a9fdaec 100644 --- a/modules/sway/hm.nix +++ b/modules/sway/hm.nix @@ -8,9 +8,12 @@ let focused = base0A; unfocused = base03; - fonts = { - names = [ config.stylix.fonts.sansSerif.name ]; - size = config.stylix.fonts.sizes.desktop + 0.0; + fonts = let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + in { + names = fonts.sansSerif; + size = sizes.desktop + 0.0; }; in { diff --git a/modules/sxiv/hm.nix b/modules/sxiv/hm.nix index 44c8294ff..20a91e7c5 100644 --- a/modules/sxiv/hm.nix +++ b/modules/sxiv/hm.nix @@ -1,8 +1,9 @@ { config, lib, ... }: let - colors = config.lib.stylix.colors; - fonts = config.stylix.fonts; + inherit (config.lib.stylix) colors; + inherit (config.stylix) fonts; + sansSerif = builtins.head fonts.sansSerif; in { options.stylix.targets.sxiv.enable = config.lib.stylix.mkEnableTarget "Sxiv" true; @@ -12,7 +13,7 @@ in { properties = { "Sxiv.foreground" = "#${colors.base01}"; "Sxiv.background" = "#${colors.base04}"; - "Sxiv.font" = "${fonts.sansSerif.name}-${toString fonts.sizes.applications}"; + "Sxiv.font" = "${sansSerif.name}-${toString fonts.sizes.applications}"; }; }; }; diff --git a/modules/vim/hm.nix b/modules/vim/hm.nix index b67211d9a..636a83742 100644 --- a/modules/vim/hm.nix +++ b/modules/vim/hm.nix @@ -20,14 +20,16 @@ let }; vimOptions = let - fonts = config.stylix.fonts; + inherit (config.stylix) fonts; + inherit (fonts) sizes; + monospace = builtins.head fonts.monospace; in { plugins = [ themePlugin ]; extraConfig = '' set termguicolors colorscheme base16-stylix unlet g:colors_name - set guifont=${escape [" "] fonts.monospace.name}:h${toString fonts.sizes.terminal} + set guifont=${escape [" "] monospace.name}:h${toString sizes.terminal} ''; }; diff --git a/modules/vscode/hm.nix b/modules/vscode/hm.nix index e08ae1219..8aff31efb 100644 --- a/modules/vscode/hm.nix +++ b/modules/vscode/hm.nix @@ -1,8 +1,9 @@ {pkgs, config, lib, ... }: -with config.stylix.fonts; - let + inherit (config.stylix) fonts; + monospace = builtins.head fonts.monospace; + themeFile = config.lib.stylix.colors { template = ./template.mustache; extension = ".json"; diff --git a/modules/waybar/hm.nix b/modules/waybar/hm.nix index fc27bfed6..5e5ba8f42 100644 --- a/modules/waybar/hm.nix +++ b/modules/waybar/hm.nix @@ -1,7 +1,11 @@ { config, lib, ... }: with config.lib.stylix.colors.withHashtag; -with config.stylix.fonts; let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + + sansSerif = builtins.head fonts.sansSerif; + colorlessModules = place: '' .modules-${place} #workspaces button { border-bottom: 3px solid transparent; diff --git a/modules/wezterm/hm.nix b/modules/wezterm/hm.nix index 7410fba6c..bb7bd63fb 100644 --- a/modules/wezterm/hm.nix +++ b/modules/wezterm/hm.nix @@ -1,6 +1,12 @@ { config, lib, ... }: -let colors = config.lib.stylix.colors.withHashtag; +let + colors = config.lib.stylix.colors.withHashtag; + + inherit (config.stylix) fonts; + inherit (fonts) sizes; + + fontList = lib.strings.concatMapStringsSep ", " ({name,...}: "\"${name}\"") (fonts.monospace ++ fonts.emoji); in { options.stylix.targets.wezterm.enable = config.lib.stylix.mkEnableTarget "wezterm" config.programs.wezterm.enable; @@ -47,7 +53,6 @@ in { }; xdg.configFile."wezterm/wezterm.lua".text = with colors; - with config.stylix.fonts; lib.mkForce '' -- Generated by Stylix local wezterm = require("wezterm") @@ -62,10 +67,7 @@ in { -- See https://github.com/wez/wezterm/issues/2615 use_fancy_tab_bar = false, color_scheme = "stylix", - font = wezterm.font_with_fallback { - "${monospace.name}", - "${emoji.name}", - }, + font = wezterm.font_with_fallback { ${fontList} }, font_size = ${builtins.toString sizes.terminal}, window_background_opacity = ${ builtins.toString config.stylix.opacity.terminal diff --git a/modules/xfce/hm.nix b/modules/xfce/hm.nix index 37dbdbc43..4e332b229 100644 --- a/modules/xfce/hm.nix +++ b/modules/xfce/hm.nix @@ -6,7 +6,12 @@ config.lib.stylix.mkEnableTarget "Xfce" false; config = lib.mkIf config.stylix.targets.xfce.enable { - xfconf.settings = with config.stylix.fonts; { + xfconf.settings = let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + sansSerif = builtins.head fonts.sansSerif; + monospace = builtins.head fonts.monospace; + in { xfwm4 = { "general/title_font" = "${sansSerif.name} ${toString sizes.desktop}"; }; diff --git a/modules/xresources/hm.nix b/modules/xresources/hm.nix index c6c673fb3..90186cd1b 100644 --- a/modules/xresources/hm.nix +++ b/modules/xresources/hm.nix @@ -1,11 +1,15 @@ { config, lib, ... }: -{ +let + inherit (config.stylix) fonts; + inherit (fonts) sizes; + monospace = builtins.head fonts.monospace; +in { options.stylix.targets.xresources.enable = config.lib.stylix.mkEnableTarget "Xresources" true; config = lib.mkIf config.stylix.targets.xresources.enable { - xresources.properties = with config.lib.stylix.colors.withHashtag; with config.stylix.fonts; { + xresources.properties = with config.lib.stylix.colors.withHashtag; { "*.faceName" = monospace.name; "*.faceSize" = sizes.terminal; "*.renderFont" = true; diff --git a/stylix/darwin/fonts.nix b/stylix/darwin/fonts.nix index 6a1a65320..5036922bc 100644 --- a/stylix/darwin/fonts.nix +++ b/stylix/darwin/fonts.nix @@ -2,16 +2,15 @@ let cfg = config.stylix.fonts; + inherit (../helper.nix) fontPackages; in { imports = [ ../fonts.nix ]; config.fonts = { fontDir.enable = true; - fonts = [ - cfg.monospace.package - cfg.serif.package - cfg.sansSerif.package - cfg.emoji.package - ]; + fonts = (fontPackages cfg.monospace) + ++ (fontPackages cfg.serif.package) + ++ (fontPackages cfg.sansSerif.package) + ++ (fontPackages cfg.emoji.package); }; } diff --git a/stylix/fonts.nix b/stylix/fonts.nix index 90a21397a..6eca5bafd 100644 --- a/stylix/fonts.nix +++ b/stylix/fonts.nix @@ -25,38 +25,38 @@ in { options.stylix.fonts = { serif = mkOption { description = mdDoc "Serif font."; - type = fontType; - default = fromOs [ "fonts" "serif" ] { + type = types.nonEmptyListOf fontType; + default = fromOs [ "fonts" "serif" ] [{ package = pkgs.dejavu_fonts; name = "DejaVu Serif"; - }; + }]; }; sansSerif = mkOption { description = mdDoc "Sans-serif font."; - type = fontType; - default = fromOs [ "fonts" "sansSerif" ] { + type = types.nonEmptyListOf fontType; + default = fromOs [ "fonts" "sansSerif" ] [{ package = pkgs.dejavu_fonts; name = "DejaVu Sans"; - }; + }]; }; monospace = mkOption { description = mdDoc "Monospace font."; - type = fontType; - default = fromOs [ "fonts" "monospace" ] { + type = types.nonEmptyListOf fontType; + default = fromOs [ "fonts" "monospace" ] [{ package = pkgs.dejavu_fonts; name = "DejaVu Sans Mono"; - }; + }]; }; emoji = mkOption { description = mdDoc "Emoji font."; - type = fontType; - default = fromOs [ "fonts" "emoji" ] { + type = types.nonEmptyListOf fontType; + default = fromOs [ "fonts" "emoji" ] [{ package = pkgs.noto-fonts-emoji; name = "Noto Color Emoji"; - }; + }]; }; sizes = { diff --git a/stylix/helper.nix b/stylix/helper.nix new file mode 100644 index 000000000..7bc05f90d --- /dev/null +++ b/stylix/helper.nix @@ -0,0 +1,7 @@ +{ + # Turns a list of fonts into a list of font names + fontNames = builtins.map ({name, ...}: name); + + # Turns a list of fonts into a list of font packages + fontPackages = builtins.map ({package, ...}: package); +} diff --git a/stylix/hm/fonts.nix b/stylix/hm/fonts.nix index d6072cb90..f5caf4a67 100644 --- a/stylix/hm/fonts.nix +++ b/stylix/hm/fonts.nix @@ -2,15 +2,14 @@ let cfg = config.stylix.fonts; + inherit (../helper.nix) fontPackages; in { imports = [ ../fonts.nix ]; config = { fonts.fontconfig.enable = true; - home.packages = [ - cfg.monospace.package - cfg.serif.package - cfg.sansSerif.package - cfg.emoji.package - ]; + home.packages = (fontPackages cfg.monospace) + ++ (fontPackages cfg.serif.package) + ++ (fontPackages cfg.sansSerif.package) + ++ (fontPackages cfg.emoji.package); }; } diff --git a/stylix/nixos/fonts.nix b/stylix/nixos/fonts.nix index ee635458a..8078e7dee 100644 --- a/stylix/nixos/fonts.nix +++ b/stylix/nixos/fonts.nix @@ -2,21 +2,20 @@ let cfg = config.stylix.fonts; + inherit (../helper.nix) fontPackages fontNames; in { imports = [ ../fonts.nix ]; config.fonts = { - packages = [ - cfg.monospace.package - cfg.serif.package - cfg.sansSerif.package - cfg.emoji.package - ]; + packages = (fontPackages cfg.monospace) + ++ (fontPackages cfg.serif.package) + ++ (fontPackages cfg.sansSerif.package) + ++ (fontPackages cfg.emoji.package); fontconfig.defaultFonts = { - monospace = [ cfg.monospace.name ]; - serif = [ cfg.serif.name ]; - sansSerif = [ cfg.sansSerif.name ]; - emoji = [ cfg.emoji.name ]; + monospace = fontNames cfg.monospace; + serif = fontNames cfg.serif; + sansSerif = fontNames cfg.sansSerif; + emoji = fontNames cfg.emoji; }; }; }