2017-01-17 00:47:03 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.gtk;
|
|
|
|
cfg2 = config.gtk.gtk2;
|
|
|
|
cfg3 = config.gtk.gtk3;
|
2021-12-21 13:16:52 +01:00
|
|
|
cfg4 = config.gtk.gtk4;
|
2017-01-17 00:47:03 +01:00
|
|
|
|
2017-09-21 13:18:33 +02:00
|
|
|
toGtk3Ini = generators.toINI {
|
2017-01-17 00:47:03 +01:00
|
|
|
mkKeyValue = key: value:
|
2022-03-17 20:30:48 +01:00
|
|
|
let value' = if isBool value then boolToString value else toString value;
|
|
|
|
in "${escape [ "=" ] key}=${value'}";
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
formatGtk2Option = n: v:
|
|
|
|
let
|
2020-05-25 00:46:58 +02:00
|
|
|
v' = if isBool v then
|
2022-03-17 20:30:48 +01:00
|
|
|
boolToString value
|
2020-05-25 00:46:58 +02:00
|
|
|
else if isString v then
|
|
|
|
''"${v}"''
|
|
|
|
else
|
|
|
|
toString v;
|
2022-03-17 20:30:48 +01:00
|
|
|
in "${escape [ "=" ] n} = ${v'}";
|
2017-01-17 00:47:03 +01:00
|
|
|
|
2017-11-08 01:17:46 +01:00
|
|
|
themeType = types.submodule {
|
|
|
|
options = {
|
|
|
|
package = mkOption {
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
default = null;
|
2022-05-07 03:27:31 +02:00
|
|
|
example = literalExpression "pkgs.gnome.gnome-themes-extra";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-11-08 01:17:46 +01:00
|
|
|
Package providing the theme. This package will be installed
|
2023-07-01 01:30:13 +02:00
|
|
|
to your profile. If `null` then the theme
|
2017-11-08 01:17:46 +01:00
|
|
|
is assumed to already be available in your profile.
|
2023-12-16 15:01:19 +01:00
|
|
|
|
|
|
|
For the theme to apply to GTK 4, this option is mandatory.
|
2017-11-08 01:17:46 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "Adwaita";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The name of the theme within the package.";
|
2017-11-08 01:17:46 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-17 20:30:48 +01:00
|
|
|
iconThemeType = types.submodule {
|
|
|
|
options = {
|
|
|
|
package = mkOption {
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
default = null;
|
2022-05-07 03:27:31 +02:00
|
|
|
example = literalExpression "pkgs.gnome.adwaita-icon-theme";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-03-17 20:30:48 +01:00
|
|
|
Package providing the icon theme. This package will be installed
|
2023-07-01 01:30:13 +02:00
|
|
|
to your profile. If `null` then the theme
|
2022-03-17 20:30:48 +01:00
|
|
|
is assumed to already be available in your profile.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "Adwaita";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The name of the icon theme within the package.";
|
2022-03-17 20:30:48 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
cursorThemeType = types.submodule {
|
|
|
|
options = {
|
|
|
|
package = mkOption {
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
default = null;
|
|
|
|
example = literalExpression "pkgs.vanilla-dmz";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-03-17 20:30:48 +01:00
|
|
|
Package providing the cursor theme. This package will be installed
|
2023-07-01 01:30:13 +02:00
|
|
|
to your profile. If `null` then the theme
|
2022-03-17 20:30:48 +01:00
|
|
|
is assumed to already be available in your profile.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "Vanilla-DMZ";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The name of the cursor theme within the package.";
|
2022-03-17 20:30:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
size = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 16;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-03-17 20:30:48 +01:00
|
|
|
The size of the cursor.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-25 00:46:58 +02:00
|
|
|
in {
|
2017-09-26 23:40:31 +02:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2018-12-24 12:05:28 +01:00
|
|
|
imports = [
|
2020-05-25 00:46:58 +02:00
|
|
|
(mkRemovedOptionModule [ "gtk" "gtk3" "waylandSupport" ] ''
|
2018-12-24 12:05:28 +01:00
|
|
|
This options is not longer needed and can be removed.
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
2017-01-17 00:47:03 +01:00
|
|
|
options = {
|
|
|
|
gtk = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "GTK 2/3 configuration";
|
2017-01-17 00:47:03 +01:00
|
|
|
|
2017-11-08 01:17:46 +01:00
|
|
|
font = mkOption {
|
2020-02-23 11:11:12 +01:00
|
|
|
type = types.nullOr hm.types.fontType;
|
2017-01-17 00:47:03 +01:00
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-01-17 00:47:03 +01:00
|
|
|
The font to use in GTK+ 2/3 applications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-03-17 20:30:48 +01:00
|
|
|
cursorTheme = mkOption {
|
|
|
|
type = types.nullOr cursorThemeType;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The cursor theme to use.";
|
2022-03-17 20:30:48 +01:00
|
|
|
};
|
|
|
|
|
2017-11-08 01:17:46 +01:00
|
|
|
iconTheme = mkOption {
|
2022-03-17 20:30:48 +01:00
|
|
|
type = types.nullOr iconThemeType;
|
2017-01-17 00:47:03 +01:00
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The icon theme to use.";
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
|
|
|
|
2017-11-08 01:17:46 +01:00
|
|
|
theme = mkOption {
|
|
|
|
type = types.nullOr themeType;
|
2017-01-17 00:47:03 +01:00
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The GTK+2/3 theme to use.";
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
|
|
|
|
2018-12-24 12:07:26 +01:00
|
|
|
gtk2 = {
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "gtk-can-change-accels = 1";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-12-24 12:07:26 +01:00
|
|
|
Extra configuration lines to add verbatim to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`~/.gtkrc-2.0`.
|
2018-12-24 12:07:26 +01:00
|
|
|
'';
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
2021-04-30 08:56:01 +02:00
|
|
|
|
|
|
|
configLocation = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${config.home.homeDirectory}/.gtkrc-2.0";
|
|
|
|
defaultText =
|
2021-10-09 11:14:08 +02:00
|
|
|
literalExpression ''"''${config.home.homeDirectory}/.gtkrc-2.0"'';
|
2021-04-30 08:56:01 +02:00
|
|
|
example =
|
2021-10-09 11:14:08 +02:00
|
|
|
literalExpression ''"''${config.xdg.configHome}/gtk-2.0/gtkrc"'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-04-30 08:56:01 +02:00
|
|
|
The location to put the GTK configuration file.
|
|
|
|
'';
|
|
|
|
};
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
|
|
|
|
2018-12-24 12:07:26 +01:00
|
|
|
gtk3 = {
|
2020-04-04 22:27:16 +02:00
|
|
|
bookmarks = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "file:///home/jane/Documents" ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Bookmarks in the sidebar of the GTK file browser";
|
2020-04-04 22:27:16 +02:00
|
|
|
};
|
|
|
|
|
2018-12-24 12:07:26 +01:00
|
|
|
extraConfig = mkOption {
|
2022-03-17 20:30:48 +01:00
|
|
|
type = with types; attrsOf (oneOf [ bool int str ]);
|
2020-05-25 00:46:58 +02:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
gtk-cursor-blink = false;
|
|
|
|
gtk-recent-files-limit = 20;
|
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-12-24 12:07:26 +01:00
|
|
|
Extra configuration options to add to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/gtk-3.0/settings.ini`.
|
2018-12-24 12:07:26 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraCss = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-12-24 12:07:26 +01:00
|
|
|
Extra configuration lines to add verbatim to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/gtk-3.0/gtk.css`.
|
2018-12-24 12:07:26 +01:00
|
|
|
'';
|
|
|
|
};
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
2021-12-21 13:16:52 +01:00
|
|
|
|
|
|
|
gtk4 = {
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = with types; attrsOf (either bool (either int str));
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
gtk-cursor-blink = false;
|
|
|
|
gtk-recent-files-limit = 20;
|
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-12-21 13:16:52 +01:00
|
|
|
Extra configuration options to add to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/gtk-4.0/settings.ini`.
|
2021-12-21 13:16:52 +01:00
|
|
|
'';
|
|
|
|
};
|
2023-06-21 18:38:43 +02:00
|
|
|
|
|
|
|
extraCss = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-06-21 18:38:43 +02:00
|
|
|
Extra configuration lines to add verbatim to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/gtk-4.0/gtk.css`.
|
2023-06-21 18:38:43 +02:00
|
|
|
'';
|
|
|
|
};
|
2021-12-21 13:16:52 +01:00
|
|
|
};
|
2017-01-17 00:47:03 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-25 00:46:58 +02:00
|
|
|
config = mkIf cfg.enable (let
|
2022-03-17 20:30:48 +01:00
|
|
|
gtkIni = optionalAttrs (cfg.font != null) {
|
2021-04-07 16:18:09 +02:00
|
|
|
gtk-font-name = let
|
|
|
|
fontSize =
|
|
|
|
optionalString (cfg.font.size != null) " ${toString cfg.font.size}";
|
|
|
|
in "${cfg.font.name}" + fontSize;
|
|
|
|
} // optionalAttrs (cfg.theme != null) { gtk-theme-name = cfg.theme.name; }
|
2020-05-25 00:46:58 +02:00
|
|
|
// optionalAttrs (cfg.iconTheme != null) {
|
|
|
|
gtk-icon-theme-name = cfg.iconTheme.name;
|
2022-03-17 20:30:48 +01:00
|
|
|
} // 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;
|
2020-05-25 00:46:58 +02:00
|
|
|
};
|
|
|
|
|
2023-12-16 15:01:19 +01:00
|
|
|
gtk4Css =
|
|
|
|
lib.optionalString (cfg.theme != null && cfg.theme.package != null) ''
|
|
|
|
/**
|
|
|
|
* GTK 4 reads the theme configured by gtk-theme-name, but ignores it.
|
|
|
|
* It does however respect user CSS, so import the theme from here.
|
|
|
|
**/
|
|
|
|
@import url("file://${cfg.theme.package}/share/themes/${cfg.theme.name}/gtk-4.0/gtk.css");
|
|
|
|
'' + cfg4.extraCss;
|
|
|
|
|
2021-04-10 03:45:14 +02:00
|
|
|
dconfIni = optionalAttrs (cfg.font != null) {
|
|
|
|
font-name = let
|
|
|
|
fontSize =
|
|
|
|
optionalString (cfg.font.size != null) " ${toString cfg.font.size}";
|
|
|
|
in "${cfg.font.name}" + fontSize;
|
|
|
|
} // optionalAttrs (cfg.theme != null) { gtk-theme = cfg.theme.name; }
|
2020-05-25 00:46:58 +02:00
|
|
|
// optionalAttrs (cfg.iconTheme != null) {
|
|
|
|
icon-theme = cfg.iconTheme.name;
|
2022-03-17 20:30:48 +01:00
|
|
|
} // optionalAttrs (cfg.cursorTheme != null) {
|
|
|
|
cursor-theme = cfg.cursorTheme.name;
|
|
|
|
} // optionalAttrs
|
|
|
|
(cfg.cursorTheme != null && cfg.cursorTheme.size != null) {
|
|
|
|
cursor-size = cfg.cursorTheme.size;
|
2020-05-25 00:46:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
optionalPackage = opt:
|
|
|
|
optional (opt != null && opt.package != null) opt.package;
|
|
|
|
in {
|
2022-03-17 20:30:48 +01:00
|
|
|
home.packages = concatMap optionalPackage [
|
|
|
|
cfg.font
|
|
|
|
cfg.theme
|
|
|
|
cfg.iconTheme
|
|
|
|
cfg.cursorTheme
|
|
|
|
];
|
2020-05-25 00:46:58 +02:00
|
|
|
|
2021-04-30 08:56:01 +02:00
|
|
|
home.file.${cfg2.configLocation}.text =
|
2022-03-20 21:22:56 +01:00
|
|
|
concatMapStrings (l: l + "\n") (mapAttrsToList formatGtk2Option gtkIni)
|
|
|
|
+ cfg2.extraConfig + "\n";
|
2020-05-25 00:46:58 +02:00
|
|
|
|
2021-04-30 08:56:01 +02:00
|
|
|
home.sessionVariables.GTK2_RC_FILES = cfg2.configLocation;
|
|
|
|
|
2020-05-25 00:46:58 +02:00
|
|
|
xdg.configFile."gtk-3.0/settings.ini".text =
|
2022-03-17 20:30:48 +01:00
|
|
|
toGtk3Ini { Settings = gtkIni // cfg3.extraConfig; };
|
2020-05-25 00:46:58 +02:00
|
|
|
|
2022-03-17 20:30:48 +01:00
|
|
|
xdg.configFile."gtk-3.0/gtk.css" =
|
|
|
|
mkIf (cfg3.extraCss != "") { text = cfg3.extraCss; };
|
2020-05-25 00:46:58 +02:00
|
|
|
|
|
|
|
xdg.configFile."gtk-3.0/bookmarks" = mkIf (cfg3.bookmarks != [ ]) {
|
2022-03-20 21:22:56 +01:00
|
|
|
text = concatMapStrings (l: l + "\n") cfg3.bookmarks;
|
2020-05-25 00:46:58 +02:00
|
|
|
};
|
2020-04-04 22:27:16 +02:00
|
|
|
|
2021-12-21 13:16:52 +01:00
|
|
|
xdg.configFile."gtk-4.0/settings.ini".text =
|
2022-03-17 20:30:48 +01:00
|
|
|
toGtk3Ini { Settings = gtkIni // cfg4.extraConfig; };
|
2021-12-21 13:16:52 +01:00
|
|
|
|
2023-12-16 15:01:19 +01:00
|
|
|
xdg.configFile."gtk-4.0/gtk.css" = mkIf (gtk4Css != "") { text = gtk4Css; };
|
2023-06-21 18:38:43 +02:00
|
|
|
|
2020-05-25 00:46:58 +02:00
|
|
|
dconf.settings."org/gnome/desktop/interface" = dconfIni;
|
|
|
|
});
|
2017-01-17 00:47:03 +01:00
|
|
|
}
|