diff --git a/modules/misc/gtk.nix b/modules/misc/gtk.nix
index 69ff34b2..0cc9146d 100644
--- a/modules/misc/gtk.nix
+++ b/modules/misc/gtk.nix
@@ -11,23 +11,19 @@ let
toGtk3Ini = generators.toINI {
mkKeyValue = key: value:
- let
- value' = if isBool value then
- (if value then "true" else "false")
- else
- toString value;
- in "${key}=${value'}";
+ let value' = if isBool value then boolToString value else toString value;
+ in "${escape [ "=" ] key}=${value'}";
};
formatGtk2Option = n: v:
let
v' = if isBool v then
- (if v then "true" else "false")
+ boolToString value
else if isString v then
''"${v}"''
else
toString v;
- in "${n} = ${v'}";
+ in "${escape [ "=" ] n} = ${v'}";
themeType = types.submodule {
options = {
@@ -50,6 +46,57 @@ let
};
};
+ iconThemeType = types.submodule {
+ options = {
+ package = mkOption {
+ type = types.nullOr types.package;
+ default = null;
+ example = literalExpression "pkgs.adwaita-icon-theme";
+ description = ''
+ Package providing the icon theme. This package will be installed
+ to your profile. If null then the theme
+ is assumed to already be available in your profile.
+ '';
+ };
+
+ name = mkOption {
+ type = types.str;
+ example = "Adwaita";
+ description = "The name of the icon theme within the package.";
+ };
+ };
+ };
+
+ cursorThemeType = types.submodule {
+ options = {
+ package = mkOption {
+ type = types.nullOr types.package;
+ default = null;
+ example = literalExpression "pkgs.vanilla-dmz";
+ description = ''
+ Package providing the cursor theme. This package will be installed
+ to your profile. If null then the theme
+ is assumed to already be available in your profile.
+ '';
+ };
+
+ name = mkOption {
+ type = types.str;
+ example = "Vanilla-DMZ";
+ description = "The name of the cursor theme within the package.";
+ };
+
+ size = mkOption {
+ type = types.nullOr types.int;
+ default = null;
+ example = 16;
+ description = ''
+ The size of the cursor.
+ '';
+ };
+ };
+ };
+
in {
meta.maintainers = [ maintainers.rycee ];
@@ -71,8 +118,14 @@ in {
'';
};
+ cursorTheme = mkOption {
+ type = types.nullOr cursorThemeType;
+ default = null;
+ description = "The cursor theme to use.";
+ };
+
iconTheme = mkOption {
- type = types.nullOr themeType;
+ type = types.nullOr iconThemeType;
default = null;
description = "The icon theme to use.";
};
@@ -116,7 +169,7 @@ in {
};
extraConfig = mkOption {
- type = with types; attrsOf (either bool (either int str));
+ type = with types; attrsOf (oneOf [ bool int str ]);
default = { };
example = {
gtk-cursor-blink = false;
@@ -156,7 +209,7 @@ in {
};
config = mkIf cfg.enable (let
- ini = optionalAttrs (cfg.font != null) {
+ gtkIni = optionalAttrs (cfg.font != null) {
gtk-font-name = let
fontSize =
optionalString (cfg.font.size != null) " ${toString cfg.font.size}";
@@ -164,6 +217,11 @@ in {
} // optionalAttrs (cfg.theme != null) { gtk-theme-name = cfg.theme.name; }
// optionalAttrs (cfg.iconTheme != null) {
gtk-icon-theme-name = cfg.iconTheme.name;
+ } // optionalAttrs (cfg.cursorTheme != null) {
+ gtk-cursor-theme-name = cfg.cursorTheme.name;
+ } // optionalAttrs
+ (cfg.cursorTheme != null && cfg.cursorTheme.size != null) {
+ gtk-cursor-theme-size = cfg.cursorTheme.size;
};
dconfIni = optionalAttrs (cfg.font != null) {
@@ -174,31 +232,41 @@ in {
} // optionalAttrs (cfg.theme != null) { gtk-theme = cfg.theme.name; }
// optionalAttrs (cfg.iconTheme != null) {
icon-theme = cfg.iconTheme.name;
+ } // optionalAttrs (cfg.cursorTheme != null) {
+ cursor-theme = cfg.cursorTheme.name;
+ } // optionalAttrs
+ (cfg.cursorTheme != null && cfg.cursorTheme.size != null) {
+ cursor-size = cfg.cursorTheme.size;
};
optionalPackage = opt:
optional (opt != null && opt.package != null) opt.package;
in {
- home.packages = optionalPackage cfg.font ++ optionalPackage cfg.theme
- ++ optionalPackage cfg.iconTheme;
+ home.packages = concatMap optionalPackage [
+ cfg.font
+ cfg.theme
+ cfg.iconTheme
+ cfg.cursorTheme
+ ];
home.file.${cfg2.configLocation}.text =
- concatMapStrings (l: l + "\n") (mapAttrsToList formatGtk2Option ini)
+ concatStringsSep "\n" (mapAttrsToList formatGtk2Option gtkIni)
+ cfg2.extraConfig;
home.sessionVariables.GTK2_RC_FILES = cfg2.configLocation;
xdg.configFile."gtk-3.0/settings.ini".text =
- toGtk3Ini { Settings = ini // cfg3.extraConfig; };
+ toGtk3Ini { Settings = gtkIni // cfg3.extraConfig; };
- xdg.configFile."gtk-3.0/gtk.css".text = cfg3.extraCss;
+ xdg.configFile."gtk-3.0/gtk.css" =
+ mkIf (cfg3.extraCss != "") { text = cfg3.extraCss; };
xdg.configFile."gtk-3.0/bookmarks" = mkIf (cfg3.bookmarks != [ ]) {
- text = concatMapStrings (l: l + "\n") cfg3.bookmarks;
+ text = concatStringsSep "\n" cfg3.bookmarks;
};
xdg.configFile."gtk-4.0/settings.ini".text =
- toGtk3Ini { Settings = ini // cfg4.extraConfig; };
+ toGtk3Ini { Settings = gtkIni // cfg4.extraConfig; };
dconf.settings."org/gnome/desktop/interface" = dconfIni;
});
diff --git a/modules/xcursor.nix b/modules/xcursor.nix
index 3ec2a354..e2c5f0c2 100644
--- a/modules/xcursor.nix
+++ b/modules/xcursor.nix
@@ -60,6 +60,11 @@ in {
platforms.linux)
];
+ warnings = [''
+ GTK cursor settings will no longer be handled in the xsession.pointerCursor module in future.
+ Please use gtk.cursorTheme for GTK cursor settings instead.
+ ''];
+
home.packages = [ cfg.package ];
xsession.initExtra = ''
@@ -73,15 +78,8 @@ in {
"Xcursor.size" = cfg.size;
};
- gtk.gtk2.extraConfig = ''
- gtk-cursor-theme-name="${cfg.name}"
- gtk-cursor-theme-size=${toString cfg.size}
- '';
-
- gtk.gtk3.extraConfig = {
- "gtk-cursor-theme-name" = cfg.name;
- "gtk-cursor-theme-size" = cfg.size;
- };
+ # TODO: deprecate after next version release.
+ gtk.cursorTheme = { inherit (cfg) package name size; };
# Set name in icons theme, for compatibility with AwesomeWM etc. See:
# https://github.com/nix-community/home-manager/issues/2081
diff --git a/tests/modules/misc/gtk/default.nix b/tests/modules/misc/gtk/default.nix
index 0dbae61e..a812d4ad 100644
--- a/tests/modules/misc/gtk/default.nix
+++ b/tests/modules/misc/gtk/default.nix
@@ -1,5 +1,6 @@
{
gtk2-basic-config = ./gtk2-basic-config.nix;
gtk2-config-file-location = ./gtk2-config-file-location.nix;
+ gtk3-basic-settings = ./gtk3-basic-settings.nix;
}
diff --git a/tests/modules/misc/gtk/gtk-basic-config-expected.conf b/tests/modules/misc/gtk/gtk2-basic-config-expected.conf
similarity index 100%
rename from tests/modules/misc/gtk/gtk-basic-config-expected.conf
rename to tests/modules/misc/gtk/gtk2-basic-config-expected.conf
diff --git a/tests/modules/misc/gtk/gtk2-basic-config.nix b/tests/modules/misc/gtk/gtk2-basic-config.nix
index a49cc44e..228b5478 100644
--- a/tests/modules/misc/gtk/gtk2-basic-config.nix
+++ b/tests/modules/misc/gtk/gtk2-basic-config.nix
@@ -13,9 +13,10 @@ with lib;
nmt.script = ''
assertFileExists home-files/.gtkrc-2.0
- assertFileContent home-files/.gtkrc-2.0 ${
- ./gtk-basic-config-expected.conf
- }
+
+ assertFileContent home-files/.gtkrc-2.0 \
+ ${./gtk2-basic-config-expected.conf}
+
assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \
'GTK2_RC_FILES=.*/.gtkrc-2.0'
'';
diff --git a/tests/modules/misc/gtk/gtk3-basic-settings-expected.ini b/tests/modules/misc/gtk/gtk3-basic-settings-expected.ini
new file mode 100644
index 00000000..f1218b06
--- /dev/null
+++ b/tests/modules/misc/gtk/gtk3-basic-settings-expected.ini
@@ -0,0 +1,3 @@
+[Settings]
+gtk-cursor-blink=false
+gtk-recent-files-limit=20
diff --git a/tests/modules/misc/gtk/gtk3-basic-settings.nix b/tests/modules/misc/gtk/gtk3-basic-settings.nix
new file mode 100644
index 00000000..43835711
--- /dev/null
+++ b/tests/modules/misc/gtk/gtk3-basic-settings.nix
@@ -0,0 +1,24 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+{
+ config = {
+ gtk = {
+ enable = true;
+ gtk3.extraConfig = {
+ gtk-cursor-blink = false;
+ gtk-recent-files-limit = 20;
+ };
+ };
+
+ test.stubs.dconf = { };
+
+ nmt.script = ''
+ assertPathExists home-files/.config/gtk-3.0
+
+ assertFileContent home-files/.config/gtk-3.0/settings.ini \
+ ${./gtk3-basic-settings-expected.ini}
+ '';
+ };
+}