From 23c783cfc583ce933bccc4f3746df6cefd84501c Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Wed, 7 Aug 2024 23:09:31 -0400 Subject: [PATCH] theme: add font options (#76) * swaylock: update to standard font name * theme: setup font options and mgirate theme.nix * zed: migrate to font modules * swaylock: migrate to font modules * kitty: migrate to font modules * fuzzel: migrate to font modules * vsCodium: migrate to font modules * rofi: migrate to font modules * rofi: migrate to font modules * waybar: migrate to font modules * alacritty: migrate to font modules * alacritty: pull font size from theme module * nixfmt * rustboro: migrate font overrides * waybar: calculate font size from theme font settings * vsCodium: set font size from module * zed: set font size from module * sway: migrate to font modules * wlogout: migrate to font modules * mako: migrate to font modules * sway: fix improper option reference --- homeManagerModules/apps/alacritty/default.nix | 14 ++++--- homeManagerModules/apps/fuzzel/default.nix | 22 ++++++----- homeManagerModules/apps/kitty/default.nix | 10 +++-- homeManagerModules/apps/rofi/default.nix | 2 +- homeManagerModules/apps/swaylock/default.nix | 24 ++++++------ homeManagerModules/apps/vsCodium/default.nix | 16 ++++---- homeManagerModules/apps/wlogout/default.nix | 18 +++++---- homeManagerModules/apps/zed/default.nix | 22 ++++++----- homeManagerModules/desktop/sway/settings.nix | 4 +- homeManagerModules/options.nix | 26 ++++++++++++- homeManagerModules/services/mako/default.nix | 14 ++++--- .../services/waybar/default.nix | 28 +++++++------- homeManagerModules/theme.nix | 37 +++++-------------- hosts/rustboro/home.nix | 10 +++-- 14 files changed, 138 insertions(+), 109 deletions(-) diff --git a/homeManagerModules/apps/alacritty/default.nix b/homeManagerModules/apps/alacritty/default.nix index d6cb9658..6c5475bb 100644 --- a/homeManagerModules/apps/alacritty/default.nix +++ b/homeManagerModules/apps/alacritty/default.nix @@ -2,8 +2,10 @@ config, lib, ... -}: { - config = lib.mkIf config.ar.home.apps.alacritty.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.alacritty.enable { programs.alacritty = { enable = true; settings = { @@ -11,8 +13,8 @@ draw_bold_text_with_bright_colors = true; primary = { - background = "${config.ar.home.theme.colors.background}"; - foreground = "${config.ar.home.theme.colors.text}"; + background = "${cfg.theme.colors.background}"; + foreground = "${cfg.theme.colors.text}"; }; transparent_background_colors = true; @@ -20,11 +22,11 @@ font = { normal = { - family = "UbuntuSans Nerd Font"; + family = cfg.theme.font.monospaceFont.name; style = "Regular"; }; - size = config.gtk.font.size + 1; + size = cfg.theme.font.monospaceFont.size + 1; }; selection.save_to_clipboard = true; diff --git a/homeManagerModules/apps/fuzzel/default.nix b/homeManagerModules/apps/fuzzel/default.nix index 32b9a2c5..92d3bb40 100644 --- a/homeManagerModules/apps/fuzzel/default.nix +++ b/homeManagerModules/apps/fuzzel/default.nix @@ -2,8 +2,10 @@ config, lib, ... -}: { - config = lib.mkIf config.ar.home.apps.fuzzel.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.fuzzel.enable { programs.fuzzel = { enable = true; settings = { @@ -13,21 +15,21 @@ }; main = { - font = "UbuntuSansMono Nerd Font:size=${toString config.gtk.font.size}"; + font = "${cfg.theme.monospaceFont.name}:size=${toString cfg.theme.monospaceFont.size}"; icon-theme = "${config.gtk.iconTheme.name}"; layer = "overlay"; lines = 3; - terminal = lib.getExe config.ar.home.defaultApps.terminal; + terminal = lib.getExe cfg.defaultApps.terminal; width = 36; }; colors = { - background = "${config.ar.home.theme.colors.background}CC"; - border = "${config.ar.home.theme.colors.primary}EE"; - selection = "${config.ar.home.theme.colors.background}FF"; - selection-match = "${config.ar.home.theme.colors.primary}FF"; - selection-text = "${config.ar.home.theme.colors.secondary}FF"; - text = "${config.ar.home.theme.colors.text}FF"; + background = "${cfg.theme.colors.background}CC"; + border = "${cfg.theme.colors.primary}EE"; + selection = "${cfg.theme.colors.background}FF"; + selection-match = "${cfg.theme.colors.primary}FF"; + selection-text = "${cfg.theme.colors.secondary}FF"; + text = "${cfg.theme.colors.text}FF"; }; }; }; diff --git a/homeManagerModules/apps/kitty/default.nix b/homeManagerModules/apps/kitty/default.nix index dc1c6f82..f1aad0c0 100644 --- a/homeManagerModules/apps/kitty/default.nix +++ b/homeManagerModules/apps/kitty/default.nix @@ -3,14 +3,16 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.apps.kitty.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.kitty.enable { programs.kitty = { enable = true; font = { - name = "UbuntuSansMono Nerd Font"; - size = config.gtk.font.size + 1; + name = cfg.theme.monospaceFont.name; + size = cfg.theme.monospaceFont.size + 1; }; settings = { diff --git a/homeManagerModules/apps/rofi/default.nix b/homeManagerModules/apps/rofi/default.nix index 5dbe6880..5a40cda9 100644 --- a/homeManagerModules/apps/rofi/default.nix +++ b/homeManagerModules/apps/rofi/default.nix @@ -15,7 +15,7 @@ in { programs.rofi = { enable = true; - font = "UbuntuSansMono Nerd Font ${toString config.gtk.font.size}"; + font = "${cfg.theme.monospaceFont.name} ${toString cfg.theme.monospaceFont.size}"; location = "center"; package = pkgs.rofi-wayland; diff --git a/homeManagerModules/apps/swaylock/default.nix b/homeManagerModules/apps/swaylock/default.nix index 987479f9..44a387c7 100644 --- a/homeManagerModules/apps/swaylock/default.nix +++ b/homeManagerModules/apps/swaylock/default.nix @@ -3,8 +3,10 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.apps.swaylock.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.swaylock.enable { home.packages = with pkgs; [swaylock]; programs.swaylock.enable = true; @@ -15,8 +17,8 @@ caps-lock-key-hl-color=e78284 color=303446 daemonize - font="UbuntuSansMonoNerdFont-Regular" - image=${config.ar.home.theme.wallpaper} + font="${cfg.theme.monospaceFont.name}" + image=${cfg.theme.wallpaper} indicator-caps-lock indicator-idle-visible indicator-radius=120 @@ -27,18 +29,18 @@ inside-ver-color=303446cc inside-wrong-color=303446cc key-hl-color=a6d189 - line-caps-lock-color=${config.ar.home.theme.colors.background}CC - line-clear-color=${config.ar.home.theme.colors.background}CC - line-color=${config.ar.home.theme.colors.background}CC - line-ver-color=${config.ar.home.theme.colors.background}CC - line-wrong-color=${config.ar.home.theme.colors.background}CC + line-caps-lock-color=${cfg.theme.colors.background}CC + line-clear-color=${cfg.theme.colors.background}CC + line-color=${cfg.theme.colors.background}CC + line-ver-color=${cfg.theme.colors.background}CC + line-wrong-color=${cfg.theme.colors.background}CC ring-caps-lock-color=e78284cc ring-clear-color=85c1dccc - ring-color=${config.ar.home.theme.colors.primary}CC + ring-color=${cfg.theme.colors.primary}CC ring-ver-color=a6d189cc ring-wrong-color=e78284cc scaling=fill - separator-color=${config.ar.home.theme.colors.background}CC + separator-color=${cfg.theme.colors.background}CC text-caps-lock-color=c6d0f5 text-clear-color=c6d0f5 text-ver-color=c6d0f5 diff --git a/homeManagerModules/apps/vsCodium/default.nix b/homeManagerModules/apps/vsCodium/default.nix index 97de0a51..ec923378 100644 --- a/homeManagerModules/apps/vsCodium/default.nix +++ b/homeManagerModules/apps/vsCodium/default.nix @@ -3,8 +3,10 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.apps.vsCodium.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.vsCodium.enable { programs.vscode = { enable = true; package = pkgs.vscodium; @@ -32,8 +34,8 @@ userSettings = { "diffEditor.ignoreTrimWhitespace" = false; - "editor.fontFamily" = "'UbuntuSansMono Nerd Font', 'monospace', monospace"; - "editor.fontSize" = lib.mkDefault 14; + "editor.fontFamily" = "'${cfg.theme.monospaceFont.name} ${toString cfg.theme.monospaceFont.size}', 'monospace', monospace"; + "editor.fontSize" = cfg.theme.monospaceFont.size + 3; "editor.formatOnPaste" = true; "editor.formatOnSave" = true; "editor.formatOnType" = true; @@ -75,14 +77,14 @@ "shellformat.flag" = "-i 4"; - "terminal.external.linuxExec" = lib.getExe config.ar.home.defaultApps.terminal; - "terminal.integrated.fontSize" = lib.mkDefault 14; + "terminal.external.linuxExec" = lib.getExe cfg.defaultApps.terminal; + "terminal.integrated.fontSize" = cfg.theme.monospaceFont.size + 3; "update.mode" = "none"; "window.menuBarVisibility" = "hidden"; "window.titleBarStyle" = lib.mkDefault "native"; "window.zoomPerWindow" = false; "workbench.colorTheme" = - if config.ar.home.theme.darkMode + if cfg.theme.darkMode then "Adwaita Dark" else "Adwaita Light"; "workbench.iconTheme" = "vs-seti"; diff --git a/homeManagerModules/apps/wlogout/default.nix b/homeManagerModules/apps/wlogout/default.nix index d8018b3e..eddd1d93 100644 --- a/homeManagerModules/apps/wlogout/default.nix +++ b/homeManagerModules/apps/wlogout/default.nix @@ -3,8 +3,10 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.apps.wlogout.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.wlogout.enable { programs.wlogout = { enable = true; @@ -33,7 +35,7 @@ * { background-image: none; box-shadow: none; - font-family: "${config.gtk.font.name}", sans-serif; + font-family: "${cfg.theme.sansFont.name}", sans-serif; transition: 20ms; } @@ -42,21 +44,21 @@ } button { - background-color: ${config.ar.home.theme.colors.background}; + background-color: ${cfg.theme.colors.background}; background-position: center; background-repeat: no-repeat; background-size: 25%; - border-color: ${config.ar.home.theme.colors.primary}; + border-color: ${cfg.theme.colors.primary}; border-radius: 10; border-style: solid; border-width: 2; - color: ${config.ar.home.theme.colors.text}; + color: ${cfg.theme.colors.text}; margin: 5px; - text-decoration-color: ${config.ar.home.theme.colors.text}; + text-decoration-color: ${cfg.theme.colors.text}; } button:active, button:hover { - background-color: ${config.ar.home.theme.colors.primary}; + background-color: ${cfg.theme.colors.primary}; outline-style: none; } diff --git a/homeManagerModules/apps/zed/default.nix b/homeManagerModules/apps/zed/default.nix index 5166a170..e419cc90 100644 --- a/homeManagerModules/apps/zed/default.nix +++ b/homeManagerModules/apps/zed/default.nix @@ -3,10 +3,12 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.apps.zed.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.apps.zed.enable { home.packages = [ - config.ar.home.apps.zed.package + cfg.apps.zed.package pkgs.nixd ]; @@ -22,7 +24,7 @@ }; } ]; - keymaps = defaults ++ config.ar.home.apps.zed.keymaps; + keymaps = defaults ++ cfg.apps.zed.keymaps; in lib.generators.toJSON {} keymaps; @@ -46,8 +48,8 @@ auto_update = false; autosave.after_delay.milliseconds = 1000; - buffer_font_family = "UbuntuSansMono Nerd Font"; - buffer_font_size = 14; + buffer_font_family = cfg.theme.monospaceFont.name; + buffer_font_size = cfg.theme.monospaceFont.size + 3; current_line_highlight = "line"; indent_guides = { @@ -87,7 +89,7 @@ metrics = false; }; - terminal.font_size = 14; + terminal.font_size = cfg.theme.monospaceFont.size + 3; theme = { dark = "Adwaita Pastel Dark"; @@ -95,13 +97,13 @@ mode = "system"; }; - ui_font_family = "UbuntuSans Nerd Font"; - ui_font_size = 16; + ui_font_family = cfg.theme.sansFont.name; + ui_font_size = cfg.theme.sansFont.size + 5; use_autoclose = false; vim_mode = false; }; - settings = defaults // config.ar.home.apps.zed.settings; + settings = defaults // cfg.apps.zed.settings; in lib.generators.toJSON {} settings; }; diff --git a/homeManagerModules/desktop/sway/settings.nix b/homeManagerModules/desktop/sway/settings.nix index 171c5788..90dba6f2 100644 --- a/homeManagerModules/desktop/sway/settings.nix +++ b/homeManagerModules/desktop/sway/settings.nix @@ -58,9 +58,9 @@ in { }; fonts = { - names = ["${config.gtk.font.name}"]; + names = [cfg.theme.sansFont.name]; style = "Bold"; - size = config.gtk.font.size + 0.0; + size = cfg.theme.sansFont.size + 0.0; }; gaps = { diff --git a/homeManagerModules/options.nix b/homeManagerModules/options.nix index ca1b1f9a..08dd4ede 100644 --- a/homeManagerModules/options.nix +++ b/homeManagerModules/options.nix @@ -197,7 +197,27 @@ in { waybar.enable = lib.mkEnableOption "Waybar wayland panel."; }; - theme = { + theme = let + mkFontOption = typ: nam: pkg: siz: { + name = lib.mkOption { + description = "Default ${typ} font name."; + default = nam; + type = lib.types.str; + }; + + package = lib.mkOption { + description = "Default ${typ} font package."; + default = pkg; + type = lib.types.package; + }; + + size = lib.mkOption { + description = "Default ${typ} font size."; + default = siz; + type = lib.types.int; + }; + }; + in { enable = lib.mkEnableOption "Gtk, Qt, and application colors."; darkMode = lib.mkOption { @@ -244,6 +264,10 @@ in { }; }; + sansFont = mkFontOption "sans serif" "UbuntuSans Nerd Font" (pkgs.nerdfonts.override {fonts = ["UbuntuSans"];}) 11; + serifFont = mkFontOption "serif" "Vegur" pkgs.vegur 11; + monospaceFont = mkFontOption "monospace" "UbuntuSansMono Nerd Font" (pkgs.nerdfonts.override {fonts = ["UbuntuSans"];}) 11; + gtk.hideTitleBar = lib.mkOption { description = "Whether to hide GTK3/4 titlebars (useful for some window managers)."; default = false; diff --git a/homeManagerModules/services/mako/default.nix b/homeManagerModules/services/mako/default.nix index e81dee82..4c264f4e 100644 --- a/homeManagerModules/services/mako/default.nix +++ b/homeManagerModules/services/mako/default.nix @@ -3,25 +3,27 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.services.mako.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.services.mako.enable { services.mako = { actions = true; anchor = "top-center"; - backgroundColor = "${config.ar.home.theme.colors.background}CC"; - borderColor = "${config.ar.home.theme.colors.primary}EE"; + backgroundColor = "${cfg.theme.colors.background}CC"; + borderColor = "${cfg.theme.colors.primary}EE"; borderRadius = 10; borderSize = 2; defaultTimeout = 10000; enable = true; - font = "${config.gtk.font.name} Regular ${toString config.gtk.font.size}"; + font = "${cfg.theme.sansFont.name} Regular ${toString cfg.theme.sansFont.size}"; height = 300; iconPath = "${pkgs.papirus-icon-theme}/share/icons/Papirus/"; icons = true; layer = "top"; margin = "20,0"; padding = "15"; - textColor = "${config.ar.home.theme.colors.text}"; + textColor = "${cfg.theme.colors.text}"; width = 400; extraConfig = '' diff --git a/homeManagerModules/services/waybar/default.nix b/homeManagerModules/services/waybar/default.nix index bc584820..27a32049 100644 --- a/homeManagerModules/services/waybar/default.nix +++ b/homeManagerModules/services/waybar/default.nix @@ -3,8 +3,10 @@ lib, pkgs, ... -}: { - config = lib.mkIf config.ar.home.services.waybar.enable { +}: let + cfg = config.ar.home; +in { + config = lib.mkIf cfg.services.waybar.enable { programs.waybar = { enable = true; @@ -15,11 +17,11 @@ output = ["*"]; position = "top"; modules-left = - lib.optionals (config.ar.home.desktop.hyprland.enable) + lib.optionals (cfg.desktop.hyprland.enable) ["hyprland/workspaces" "hyprland/submap"] - ++ lib.optionals (config.ar.home.desktop.sway.enable) + ++ lib.optionals (cfg.desktop.sway.enable) ["sway/workspaces" "sway/scratchpad" "sway/mode"] - ++ lib.optionals (config.ar.home.desktop.hyprland.tabletMode.enable) + ++ lib.optionals (cfg.desktop.hyprland.tabletMode.enable) ["custom/menu" "custom/hyprland-close"]; modules-center = ["clock"]; @@ -256,25 +258,25 @@ * { border: none; border-radius: 0px; - font-family: "UbuntuSansMono Nerd Font"; - font-size: 14px; + font-family: "${cfg.theme.monospaceFont.name}"; + font-size: ${toString (cfg.theme.monospaceFont.size + 3)}px; font-weight: 600; } window#waybar { background: rgba (35, 38, 52, 0.0); - color: ${config.ar.home.theme.colors.text}; + color: ${cfg.theme.colors.text}; } #workspaces button { padding: 0px 5px; margin: 0px 0px; - color: ${config.ar.home.theme.colors.text}; + color: ${cfg.theme.colors.text}; } #workspaces button.active, #workspaces button.focused { - color: ${config.ar.home.theme.colors.primary}; + color: ${cfg.theme.colors.primary}; } #clock, @@ -294,11 +296,11 @@ } #battery { - color: ${config.ar.home.theme.colors.text}; + color: ${cfg.theme.colors.text}; } #battery.charging { - color: ${config.ar.home.theme.colors.primary}; + color: ${cfg.theme.colors.primary}; } #battery.critical:not(.charging), @@ -328,7 +330,7 @@ #submap, #mode { - color: ${config.ar.home.theme.colors.text}; + color: ${cfg.theme.colors.text}; background: rgba(255, 123, 99, 0.8); } ''; diff --git a/homeManagerModules/theme.nix b/homeManagerModules/theme.nix index e3717c13..23421685 100644 --- a/homeManagerModules/theme.nix +++ b/homeManagerModules/theme.nix @@ -40,33 +40,16 @@ } ''; }; - - font = { - name = "UbuntuSans Nerd Font"; - package = pkgs.nerdfonts.override {fonts = ["UbuntuSans"];}; - size = 11; - }; - - monospaceFont = { - inherit (font) package size; - name = "UbuntuSansMono Nerd Font"; - }; - - serifFont = { - inherit (font) size; - name = "Vegur"; - package = pkgs.vegur; - }; in { config = lib.mkIf cfg.enable { home = { packages = [ - font.package - monospaceFont.package + cfg.monospaceFont.package + cfg.sansFont.package + cfg.serifFont.package pkgs.adwaita-qt pkgs.gnome.adwaita-icon-theme pkgs.liberation_ttf - serifFont.package ]; pointerCursor = { @@ -86,9 +69,9 @@ in { enable = true; defaultFonts = { - monospace = [monospaceFont.name]; - sansSerif = [font.name]; - serif = [serifFont.name]; + monospace = [cfg.monospaceFont.name]; + sansSerif = [cfg.sansFont.name]; + serif = [cfg.serifFont.name]; }; }; @@ -104,7 +87,7 @@ in { package = pkgs.adw-gtk3; }; - font = {inherit (font) name package size;}; + font = {inherit (cfg.sansFont) name package size;}; iconTheme = { name = @@ -145,11 +128,11 @@ in { then "prefer-dark" else "prefer-light"; - document-font-name = "${serifFont.name} ${toString serifFont.size}"; - monospace-font-name = "${monospaceFont.name} ${toString monospaceFont.size}"; + document-font-name = "${cfg.serifFont.name} ${toString cfg.serifFont.size}"; + monospace-font-name = "${cfg.monospaceFont.name} ${toString cfg.monospaceFont.size}"; }; - "org/gnome/desktop/wm/preferences".titlebar-font = "${font.name} ${toString font.size}"; + "org/gnome/desktop/wm/preferences".titlebar-font = "${cfg.sansFont.name} ${toString cfg.sansFont.size}"; }; }; } diff --git a/hosts/rustboro/home.nix b/hosts/rustboro/home.nix index 45dabebc..3dbec73e 100644 --- a/hosts/rustboro/home.nix +++ b/hosts/rustboro/home.nix @@ -1,8 +1,6 @@ -{lib, ...}: { +{ home-manager.sharedModules = [ { - gtk.font.size = lib.mkForce 14; - home.pointerCursor.size = lib.mkForce 24; wayland.windowManager.sway.config.output = {"LG Display 0x0569 Unknown".scale = "1.0";}; ar.home = { @@ -12,6 +10,12 @@ enable = true; preset = "LoudnessEqualizer"; }; + + theme = { + monospaceFont.size = 14; + sansFont.size = 14; + serifFont.size = 14; + }; }; } ];