feat(home-manager)!: add support for global cursors (#195)

* feat(home-manager)!: add support for global cursors

this replaces the previous gtk module options

* fix: document function types correctly in lib
This commit is contained in:
Weathercold 2024-06-24 23:13:58 -04:00 committed by GitHub
parent 2fb16f2d6f
commit 6e77fdd91d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 133 additions and 62 deletions

View file

@ -4,6 +4,7 @@
./bottom.nix ./bottom.nix
./btop.nix ./btop.nix
./cava.nix ./cava.nix
./cursor.nix
./delta.nix ./delta.nix
./dunst.nix ./dunst.nix
./fcitx5.nix ./fcitx5.nix

View file

@ -0,0 +1,28 @@
{
config,
pkgs,
lib,
...
}:
let
inherit (lib) ctp mkIf;
cfg = config.catppuccin.pointerCursor;
# "dark" and "light" can be used alongside the regular accents
cursorAccentType = ctp.mergeEnums ctp.types.accentOption (
lib.types.enum [
"dark"
"light"
]
);
in
{
options.catppuccin.pointerCursor = ctp.mkCatppuccinOpt "cursors" // {
accent = ctp.mkBasicOpt "accent" cursorAccentType "cursors";
};
config.home.pointerCursor = mkIf cfg.enable {
name = "catppuccin-${cfg.flavor}-${cfg.accent}-cursors";
package = pkgs.catppuccin-cursors.${cfg.flavor + ctp.mkUpper cfg.accent};
};
}

View file

