1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-05 01:19:46 +01:00
home-manager/modules/misc/gtk.nix

177 lines
4.5 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.gtk;
cfg2 = config.gtk.gtk2;
cfg3 = config.gtk.gtk3;
2017-09-21 13:18:33 +02:00
toGtk3Ini = generators.toINI {
mkKeyValue = key: value:
let
value' =
if isBool value then (if value then "true" else "false")
else toString value;
in
"${key}=${value'}";
};
formatGtk2Option = n: v:
let
v' =
if isBool v then (if v then "true" else "false")
else if isString v then "\"${v}\""
else toString v;
in
"${n} = ${v'}";
themeType = types.submodule {
options = {
package = mkOption {
type = types.nullOr types.package;
default = null;
example = literalExample "pkgs.gnome3.gnome_themes_standard";
description = ''
Package providing the theme. This package will be installed
to your profile. If <literal>null</literal> then the theme
is assumed to already be available in your profile.
'';
};
name = mkOption {
type = types.str;
example = "Adwaita";
description = "The name of the theme within the package.";
};
};
};
in
{
meta.maintainers = [ maintainers.rycee ];
imports = [
(mkRemovedOptionModule ["gtk" "gtk3" "waylandSupport"] ''
This options is not longer needed and can be removed.
'')
];
options = {
gtk = {
enable = mkEnableOption "GTK 2/3 configuration";
font = mkOption {
2020-02-23 11:11:12 +01:00
type = types.nullOr hm.types.fontType;
default = null;
description = ''
The font to use in GTK+ 2/3 applications.
'';
};
iconTheme = mkOption {
type = types.nullOr themeType;
default = null;
description = "The icon theme to use.";
};
theme = mkOption {
type = types.nullOr themeType;
default = null;
description = "The GTK+2/3 theme to use.";
};
gtk2 = {
extraConfig = mkOption {
type = types.lines;
default = "";
example = "gtk-can-change-accels = 1";
description = ''
Extra configuration lines to add verbatim to
<filename>~/.gtkrc-2.0</filename>.
'';
};
};
gtk3 = {
bookmarks = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "file:///home/jane/Documents" ];
description = "Bookmarks in the sidebar of the GTK file browser";
};
extraConfig = mkOption {
2019-03-31 12:57:08 +02:00
type = with types; attrsOf (either bool (either int str));
default = {};
example = { gtk-cursor-blink = false; gtk-recent-files-limit = 20; };
description = ''
Extra configuration options to add to
<filename>~/.config/gtk-3.0/settings.ini</filename>.
'';
};
extraCss = mkOption {
type = types.lines;
default = "";
description = ''
Extra configuration lines to add verbatim to
<filename>~/.config/gtk-3.0/gtk.css</filename>.
'';
};
};
};
};
2017-01-17 18:16:45 +01:00
config = mkIf cfg.enable (
let
ini =
2017-11-24 22:25:36 +01:00
optionalAttrs (cfg.font != null)
{ gtk-font-name = cfg.font.name; }
//
optionalAttrs (cfg.theme != null)
{ gtk-theme-name = cfg.theme.name; }
//
optionalAttrs (cfg.iconTheme != null)
{ gtk-icon-theme-name = cfg.iconTheme.name; };
2018-09-22 18:30:13 +02:00
dconfIni =
optionalAttrs (cfg.font != null)
{ font-name = cfg.font.name; }
//
optionalAttrs (cfg.theme != null)
{ gtk-theme = cfg.theme.name; }
//
optionalAttrs (cfg.iconTheme != null)
{ icon-theme = cfg.iconTheme.name; };
optionalPackage = opt:
optional (opt != null && opt.package != null) opt.package;
in
{
home.packages =
optionalPackage cfg.font
++ optionalPackage cfg.theme
++ optionalPackage cfg.iconTheme;
home.file.".gtkrc-2.0".text =
concatStringsSep "\n" (
mapAttrsToList formatGtk2Option ini
) + "\n" + cfg2.extraConfig;
xdg.configFile."gtk-3.0/settings.ini".text =
toGtk3Ini { Settings = ini // cfg3.extraConfig; };
xdg.configFile."gtk-3.0/gtk.css".text = cfg3.extraCss;
2018-09-22 18:30:13 +02:00
xdg.configFile."gtk-3.0/bookmarks" = mkIf (cfg3.bookmarks != []) {
text = concatStringsSep "\n" cfg3.bookmarks;
};
dconf.settings."org/gnome/desktop/interface" = dconfIni;
}
);
}