From 32971e91bf4618c9c09f5fb728dbe67757d8b08a Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Thu, 21 Nov 2024 15:51:01 +0100 Subject: [PATCH] treewide: theme module refactor I decided to refactor how the theme module works. The idea is, that I wanted originally a module that I could give a base16 scheme name to, and use that globally in my config. However, scheme only took the base16 scheme name without any checks, which was pretty bad. I ended up creating a new option, schemeName, that scheme is computed from. It then makes the whole configuration cleaner, and avoids long inputs interpolations with the scheme name. --- home/programs/fuzzel.nix | 2 +- home/programs/gtk.nix | 3 +-- home/programs/niri/default.nix | 4 +--- home/programs/swaylock.nix | 3 +-- home/programs/waybar/style.nix | 3 +-- home/terminal/emulators/foot.nix | 3 +-- modules/theme/default.nix | 24 +++++++++++++++++++----- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/home/programs/fuzzel.nix b/home/programs/fuzzel.nix index d386e6e..5951f4c 100644 --- a/home/programs/fuzzel.nix +++ b/home/programs/fuzzel.nix @@ -15,7 +15,7 @@ font = "monospace:size=14"; }; colors = let - inherit (inputs.basix.schemeData.base16.${osConfig.theme.scheme}) palette; + inherit (osConfig.theme.scheme) palette; in { background = "${palette.base00}ff"; text = "${palette.base05}ff"; diff --git a/home/programs/gtk.nix b/home/programs/gtk.nix index f094875..0db7861 100644 --- a/home/programs/gtk.nix +++ b/home/programs/gtk.nix @@ -1,12 +1,11 @@ { - inputs, pkgs, config, osConfig, lib, ... }: let - isDark = inputs.basix.schemeData.base16.${osConfig.theme.scheme}.variant == "dark"; + isDark = osConfig.theme.scheme.variant == "dark"; in { home.pointerCursor = { inherit (osConfig.theme.cursorTheme) name package size; diff --git a/home/programs/niri/default.nix b/home/programs/niri/default.nix index 6ebfdbb..6061c02 100644 --- a/home/programs/niri/default.nix +++ b/home/programs/niri/default.nix @@ -1,13 +1,11 @@ { - inputs, lib, pkgs, config, osConfig, ... }: let - inherit (inputs.basix.schemeData.base16.${osConfig.theme.scheme}) palette; - inherit (lib) getExe mkIf; + inherit (osConfig.theme.scheme) palette; in { imports = [./binds.nix]; diff --git a/home/programs/swaylock.nix b/home/programs/swaylock.nix index f86b745..f5fe17f 100644 --- a/home/programs/swaylock.nix +++ b/home/programs/swaylock.nix @@ -1,10 +1,9 @@ { - inputs, pkgs, osConfig, ... }: let - inherit (inputs.basix.schemeData.base16.${osConfig.theme.scheme}) palette; + inherit (osConfig.theme.scheme) palette; in { # requires `security.pam.services.swaylock = { };` at the system level or else # unlock will not work. diff --git a/home/programs/waybar/style.nix b/home/programs/waybar/style.nix index 2b7f276..0eb7964 100644 --- a/home/programs/waybar/style.nix +++ b/home/programs/waybar/style.nix @@ -1,10 +1,9 @@ { - inputs, lib, osConfig, ... }: let - inherit (inputs.basix.schemeData.base16.${osConfig.theme.scheme}) palette; + inherit (osConfig.theme.scheme) palette; inherit (builtins) concatStringsSep; inherit (lib) mapAttrsToList; diff --git a/home/terminal/emulators/foot.nix b/home/terminal/emulators/foot.nix index beb6e21..49c4bee 100644 --- a/home/terminal/emulators/foot.nix +++ b/home/terminal/emulators/foot.nix @@ -1,5 +1,4 @@ { - inputs, osConfig, config, lib, @@ -17,7 +16,7 @@ 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) inputs.basix.schemeData.base16.${osConfig.theme.scheme}.palette; + palette = mapAttrs (_: color: removePrefix "#" color) osConfig.theme.scheme.palette; in { background = palette.base00; foreground = palette.base05; diff --git a/modules/theme/default.nix b/modules/theme/default.nix index 56da004..f6d8f00 100644 --- a/modules/theme/default.nix +++ b/modules/theme/default.nix @@ -1,22 +1,33 @@ { + inputs, + config, lib, pkgs, ... }: let - inherit (lib) mkEnableOption mkOption; - inherit (lib.types) string path package; + inherit (lib) mkEnableOption mkOption mkIf attrNames; + inherit (lib.types) path package enum; + cfg = config.theme; in { imports = [./gtk.nix]; options.theme = { enable = mkEnableOption "theme"; - scheme = mkOption { + schemeName = mkOption { description = '' Name of the tinted-scheming color scheme to use. ''; - type = string; - example = lib.literalExpression "catppuccin-macchiato"; + type = enum (attrNames inputs.basix.schemeData.base16); + example = "catppuccin-macchiato"; default = "catppuccin-macchiato"; }; + + scheme = mkOption { + description = '' + Resolved scheme from the tinted-scheming library. + ''; + type = lib.types.attrs; + }; + wallpaper = mkOption { description = '' Location of the wallpaper that will be used throughout the system. @@ -51,4 +62,7 @@ in { }; }; }; + config.theme = mkIf cfg.enable { + scheme = inputs.basix.schemeData.base16.${config.theme.schemeName}; + }; }