@ -6,27 +6,24 @@
}: }:
let let
inherit (lib) inherit (lib)
concatStringsSep
ctp ctp
mkOption mkIf
mkEnableOption mkEnableOption
mkMerge
mkOption
mkRenamedOptionModule
types types
; ;
cfg = config.gtk.catppuccin; cfg = config.gtk.catppuccin;
enable = cfg.enable && config.gtk.enable; enable = cfg.enable && config.gtk.enable;
# "dark" and "light" can be used alongside the regular accents
cursorAccentType = ctp.mergeEnums ctp.types.accentOption (
lib.types.enum [
"dark"
"light"
]
);
in in
{ {
options.gtk.catppuccin = ctp.mkCatppuccinOpt "gtk" // { options.gtk.catppuccin = ctp.mkCatppuccinOpt "gtk" // {
# NOTE: we are overriding the previous declaration of `enable` here # NOTE: we are overriding the previous declaration of `enable` here
# as this module is deprecated and we do not want it to apply with # as this module is deprecated and we do not want it to apply with
# the global `catppuccin.enable` # the global `catppuccin.enable`
enable = lib.mkEnableOption "Catppuccin theme"; enable = mkEnableOption "Catppuccin theme";
accent = ctp.mkAccentOpt "gtk"; accent = ctp.mkAccentOpt "gtk";
size = mkOption { size = mkOption {
@ -48,31 +45,74 @@ in
default = [ "normal" ]; default = [ "normal" ];
description = "Catppuccin tweaks for gtk"; description = "Catppuccin tweaks for gtk";
}; };
gnomeShellTheme = mkEnableOption "Catppuccin gtk theme for GNOME Shell";
cursor = ctp.mkCatppuccinOpt "gtk cursors" // { gnomeShellTheme = mkEnableOption "Catppuccin gtk theme for GNOME Shell";
accent = ctp.mkBasicOpt "accent" cursorAccentType "gtk cursors";
};
icon = ctp.mkCatppuccinOpt "gtk modified Papirus icon theme" // { icon = ctp.mkCatppuccinOpt "gtk modified Papirus icon theme" // {
accent = ctp.mkAccentOpt "gtk modified Papirus icon theme"; accent = ctp.mkAccentOpt "gtk modified Papirus icon theme";
}; };
}; };
config = lib.mkIf enable { imports = [
(mkRenamedOptionModule
[
"gtk"
"catppuccin"
"cursor"
"enable"
]
[
"catppuccin"
"pointerCursor"
"enable"
]
)
(mkRenamedOptionModule
[
"gtk"
"catppuccin"
"cursor"
"flavor"
]
[
"catppuccin"
"pointerCursor"
"flavor"
]
)
(mkRenamedOptionModule
[
"gtk"
"catppuccin"
"cursor"
"accent"
]
[
"catppuccin"
"pointerCursor"
"accent"
]
)
];
config = mkMerge [
(mkIf (enable || cfg.gnomeShellTheme) {
warnings = [ warnings = [
'' ''
`gtk.catppuccin` is deprecated and will be removed in a future release. `gtk.catppuccin.enable` and `gtk.catppuccin.gnomeShellTheme` are deprecated and will be removed in a future release.
The upstream port has been archived and support will no longer be provided. The upstream port has been archived and support will no longer be provided.
Please see https://github.com/catppuccin/gtk/issues/262 Please see https://github.com/catppuccin/gtk/issues/262
'' ''
]; ];
})
gtk = { (mkIf enable {
theme = gtk.theme =
let let
gtkTweaks = lib.concatStringsSep "," cfg.tweaks; gtkTweaks = concatStringsSep "," cfg.tweaks;
in in
{ {
name = "catppuccin-${cfg.flavor}-${cfg.accent}-${cfg.size}+${gtkTweaks}"; name = "catppuccin-${cfg.flavor}-${cfg.accent}-${cfg.size}+${gtkTweaks}";
@ -83,26 +123,6 @@ in
}; };
}; };
cursorTheme =
let
accentUpper = ctp.mkUpper cfg.cursor.accent;
in
lib.mkIf cfg.cursor.enable {
name = "catppuccin-${cfg.cursor.flavor}-${cfg.cursor.accent}-cursors";
package = pkgs.catppuccin-cursors.${cfg.cursor.flavor + accentUpper};
};
iconTheme =
let
# use the light icon theme for latte
polarity = if cfg.icon.flavor == "latte" then "Light" else "Dark";
in
lib.mkIf cfg.icon.enable {
name = "Papirus-${polarity}";
package = pkgs.catppuccin-papirus-folders.override { inherit (cfg.icon) accent flavor; };
};
};
xdg.configFile = xdg.configFile =
let let
gtk4Dir = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0"; gtk4Dir = "${config.gtk.theme.package}/share/themes/${config.gtk.theme.name}/gtk-4.0";
@ -112,10 +132,31 @@ in
"gtk-4.0/gtk.css".source = "${gtk4Dir}/gtk.css"; "gtk-4.0/gtk.css".source = "${gtk4Dir}/gtk.css";
"gtk-4.0/gtk-dark.css".source = "${gtk4Dir}/gtk-dark.css"; "gtk-4.0/gtk-dark.css".source = "${gtk4Dir}/gtk-dark.css";
}; };
})
home.packages = lib.mkIf cfg.gnomeShellTheme [ pkgs.gnomeExtensions.user-themes ]; (mkIf cfg.icon.enable {
gtk.iconTheme =
let
# use the light icon theme for latte
polarity = if cfg.icon.flavor == "latte" then "Light" else "Dark";
in
{
name = "Papirus-${polarity}";
package = pkgs.catppuccin-papirus-folders.override { inherit (cfg.icon) accent flavor; };
};
})
dconf.settings = lib.mkIf cfg.gnomeShellTheme { (mkIf cfg.gnomeShellTheme {
assertions = [
{
assertion = enable;
message = "`gtk.enable` and `gtk.catppuccin.enable` must be `true` to use the GNOME shell theme";
}
];
home.packages = [ pkgs.gnomeExtensions.user-themes ];
dconf.settings = {
"org/gnome/shell" = { "org/gnome/shell" = {
disable-user-extensions = false; disable-user-extensions = false;
enabled-extensions = [ "user-theme@gnome-shell-extensions.gcampax.github.com" ]; enabled-extensions = [ "user-theme@gnome-shell-extensions.gcampax.github.com" ];
@ -127,5 +168,6 @@ in
color-scheme = if cfg.flavor == "latte" then "default" else "prefer-dark"; color-scheme = if cfg.flavor == "latte" then "default" else "prefer-dark";
}; };
}; };
}; })
];
} }

