From e24ab1eb9530c392fcf835a091c2e0feed4b9e02 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Sun, 6 Oct 2024 17:48:46 +0200 Subject: [PATCH] repo: move everything gtk into modules This is mostly so that applications like ReGreet, which are managed by NixOS instead of HM, can also use the same GTK settings. It reduces repeating code by a lot and allows changing themes way more easily now. --- home/programs/fuzzel.nix | 2 +- home/programs/gtk.nix | 21 +++------- home/programs/swaybg.nix | 2 +- home/programs/swaylock.nix | 2 +- home/terminal/emulators/foot.nix | 3 +- hosts/default.nix | 10 +++-- modules/default.nix | 2 +- modules/style/default.nix | 48 +++++++++++++++++++++++ modules/style/gtk.nix | 66 ++++++++++++++++++++++++++++++++ modules/theme/default.nix | 18 --------- system/services/regreet.nix | 22 ++++++++--- 11 files changed, 146 insertions(+), 50 deletions(-) create mode 100644 modules/style/default.nix create mode 100644 modules/style/gtk.nix delete mode 100644 modules/theme/default.nix diff --git a/home/programs/fuzzel.nix b/home/programs/fuzzel.nix index 812743f..0c02750 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.${nixosConfig.theme.scheme}) palette; + inherit (inputs.basix.schemeData.base16.${nixosConfig.style.scheme}) palette; in { background = "${palette.base00}ff"; text = "${palette.base05}ff"; diff --git a/home/programs/gtk.nix b/home/programs/gtk.nix index d525f5f..593d11d 100644 --- a/home/programs/gtk.nix +++ b/home/programs/gtk.nix @@ -1,12 +1,11 @@ { pkgs, config, + nixosConfig, ... }: { home.pointerCursor = { - package = pkgs.bibata-cursors; - name = "Bibata-Modern-Classic"; - size = 24; + inherit (nixosConfig.style.cursorTheme) name package size; gtk.enable = true; x11.enable = true; }; @@ -30,21 +29,11 @@ gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc"; iconTheme = { - name = "Papirus-Dark"; - package = pkgs.papirus-icon-theme; + inherit (nixosConfig.style.gtk.iconTheme) name package; }; - theme = let - accent = "lavender"; - variant = "frappe"; - size = "standard"; - in { - name = "catppuccin-${variant}-${accent}-${size}"; - package = pkgs.catppuccin-gtk.override { - # https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/data/themes/catppuccin-gtk/default.nix - accents = [accent]; - inherit variant size; - }; + theme = { + inherit (nixosConfig.style.gtk.theme) name package; }; }; } diff --git a/home/programs/swaybg.nix b/home/programs/swaybg.nix index 975e5d9..8ac4d07 100644 --- a/home/programs/swaybg.nix +++ b/home/programs/swaybg.nix @@ -11,7 +11,7 @@ PartOf = ["graphical-session.target"]; }; Service = { - ExecStart = builtins.trace nixosConfig.theme.wallpaper "${lib.getExe pkgs.swaybg} -i ${nixosConfig.theme.wallpaper} -m fill"; + ExecStart = "${lib.getExe pkgs.swaybg} -i ${nixosConfig.style.wallpaper} -m fill"; Restart = "on-failure"; }; Install.WantedBy = ["graphical-session.target"]; diff --git a/home/programs/swaylock.nix b/home/programs/swaylock.nix index 6f5d082..665699e 100644 --- a/home/programs/swaylock.nix +++ b/home/programs/swaylock.nix @@ -4,7 +4,7 @@ nixosConfig, ... }: let - inherit (inputs.basix.schemeData.base16.${nixosConfig.theme.scheme}) palette; + inherit (inputs.basix.schemeData.base16.${nixosConfig.style.scheme}) palette; in { # requires `security.pam.services.swaylock = { };` at the system level or else # unlock will not work. diff --git a/home/terminal/emulators/foot.nix b/home/terminal/emulators/foot.nix index 6fb3795..3a2abe0 100644 --- a/home/terminal/emulators/foot.nix +++ b/home/terminal/emulators/foot.nix @@ -11,8 +11,7 @@ font = "monospace:size=14"; }; colors = let - inherit (nixosConfig.theme) scheme; - schemeData = inputs.basix.schemeData.base16.${scheme}; + schemeData = inputs.basix.schemeData.base16.${nixosConfig.style.scheme}; in { background = schemeData.palette.base00; foreground = schemeData.palette.base05; diff --git a/hosts/default.nix b/hosts/default.nix index f230165..023ac37 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -23,13 +23,15 @@ ../system/services/regreet.nix "${mod}/programs/niri" - self.nixosModules.theme + self.nixosModules.style { - theme.wallpaper = lib.mkDefault ../wallpapers/lucy-edgerunners-wallpaper.jpg; - theme.scheme = lib.mkDefault "catppuccin-frappe"; + style = { + gtk.enable = true; + wallpaper = lib.mkDefault ../wallpapers/lucy-edgerunners-wallpaper.jpg; + scheme = lib.mkDefault "catppuccin-frappe"; + }; } - { home-manager = { users.nezia.imports = homeImports.vamos; diff --git a/modules/default.nix b/modules/default.nix index 47af602..4d8324f 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,5 +1,5 @@ { flake.nixosModules = { - theme = import ./theme; + style = import ./style; }; } diff --git a/modules/style/default.nix b/modules/style/default.nix new file mode 100644 index 0000000..a97420e --- /dev/null +++ b/modules/style/default.nix @@ -0,0 +1,48 @@ +{ + lib, + pkgs, + ... +}: let + inherit (lib) mkOption; + inherit (lib.types) string path package; +in { + imports = [./gtk.nix]; + options.style = { + scheme = mkOption { + description = '' + Name of the tinted-scheming color scheme to use. + ''; + type = string; + example = lib.literalExpression "catppuccin-frappe"; + }; + wallpaper = mkOption { + description = '' + Location of the wallpaper that will be used throughout the system. + ''; + type = path; + example = lib.literalExpression "./wallpaper.png"; + }; + + cursorTheme = { + name = mkOption { + description = '' + Name of the cursor theme. + ''; + default = "Bibata-Modern-Classic"; + }; + package = mkOption { + type = package; + description = '' + Package providing the cursor theme. + ''; + default = pkgs.bibata-cursors; + }; + size = mkOption { + description = '' + Size of the cursor. + ''; + default = 24; + }; + }; + }; +} diff --git a/modules/style/gtk.nix b/modules/style/gtk.nix new file mode 100644 index 0000000..db02ff9 --- /dev/null +++ b/modules/style/gtk.nix @@ -0,0 +1,66 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (builtins) pathExists; + inherit (lib) mkOption mkEnableOption; + inherit (lib.types) package str; + + cfg = config.style.gtk; +in { + options.style.gtk = { + enable = mkEnableOption "enable GTK theming options"; + theme = { + name = mkOption { + type = str; + description = "Name for the GTK theme"; + default = "catppuccin-frappe-lavender-standard"; + }; + package = mkOption { + type = package; + description = "Package providing the GTK theme"; + + default = pkgs.catppuccin-gtk.override { + # https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/data/themes/catppuccin-gtk/default.nix + variant = "frappe"; + accents = ["lavender"]; + size = "standard"; + }; + }; + }; + iconTheme = { + name = mkOption { + type = str; + description = "The name for the icon theme that will be used for GTK programs"; + default = "Papirus-Dark"; + }; + + package = mkOption { + type = package; + description = "The GTK icon theme to be used"; + default = pkgs.catppuccin-papirus-folders.override { + accent = "lavender"; + flavor = "frappe"; + }; + }; + }; + }; + config = { + assertions = [ + (let + themePath = cfg.theme.package + /share/themes + "/${cfg.theme.name}"; + in { + assertion = cfg.enable -> pathExists themePath; + message = '' + ${toString themePath} set by the GTK module does not exist! + + To suppress this message, make sure that + `config.modules.style.gtk.theme.package` contains + the path `${cfg.theme.name}` + ''; + }) + ]; + }; +} diff --git a/modules/theme/default.nix b/modules/theme/default.nix deleted file mode 100644 index fbef65f..0000000 --- a/modules/theme/default.nix +++ /dev/null @@ -1,18 +0,0 @@ -{lib, ...}: { - options.theme = { - scheme = lib.mkOption { - description = '' - Name of the tinted-scheming color scheme to use. - ''; - type = lib.types.string; - example = lib.literalExpression "catppuccin-frappe"; - }; - wallpaper = lib.mkOption { - description = '' - Location of the wallpaper that will be used throughout the system. - ''; - type = lib.types.path; - example = lib.literalExpression "./wallpaper.png"; - }; - }; -} diff --git a/system/services/regreet.nix b/system/services/regreet.nix index ab992d0..252aa2b 100644 --- a/system/services/regreet.nix +++ b/system/services/regreet.nix @@ -1,19 +1,29 @@ { - inputs, + lib, + pkgs, config, ... -}: { +}: let + inherit (lib) mkForce; +in { + environment.systemPackages = [ + config.style.gtk.theme.package + config.style.gtk.iconTheme.package + config.style.cursorTheme.package + ]; + programs.regreet = { enable = true; + package = pkgs.greetd.regreet; cageArgs = [ "-s" "-d" ]; settings = { - GTK = let - schemeData = inputs.basix.schemeData.base16.${config.theme.scheme}; - in { - application_prefer_dark_theme = schemeData.variant == "dark"; + GTK = { + cursor_theme_name = mkForce config.style.cursorTheme.name; + icon_theme_name = mkForce config.style.gtk.iconTheme.name; + theme_name = mkForce config.style.gtk.theme.name; }; }; };