From 2ac966be4984552638bf136ec20d758bff63b152 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Tue, 26 Nov 2024 18:01:46 +0100 Subject: [PATCH] treewide: global refactor towards a better module structure Initially, I was using a weird combination of options in order to apply my theme dynamically. I was setting a read-only option from inside my modules, which was then used in every application that required it. What I ended up doing is refactoring everything in order to be inside of my theme module, and automatically configured when enabled, without doing any mkMerge/mkIf shenanigans in my other pieces of configuration. This is healthier, although it should be split up as the theme/default.nix got quite big. --- home/programs/fuzzel.nix | 11 -- home/programs/gtk.nix | 29 +--- home/programs/media/zathura.nix | 75 ++-------- home/programs/niri/default.nix | 152 +++++++++---------- home/programs/plasma/default.nix | 37 ----- home/programs/swaylock.nix | 66 ++------- home/programs/waybar/default.nix | 9 +- home/services/swaync/default.nix | 6 +- home/terminal/emulators/foot.nix | 28 ---- home/terminal/emulators/gnome-terminal.nix | 14 +- home/terminal/emulators/konsole.nix | 37 ----- modules/theme/default.nix | 161 +++++++++++++++++++-- 12 files changed, 252 insertions(+), 373 deletions(-) delete mode 100644 home/programs/plasma/default.nix delete mode 100644 home/terminal/emulators/konsole.nix diff --git a/home/programs/fuzzel.nix b/home/programs/fuzzel.nix index 5951f4c..3c88624 100644 --- a/home/programs/fuzzel.nix +++ b/home/programs/fuzzel.nix @@ -14,17 +14,6 @@ dpi-aware = "auto"; font = "monospace:size=14"; }; - colors = let - inherit (osConfig.theme.scheme) palette; - in { - background = "${palette.base00}ff"; - text = "${palette.base05}ff"; - input = "${palette.base05}ff"; - selection = "${palette.base02}ff"; - selection-text = "${palette.base07}ff"; - selection-match = "${palette.base0D}ff"; - border = "${palette.base0E}ff"; - }; border.width = 5; }; }; diff --git a/home/programs/gtk.nix b/home/programs/gtk.nix index 0db7861..eee5a90 100644 --- a/home/programs/gtk.nix +++ b/home/programs/gtk.nix @@ -1,18 +1,8 @@ { pkgs, config, - osConfig, - lib, ... -}: let - isDark = osConfig.theme.scheme.variant == "dark"; -in { - home.pointerCursor = { - inherit (osConfig.theme.cursorTheme) name package size; - gtk.enable = true; - x11.enable = true; - }; - +}: { gtk = { enable = true; @@ -24,7 +14,6 @@ in { gtk3.extraConfig = { gtk-decoration-layout = ":menu"; - gtk-application-prefer-dark-theme = isDark; }; gtk4.extraConfig = { @@ -32,21 +21,5 @@ in { }; gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc"; - - iconTheme = { - inherit (osConfig.theme.gtk.iconTheme) name package; - }; - - theme = lib.mkIf (!osConfig.services.xserver.desktopManager.gnome.enable) { - inherit (osConfig.theme.gtk.theme) name package; - }; - }; - dconf.settings = { - "org/gnome/desktop/interface" = { - color-scheme = - if isDark - then "prefer-dark" - else "default"; - }; }; } diff --git a/home/programs/media/zathura.nix b/home/programs/media/zathura.nix index e255516..82bdf35 100644 --- a/home/programs/media/zathura.nix +++ b/home/programs/media/zathura.nix @@ -1,68 +1,17 @@ -{ - osConfig, - lib, - lib', - ... -}: let - inherit (osConfig.theme.scheme) palette; - inherit (lib) mkIf mkMerge; - inherit (lib') rgba; -in { +_: { programs.zathura = { enable = true; - options = mkMerge [ - { - font = "Inter 12"; - selection-notification = true; + options = { + font = "Inter 12"; + selection-notification = true; - selection-clipboard = "clipboard"; - adjust-open = "best-fit"; - pages-per-row = "1"; - scroll-page-aware = "true"; - scroll-full-overlap = "0.01"; - scroll-step = "100"; - zoom-min = "10"; - } - (mkIf osConfig.theme.enable { - default-fg = palette.base05; - default-bg = palette.base00; - - completion-bg = palette.base02; - completion-fg = palette.base05; - completion-highlight-bg = palette.base03; - completion-highlight-fg = palette.base05; - completion-group-bg = palette.base02; - completion-group-fg = palette.base0D; - - statusbar-fg = palette.base05; - statusbar-bg = palette.base02; - - notification-bg = palette.base02; - notification-fg = palette.base05; - notification-error-bg = palette.base02; - notification-error-fg = palette.base08; - notification-warning-bg = palette.base02; - notification-warning-fg = palette.base0A; - - inputbar-fg = palette.base05; - inputbar-bg = palette.base02; - - recolor = true; - recolor-lightcolor = palette.base00; - recolor-darkcolor = palette.base05; - - index-fg = palette.base05; - index-bg = palette.base00; - index-active-fg = palette.base05; - index-active-bg = palette.base02; - - render-loading-bg = palette.base00; - render-loading-fg = palette.base05; - - highlight-color = rgba lib palette.base03 ".5"; - highlight-fg = rgba lib palette.base0E ".5"; - highlight-active-color = rgba lib palette.base0E ".5"; - }) - ]; + selection-clipboard = "clipboard"; + adjust-open = "best-fit"; + pages-per-row = "1"; + scroll-page-aware = "true"; + scroll-full-overlap = "0.01"; + scroll-step = "100"; + zoom-min = "10"; + }; }; } diff --git a/home/programs/niri/default.nix b/home/programs/niri/default.nix index ddb74c9..858a703 100644 --- a/home/programs/niri/default.nix +++ b/home/programs/niri/default.nix @@ -2,11 +2,8 @@ lib, pkgs, config, - osConfig, ... -}: let - inherit (lib) mkMerge mkIf; -in { +}: { imports = [./binds.nix]; xdg.portal = { @@ -22,85 +19,78 @@ in { }; }; - programs.niri = mkMerge [ - { - settings = { - input = { - power-key-handling.enable = false; - keyboard.xkb = { - layout = "us"; - options = "compose:ralt"; - }; - }; - - prefer-no-csd = true; - hotkey-overlay.skip-at-startup = true; - - layout = { - focus-ring = { - enable = true; - }; - always-center-single-column = true; - }; - - # https://github.com/sodiboo/system/blob/2978f4d79c51a5bd7e38a9cd75e3ec9046aa7e75/niri.mod.nix#L418-L434 - outputs = let - cfg = config.programs.niri.settings.outputs; - in { - "HDMI-A-1" = { - mode = { - width = 1920; - height = 1080; - refresh = 60.0; - }; - position.x = -cfg."HDMI-A-1".mode.width; - position.y = 0; - }; - "DP-1" = { - mode = { - width = 2560; - height = 1440; - refresh = 144.0; - }; - position.x = 0; - position.y = 0; - }; - }; - - window-rules = [ - { - draw-border-with-background = false; - geometry-corner-radius = let - r = 8.0; - in { - top-left = r; - top-right = r; - bottom-left = r; - bottom-right = r; - }; - clip-to-geometry = true; - } - { - matches = [ - {app-id = "foot";} - ]; - default-column-width = {proportion = 0.5;}; - } - ]; - - environment = { - "NIXOS_OZONE_WL" = "1"; - "DISPLAY" = ":0"; - "_JAVA_AWT_WM_NONREPARENTING" = "1"; # https://wiki.archlinux.org/title/Sway#Java_applications + programs.niri = { + settings = { + input = { + power-key-handling.enable = false; + keyboard.xkb = { + layout = "us"; + options = "compose:ralt"; }; }; - } - (mkIf osConfig.theme.enable (let - inherit (osConfig.theme.scheme) palette; - in { - settings.layout.focus-ring.active.color = palette.base0E; - })) - ]; + + prefer-no-csd = true; + hotkey-overlay.skip-at-startup = true; + + layout = { + focus-ring = { + enable = true; + }; + always-center-single-column = true; + }; + + # https://github.com/sodiboo/system/blob/2978f4d79c51a5bd7e38a9cd75e3ec9046aa7e75/niri.mod.nix#L418-L434 + outputs = let + cfg = config.programs.niri.settings.outputs; + in { + "HDMI-A-1" = { + mode = { + width = 1920; + height = 1080; + refresh = 60.0; + }; + position.x = -cfg."HDMI-A-1".mode.width; + position.y = 0; + }; + "DP-1" = { + mode = { + width = 2560; + height = 1440; + refresh = 144.0; + }; + position.x = 0; + position.y = 0; + }; + }; + + window-rules = [ + { + draw-border-with-background = false; + geometry-corner-radius = let + r = 8.0; + in { + top-left = r; + top-right = r; + bottom-left = r; + bottom-right = r; + }; + clip-to-geometry = true; + } + { + matches = [ + {app-id = "foot";} + ]; + default-column-width = {proportion = 0.5;}; + } + ]; + + environment = { + "NIXOS_OZONE_WL" = "1"; + "DISPLAY" = ":0"; + "_JAVA_AWT_WM_NONREPARENTING" = "1"; # https://wiki.archlinux.org/title/Sway#Java_applications + }; + }; + }; # copied from https://github.com/linyinfeng/dotfiles/blob/c00fe3b1562ad947672863a43e455bc2f01a56b6/home-manager/profiles/niri/default.nix#L594-L611 systemd.user.services.xwayland-satellite = { diff --git a/home/programs/plasma/default.nix b/home/programs/plasma/default.nix deleted file mode 100644 index 4da779b..0000000 --- a/home/programs/plasma/default.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ - inputs, - config, - pkgs, - ... -}: { - imports = [ - inputs.plasma-manager.homeManagerModules.plasma-manager - ]; - rograms.plasma = { - enable = true; - workspace = { - lookAndFeel = "org.kde.breezedark.desktop"; - inherit (config.theme) wallpaper; - }; - - input = { - touchpads = [ - { - enable = true; - naturalScroll = true; - vendorId = "093a"; - productId = "0274"; - name = "PIXA3854:00 093A:0274 Touchpad"; - } - ]; - keyboard = { - options = [ - "compose:ralt" - ]; - }; - }; - }; - home.packages = with pkgs; [ - qalculate-qt - ]; -} diff --git a/home/programs/swaylock.nix b/home/programs/swaylock.nix index e03aa34..d9c0d04 100644 --- a/home/programs/swaylock.nix +++ b/home/programs/swaylock.nix @@ -1,64 +1,24 @@ -{ - pkgs, - osConfig, - lib, - ... -}: let - inherit (lib) mkMerge mkIf; -in { +{pkgs, ...}: { # requires `security.pam.services.swaylock = { };` at the system level or else # unlock will not work. programs.swaylock = { enable = true; package = pkgs.swaylock-effects; - settings = mkMerge [ - { - clock = true; - timestr = "%H:%M"; + settings = { + clock = true; + timestr = "%H:%M"; - indicator = true; - indicator-radius = 111; - indicator-thickness = 9; + indicator = true; + indicator-radius = 111; + indicator-thickness = 9; - screenshots = true; - effect-blur = "7x5"; - effect-vignette = "0.75:0.75"; - effect-pixelate = 5; + screenshots = true; + effect-blur = "7x5"; + effect-vignette = "0.75:0.75"; + effect-pixelate = 5; - ignore-empty-password = false; # needed for PAM to work with fprintd / password - } - (mkIf - osConfig.theme.enable - (let - inherit (osConfig.theme.scheme) palette; - in { - inside-color = palette.base01; - inside-clear-color = palette.base0C; - inside-caps-lock-color = palette.base09; - inside-ver-color = palette.base0D; - inside-wrong-color = palette.base08; - key-hl-color = palette.base0B; - layout-bg-color = palette.base00; - layout-border-color = palette.base05; - layout-text-color = palette.base07; - line-color = palette.base00; - line-clear-color = palette.base0C; - line-caps-lock-color = palette.base09; - line-ver-color = palette.base0D; - line-wrong-color = palette.base08; - ring-color = palette.base02; - ring-clear-color = palette.base0C; - ring-caps-lock-color = palette.base09; - ring-ver-color = palette.base0D; - ring-wrong-color = palette.base08; - separator-color = palette.base02; - text-color = palette.base07; - text-clear-color = palette.base04; - text-caps-lock-color = palette.base04; - text-ver-color = palette.base04; - text-wrong-color = palette.base04; - })) - ]; + ignore-empty-password = false; # needed for PAM to work with fprintd / password + }; }; } diff --git a/home/programs/waybar/default.nix b/home/programs/waybar/default.nix index 4d446f2..4d01685 100644 --- a/home/programs/waybar/default.nix +++ b/home/programs/waybar/default.nix @@ -1,22 +1,17 @@ { pkgs, lib, - lib', osConfig, config, ... }: let - inherit (lib) getExe mkMerge mkIf optionalString; - inherit (lib') generateGtkColors; - inherit (osConfig.theme.scheme) palette; + inherit (lib) getExe mkMerge mkIf; inherit (builtins) readFile; in { programs.waybar = { enable = true; systemd.enable = true; - style = - optionalString osConfig.theme.enable generateGtkColors lib palette - + readFile ./style.css; + style = readFile ./style.css; settings = { mainBar = mkMerge [ { diff --git a/home/services/swaync/default.nix b/home/services/swaync/default.nix index aab28b4..5d94c2b 100644 --- a/home/services/swaync/default.nix +++ b/home/services/swaync/default.nix @@ -5,15 +5,11 @@ ... }: let inherit (lib) optionalString; - inherit (lib') generateGtkColors; - inherit (osConfig.theme.scheme) palette; inherit (builtins) readFile; in { services.swaync = { enable = true; - style = - optionalString osConfig.theme.enable generateGtkColors lib palette - + readFile ./style.css; + style = readFile ./style.css; settings = { positionX = "right"; positionY = "top"; diff --git a/home/terminal/emulators/foot.nix b/home/terminal/emulators/foot.nix index fcc6712..5172de2 100644 --- a/home/terminal/emulators/foot.nix +++ b/home/terminal/emulators/foot.nix @@ -4,7 +4,6 @@ lib, ... }: let - inherit (lib) mkIf; in { programs.foot = { enable = true; @@ -14,33 +13,6 @@ in { font = "monospace:size=14"; shell = "${lib.getExe config.programs.fish.package}"; }; - colors = mkIf osConfig.theme.enable (let - inherit (lib) mapAttrs; - inherit (lib.strings) removePrefix; - # because someone thought this was a great idea: https://github.com/tinted-theming/schemes/commit/61058a8d2e2bd4482b53d57a68feb56cdb991f0b - palette = mapAttrs (_: color: removePrefix "#" color) osConfig.theme.scheme.palette; - in { - background = palette.base00; - foreground = palette.base05; - - regular0 = palette.base01; - regular1 = palette.base08; - regular2 = palette.base0B; - regular3 = palette.base0A; - regular4 = palette.base0D; - regular5 = palette.base0E; - regular6 = palette.base0C; - regular7 = palette.base06; - - bright0 = palette.base02; - bright1 = palette.base08; - bright2 = palette.base0B; - bright3 = palette.base0A; - bright4 = palette.base0D; - bright5 = palette.base0E; - bright6 = palette.base0C; - bright7 = palette.base07; - }); }; }; } diff --git a/home/terminal/emulators/gnome-terminal.nix b/home/terminal/emulators/gnome-terminal.nix index dd8b3c4..42ba538 100644 --- a/home/terminal/emulators/gnome-terminal.nix +++ b/home/terminal/emulators/gnome-terminal.nix @@ -1,8 +1,4 @@ -{ - config, - inputs, - ... -}: { +_: { programs.gnome-terminal = { enable = true; showMenubar = true; @@ -14,14 +10,6 @@ boldIsBright = true; visibleName = "default"; font = "Intel One Mono 14"; - colors = let - inherit (inputs.basix.schemeData.base16.${config.theme.scheme}) palette; - in { - backgroundColor = "#${palette.base00}"; - foregroundColor = builtins.trace "#${palette.base05}" "#${palette.base05}"; - - palette = builtins.attrValues (builtins.mapAttrs (_: color: "#${color}") palette); - }; }; }; }; diff --git a/home/terminal/emulators/konsole.nix b/home/terminal/emulators/konsole.nix deleted file mode 100644 index cbe8d8e..0000000 --- a/home/terminal/emulators/konsole.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ - config, - inputs, - pkgs, - ... -}: { - programs.konsole = let - inherit (config.theme) scheme; - schemeData = inputs.basix.schemeData.base16.${scheme}; - in { - enable = true; - defaultProfile = "default"; - profiles = { - default = { - font = { - name = "monospace"; - size = 14; - }; - colorScheme = schemeData.name; - }; - }; - - extraConfig = { - "MainWindow" = { - "MenuBar" = "Disabled"; - "ToolBarsMovable" = "Disabled"; - }; - "KonsoleWindow" = { - "ShowMenuBarByDefault" = "false"; - }; - }; - - customColorSchemes = { - "${schemeData.name}" = pkgs.lib.mkKonsoleColorScheme schemeData; - }; - }; -} diff --git a/modules/theme/default.nix b/modules/theme/default.nix index e38a7a6..b9b0e6e 100644 --- a/modules/theme/default.nix +++ b/modules/theme/default.nix @@ -2,11 +2,13 @@ inputs, config, lib, + lib', pkgs, ... }: let inherit (lib) mkEnableOption mkOption mkIf attrNames; inherit (lib.types) path package enum; + inherit (lib') generateGtkColors; cfg = config.theme; in { imports = [./gtk.nix]; @@ -21,14 +23,6 @@ in { default = "catppuccin-macchiato"; }; - scheme = mkOption { - description = '' - Resolved scheme from the tinted-theming library. - ''; - readOnly = true; - type = lib.types.attrs; - }; - wallpaper = mkOption { description = '' Location of the wallpaper that will be used throughout the system. @@ -63,7 +57,154 @@ in { }; }; }; - config.theme = mkIf cfg.enable { + config = let scheme = inputs.basix.schemeData.base16.${config.theme.schemeName}; - }; + in + mkIf cfg.enable + { + home-manager.users.nezia = { + home.pointerCursor = { + inherit (config.theme.cursorTheme) name package size; + }; + + gtk = { + iconTheme = { + inherit (config.theme.gtk.iconTheme) name package; + }; + + theme = lib.mkIf (!config.services.xserver.desktopManager.gnome.enable) { + inherit (config.theme.gtk.theme) name package; + }; + + gtk3.extraConfig = { + gtk-application-prefer-dark-theme = scheme.variant == "dark"; + }; + }; + + services.swaync.style = + generateGtkColors lib scheme.palette; + + programs = { + niri = { + settings.layout.focus-ring.active.color = scheme.palette.base0E; + }; + + foot.settings.colors = let + inherit (lib.strings) removePrefix; + # because someone thought this was a great idea: https://github.com/tinted-theming/schemes/commit/61058a8d2e2bd4482b53d57a68feb56cdb991f0b + palette = builtins.mapAttrs (_: color: removePrefix "#" color) scheme.palette; + in { + background = palette.base00; + foreground = palette.base05; + + regular0 = palette.base01; + regular1 = palette.base08; + regular2 = palette.base0B; + regular3 = palette.base0A; + regular4 = palette.base0D; + regular5 = palette.base0E; + regular6 = palette.base0C; + regular7 = palette.base06; + + bright0 = palette.base02; + bright1 = palette.base08; + bright2 = palette.base0B; + bright3 = palette.base0A; + bright4 = palette.base0D; + bright5 = palette.base0E; + bright6 = palette.base0C; + bright7 = palette.base07; + }; + + waybar.style = + generateGtkColors lib scheme.palette; + fuzzel.settings.colors = { + background = "${scheme.palette.base00}ff"; + text = "${scheme.palette.base05}ff"; + input = "${scheme.palette.base05}ff"; + selection = "${scheme.palette.base02}ff"; + selection-text = "${scheme.palette.base07}ff"; + selection-match = "${scheme.palette.base0D}ff"; + border = "${scheme.palette.base0E}ff"; + }; + + swaylock.settings = { + inside-color = scheme.palette.base01; + inside-clear-color = scheme.palette.base0C; + inside-caps-lock-color = scheme.palette.base09; + inside-ver-color = scheme.palette.base0D; + inside-wrong-color = scheme.palette.base08; + key-hl-color = scheme.palette.base0B; + layout-bg-color = scheme.palette.base00; + layout-border-color = scheme.palette.base05; + layout-text-color = scheme.palette.base07; + line-color = scheme.palette.base00; + line-clear-color = scheme.palette.base0C; + line-caps-lock-color = scheme.palette.base09; + line-ver-color = scheme.palette.base0D; + line-wrong-color = scheme.palette.base08; + ring-color = scheme.palette.base02; + ring-clear-color = scheme.palette.base0C; + ring-caps-lock-color = scheme.palette.base09; + ring-ver-color = scheme.palette.base0D; + ring-wrong-color = scheme.palette.base08; + separator-color = scheme.palette.base02; + text-color = scheme.palette.base07; + text-clear-color = scheme.palette.base04; + text-caps-lock-color = scheme.palette.base04; + text-ver-color = scheme.palette.base04; + text-wrong-color = scheme.palette.base04; + }; + + zathura.options = { + default-fg = scheme.palette.base05; + default-bg = scheme.palette.base00; + + completion-bg = scheme.palette.base02; + completion-fg = scheme.palette.base05; + completion-highlight-bg = scheme.palette.base03; + completion-highlight-fg = scheme.palette.base05; + completion-group-bg = scheme.palette.base02; + completion-group-fg = scheme.palette.base0D; + + statusbar-fg = scheme.palette.base05; + statusbar-bg = scheme.palette.base02; + + notification-bg = scheme.palette.base02; + notification-fg = scheme.palette.base05; + notification-error-bg = scheme.palette.base02; + notification-error-fg = scheme.palette.base08; + notification-warning-bg = scheme.palette.base02; + notification-warning-fg = scheme.palette.base0A; + + inputbar-fg = scheme.palette.base05; + inputbar-bg = scheme.palette.base02; + + recolor = true; + recolor-lightcolor = scheme.palette.base00; + recolor-darkcolor = scheme.palette.base05; + + index-fg = scheme.palette.base05; + index-bg = scheme.palette.base00; + index-active-fg = scheme.palette.base05; + index-active-bg = scheme.palette.base02; + + render-loading-bg = scheme.palette.base00; + render-loading-fg = scheme.palette.base05; + + highlight-color = lib'.rgba lib scheme.palette.base03 ".5"; + highlight-fg = lib'.rgba lib scheme.palette.base0E ".5"; + highlight-active-color = lib'.rgba lib scheme.palette.base0E ".5"; + }; + + gnome-terminal.profile = { + "4621184a-b921-42cf-80a0-7784516606f2".colors = { + backgroundColor = "#${scheme.palette.base00}"; + foregroundColor = "#${scheme.palette.base05}" "#${scheme.palette.base05}"; + palette = builtins.attrValues (builtins.mapAttrs (_: color: "#${color}") scheme.palette); + }; + }; + }; + }; + }; }