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

View file

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

View file

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