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.
This commit is contained in:
Anthony Rodriguez 2024-10-06 17:48:46 +02:00
parent 6e0076c7ef
commit e24ab1eb95
Signed by: nezia
GPG key ID: EE3BE97C040A86CE
11 changed files with 146 additions and 50 deletions

View file

@ -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";

View file

@ -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;
};
};
}

View file

@ -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"];

View file

@ -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.

View file

@ -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;

View file

@ -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;

View file

@ -1,5 +1,5 @@
{
flake.nixosModules = {
theme = import ./theme;
style = import ./style;
};
}

48
modules/style/default.nix Normal file
View file

@ -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;
};
};
};
}

66
modules/style/gtk.nix Normal file
View file

@ -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}`
'';
})
];
};
}

View file

@ -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";
};
};
}

View file

@ -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;
};
};
};