fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
8.1 KiB285 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.gtk;
8  cfg2 = config.gtk.gtk2;
9  cfg3 = config.gtk.gtk3;
10  cfg4 = config.gtk.gtk4;
11
12  toGtk3Ini = generators.toINI {
13    mkKeyValue = key: value:
14      let value' = if isBool value then boolToString value else toString value;
15      in "${escape [ "=" ] key}=${value'}";
16  };
17
18  formatGtk2Option = n: v:
19    let
20      v' = if isBool v then
21        boolToString value
22      else if isString v then
23        ''"${v}"''
24      else
25        toString v;
26    in "${escape [ "=" ] n} = ${v'}";
27
28  themeType = types.submodule {
29    options = {
30      package = mkOption {
31        type = types.nullOr types.package;
32        default = null;
33        example = literalExpression "pkgs.gnome.gnome-themes-extra";
34        description = ''
35          Package providing the theme. This package will be installed
36          to your profile. If `null` then the theme
37          is assumed to already be available in your profile.
38        '';
39      };
40
41      name = mkOption {
42        type = types.str;
43        example = "Adwaita";
44        description = "The name of the theme within the package.";
45      };
46    };
47  };
48
49  iconThemeType = types.submodule {
50    options = {
51      package = mkOption {
52        type = types.nullOr types.package;
53        default = null;
54        example = literalExpression "pkgs.gnome.adwaita-icon-theme";
55        description = ''
56          Package providing the icon theme. This package will be installed
57          to your profile. If `null` then the theme
58          is assumed to already be available in your profile.
59        '';
60      };
61
62      name = mkOption {
63        type = types.str;
64        example = "Adwaita";
65        description = "The name of the icon theme within the package.";
66      };
67    };
68  };
69
70  cursorThemeType = types.submodule {
71    options = {
72      package = mkOption {
73        type = types.nullOr types.package;
74        default = null;
75        example = literalExpression "pkgs.vanilla-dmz";
76        description = ''
77          Package providing the cursor theme. This package will be installed
78          to your profile. If `null` then the theme
79          is assumed to already be available in your profile.
80        '';
81      };
82
83      name = mkOption {
84        type = types.str;
85        example = "Vanilla-DMZ";
86        description = "The name of the cursor theme within the package.";
87      };
88
89      size = mkOption {
90        type = types.nullOr types.int;
91        default = null;
92        example = 16;
93        description = ''
94          The size of the cursor.
95        '';
96      };
97    };
98  };
99
100in {
101  meta.maintainers = [ maintainers.rycee ];
102
103  imports = [
104    (mkRemovedOptionModule [ "gtk" "gtk3" "waylandSupport" ] ''
105      This options is not longer needed and can be removed.
106    '')
107  ];
108
109  options = {
110    gtk = {
111      enable = mkEnableOption "GTK 2/3 configuration";
112
113      font = mkOption {
114        type = types.nullOr hm.types.fontType;
115        default = null;
116        description = ''
117          The font to use in GTK+ 2/3 applications.
118        '';
119      };
120
121      cursorTheme = mkOption {
122        type = types.nullOr cursorThemeType;
123        default = null;
124        description = "The cursor theme to use.";
125      };
126
127      iconTheme = mkOption {
128        type = types.nullOr iconThemeType;
129        default = null;
130        description = "The icon theme to use.";
131      };
132
133      theme = mkOption {
134        type = types.nullOr themeType;
135        default = null;
136        description = "The GTK+2/3 theme to use.";
137      };
138
139      gtk2 = {
140        extraConfig = mkOption {
141          type = types.lines;
142          default = "";
143          example = "gtk-can-change-accels = 1";
144          description = ''
145            Extra configuration lines to add verbatim to
146            {file}`~/.gtkrc-2.0`.
147          '';
148        };
149
150        configLocation = mkOption {
151          type = types.path;
152          default = "${config.home.homeDirectory}/.gtkrc-2.0";
153          defaultText =
154            literalExpression ''"''${config.home.homeDirectory}/.gtkrc-2.0"'';
155          example =
156            literalExpression ''"''${config.xdg.configHome}/gtk-2.0/gtkrc"'';
157          description = ''
158            The location to put the GTK configuration file.
159          '';
160        };
161      };
162
163      gtk3 = {
164        bookmarks = mkOption {
165          type = types.listOf types.str;
166          default = [ ];
167          example = [ "file:///home/jane/Documents" ];
168          description = "Bookmarks in the sidebar of the GTK file browser";
169        };
170
171        extraConfig = mkOption {
172          type = with types; attrsOf (oneOf [ bool int str ]);
173          default = { };
174          example = {
175            gtk-cursor-blink = false;
176            gtk-recent-files-limit = 20;
177          };
178          description = ''
179            Extra configuration options to add to
180            {file}`$XDG_CONFIG_HOME/gtk-3.0/settings.ini`.
181          '';
182        };
183
184        extraCss = mkOption {
185          type = types.lines;
186          default = "";
187          description = ''
188            Extra configuration lines to add verbatim to
189            {file}`$XDG_CONFIG_HOME/gtk-3.0/gtk.css`.
190          '';
191        };
192      };
193
194      gtk4 = {
195        extraConfig = mkOption {
196          type = with types; attrsOf (either bool (either int str));
197          default = { };
198          example = {
199            gtk-cursor-blink = false;
200            gtk-recent-files-limit = 20;
201          };
202          description = ''
203            Extra configuration options to add to
204            {file}`$XDG_CONFIG_HOME/gtk-4.0/settings.ini`.
205          '';
206        };
207
208        extraCss = mkOption {
209          type = types.lines;
210          default = "";
211          description = ''
212            Extra configuration lines to add verbatim to
213            {file}`$XDG_CONFIG_HOME/gtk-4.0/gtk.css`.
214          '';
215        };
216      };
217    };
218  };
219
220  config = mkIf cfg.enable (let
221    gtkIni = optionalAttrs (cfg.font != null) {
222      gtk-font-name = let
223        fontSize =
224          optionalString (cfg.font.size != null) " ${toString cfg.font.size}";
225      in "${cfg.font.name}" + fontSize;
226    } // optionalAttrs (cfg.theme != null) { gtk-theme-name = cfg.theme.name; }
227      // optionalAttrs (cfg.iconTheme != null) {
228        gtk-icon-theme-name = cfg.iconTheme.name;
229      } // optionalAttrs (cfg.cursorTheme != null) {
230        gtk-cursor-theme-name = cfg.cursorTheme.name;
231      } // optionalAttrs
232      (cfg.cursorTheme != null && cfg.cursorTheme.size != null) {
233        gtk-cursor-theme-size = cfg.cursorTheme.size;
234      };
235
236    dconfIni = optionalAttrs (cfg.font != null) {
237      font-name = let
238        fontSize =
239          optionalString (cfg.font.size != null) " ${toString cfg.font.size}";
240      in "${cfg.font.name}" + fontSize;
241    } // optionalAttrs (cfg.theme != null) { gtk-theme = cfg.theme.name; }
242      // optionalAttrs (cfg.iconTheme != null) {
243        icon-theme = cfg.iconTheme.name;
244      } // optionalAttrs (cfg.cursorTheme != null) {
245        cursor-theme = cfg.cursorTheme.name;
246      } // optionalAttrs
247      (cfg.cursorTheme != null && cfg.cursorTheme.size != null) {
248        cursor-size = cfg.cursorTheme.size;
249      };
250
251    optionalPackage = opt:
252      optional (opt != null && opt.package != null) opt.package;
253  in {
254    home.packages = concatMap optionalPackage [
255      cfg.font
256      cfg.theme
257      cfg.iconTheme
258      cfg.cursorTheme
259    ];
260
261    home.file.${cfg2.configLocation}.text =
262      concatMapStrings (l: l + "\n") (mapAttrsToList formatGtk2Option gtkIni)
263      + cfg2.extraConfig + "\n";
264
265    home.sessionVariables.GTK2_RC_FILES = cfg2.configLocation;
266
267    xdg.configFile."gtk-3.0/settings.ini".text =
268      toGtk3Ini { Settings = gtkIni // cfg3.extraConfig; };
269
270    xdg.configFile."gtk-3.0/gtk.css" =
271      mkIf (cfg3.extraCss != "") { text = cfg3.extraCss; };
272
273    xdg.configFile."gtk-3.0/bookmarks" = mkIf (cfg3.bookmarks != [ ]) {
274      text = concatMapStrings (l: l + "\n") cfg3.bookmarks;
275    };
276
277    xdg.configFile."gtk-4.0/settings.ini".text =
278      toGtk3Ini { Settings = gtkIni // cfg4.extraConfig; };
279
280    xdg.configFile."gtk-4.0/gtk.css" =
281      mkIf (cfg4.extraCss != "") { text = cfg4.extraCss; };
282
283    dconf.settings."org/gnome/desktop/interface" = dconfIni;
284  });
285}