View file

@ -3,7 +3,7 @@ let
inherit (config.catppuccin) sources; inherit (config.catppuccin) sources;
cfg = config.wayland.windowManager.hyprland.catppuccin; cfg = config.wayland.windowManager.hyprland.catppuccin;
enable = cfg.enable && config.wayland.windowManager.hyprland.enable; enable = cfg.enable && config.wayland.windowManager.hyprland.enable;
inherit (config.gtk.catppuccin) cursor; inherit (config.catppuccin) pointerCursor;
in in
{ {
options.wayland.windowManager.hyprland.catppuccin = lib.ctp.mkCatppuccinOpt "hyprland" // { options.wayland.windowManager.hyprland.catppuccin = lib.ctp.mkCatppuccinOpt "hyprland" // {
@ -11,9 +11,9 @@ in
}; };
config = lib.mkIf enable { config = lib.mkIf enable {
home.sessionVariables = lib.mkIf cursor.enable { home.sessionVariables = lib.mkIf pointerCursor.enable {
HYPRCURSOR_SIZE = "24"; HYPRCURSOR_SIZE = "24";
HYPRCURSOR_THEME = "catppuccin-${cursor.flavor}-${cursor.accent}-cursors"; HYPRCURSOR_THEME = "catppuccin-${pointerCursor.flavor}-${pointerCursor.accent}-cursors";
}; };
wayland.windowManager.hyprland.settings = { wayland.windowManager.hyprland.settings = {
@ -25,7 +25,7 @@ in
$accentAlpha=''$${cfg.accent}Alpha $accentAlpha=''$${cfg.accent}Alpha
'') '')
] ]
++ lib.optionals cursor.enable [ ++ lib.optionals pointerCursor.enable [
(builtins.toFile "hyprland-cursors.conf" '' (builtins.toFile "hyprland-cursors.conf" ''
env = HYPRCURSOR_THEME,MyCursor env = HYPRCURSOR_THEME,MyCursor
env = HYPRCURSOR_SIZE,24 env = HYPRCURSOR_SIZE,24

View file

@ -9,7 +9,7 @@ let
inherit (lib) ctp; inherit (lib) ctp;
in in
{ {
# string -> type -> string -> a -> a # string -> type -> string -> a
# this is an internal function and shouldn't be # this is an internal function and shouldn't be
# used unless you know what you're doing. it takes # used unless you know what you're doing. it takes
# a string (the name of the property, i.e., flavor # a string (the name of the property, i.e., flavor
@ -23,7 +23,7 @@ in
description = "Catppuccin ${attr} for ${name}"; description = "Catppuccin ${attr} for ${name}";
}; };
# string -> a -> a # string -> a
# this creates a flavor option for modules # this creates a flavor option for modules
# the first string should be the name of the module, # the first string should be the name of the module,
# followed by the local config attrset # followed by the local config attrset
@ -105,7 +105,7 @@ in
in in
fromJSON (readFile json); fromJSON (readFile json);
# string -> a -> a # string -> a
# this creates a basic attrset only containing an # this creates a basic attrset only containing an
# enable and flavor option. the fist string should # enable and flavor option. the fist string should
# be the name of the module, followed by the local config # be the name of the module, followed by the local config
@ -117,7 +117,7 @@ in
flavor = ctp.mkFlavorOpt name; flavor = ctp.mkFlavorOpt name;
}; };
# string -> a -> a # string -> a
# this creates an accent option for modules # this creates an accent option for modules
# the first string should be the name of the module, # the first string should be the name of the module,
# followed by the local config attrset # followed by the local config attrset