fork/home-manager

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

Robert Helgessongnome-terminal: add assertion on profile namesf58889c0

master
9.5 KiB340 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.gnome-terminal;
8
9  eraseBinding = types.enum [
10    "auto"
11    "ascii-backspace"
12    "ascii-delete"
13    "delete-sequence"
14    "tty"
15  ];
16
17  backForeSubModule = types.submodule ({ ... }: {
18    options = {
19      foreground = mkOption {
20        type = types.str;
21        description = "The foreground color.";
22      };
23
24      background = mkOption {
25        type = types.str;
26        description = "The background color.";
27      };
28    };
29  });
30
31  profileColorsSubModule = types.submodule ({ ... }: {
32    options = {
33      foregroundColor = mkOption {
34        type = types.str;
35        description = "The foreground color.";
36      };
37
38      backgroundColor = mkOption {
39        type = types.str;
40        description = "The background color.";
41      };
42
43      boldColor = mkOption {
44        default = null;
45        type = types.nullOr types.str;
46        description = "The bold color, null to use same as foreground.";
47      };
48
49      palette = mkOption {
50        type = types.listOf types.str;
51        description = "The terminal palette.";
52      };
53
54      cursor = mkOption {
55        default = null;
56        type = types.nullOr backForeSubModule;
57        description = "The color for the terminal cursor.";
58      };
59
60      highlight = mkOption {
61        default = null;
62        type = types.nullOr backForeSubModule;
63        description = "The colors for the terminal’s highlighted area.";
64      };
65    };
66  });
67
68  profileSubModule = types.submodule ({ name, config, ... }: {
69    options = {
70      default = mkOption {
71        default = false;
72        type = types.bool;
73        description = "Whether this should be the default profile.";
74      };
75
76      visibleName = mkOption {
77        type = types.str;
78        description = "The profile name.";
79      };
80
81      colors = mkOption {
82        default = null;
83        type = types.nullOr profileColorsSubModule;
84        description = "The terminal colors, null to use system default.";
85      };
86
87      cursorBlinkMode = mkOption {
88        default = "system";
89        type = types.enum [ "system" "on" "off" ];
90        description = "The cursor blink mode.";
91      };
92
93      cursorShape = mkOption {
94        default = "block";
95        type = types.enum [ "block" "ibeam" "underline" ];
96        description = "The cursor shape.";
97      };
98
99      font = mkOption {
100        default = null;
101        type = types.nullOr types.str;
102        description = "The font name, null to use system default.";
103      };
104
105      allowBold = mkOption {
106        default = null;
107        type = types.nullOr types.bool;
108        description = ''
109          If `true`, allow applications in the
110          terminal to make text boldface.
111        '';
112      };
113
114      scrollOnOutput = mkOption {
115        default = true;
116        type = types.bool;
117        description = "Whether to scroll when output is written.";
118      };
119
120      showScrollbar = mkOption {
121        default = true;
122        type = types.bool;
123        description = "Whether the scroll bar should be visible.";
124      };
125
126      scrollbackLines = mkOption {
127        default = 10000;
128        type = types.nullOr types.int;
129        description = ''
130          The number of scrollback lines to keep, null for infinite.
131        '';
132      };
133
134      customCommand = mkOption {
135        default = null;
136        type = types.nullOr types.str;
137        description = ''
138          The command to use to start the shell, or null for default shell.
139        '';
140      };
141
142      loginShell = mkOption {
143        default = false;
144        type = types.bool;
145        description = "Run command as a login shell.";
146      };
147
148      backspaceBinding = mkOption {
149        default = "ascii-delete";
150        type = eraseBinding;
151        description = ''
152          Which string the terminal should send to an application when the user
153          presses the *Backspace* key.
154
155          `auto`
156          : Attempt to determine the right value from the terminal's IO settings.
157
158          `ascii-backspace`
159          : Send an ASCII backspace character (`0x08`).
160
161          `ascii-delete`
162          : Send an ASCII delete character (`0x7F`).
163
164          `delete-sequence`
165          : Send the `@7` control sequence.
166
167          `tty`
168          : Send terminal's "erase" setting.
169        '';
170      };
171
172      boldIsBright = mkOption {
173        default = null;
174        type = types.nullOr types.bool;
175        description = "Whether bold text is shown in bright colors.";
176      };
177
178      deleteBinding = mkOption {
179        default = "delete-sequence";
180        type = eraseBinding;
181        description = ''
182          Which string the terminal should send to an application when the user
183          presses the *Delete* key.
184
185          `auto`
186          : Send the `@7` control sequence.
187
188          `ascii-backspace`
189          : Send an ASCII backspace character (`0x08`).
190
191          `ascii-delete`
192          : Send an ASCII delete character (`0x7F`).
193
194          `delete-sequence`
195          : Send the `@7` control sequence.
196
197          `tty`
198          : Send terminal's "erase" setting.
199        '';
200      };
201
202      audibleBell = mkOption {
203        default = true;
204        type = types.bool;
205        description = "Turn on/off the terminal's bell.";
206      };
207
208      transparencyPercent = mkOption {
209        default = null;
210        type = types.nullOr (types.ints.between 0 100);
211        description = "Background transparency in percent.";
212      };
213    };
214  });
215
216  buildProfileSet = pcfg:
217    {
218      audible-bell = pcfg.audibleBell;
219      visible-name = pcfg.visibleName;
220      scroll-on-output = pcfg.scrollOnOutput;
221      scrollbar-policy = if pcfg.showScrollbar then "always" else "never";
222      scrollback-lines = pcfg.scrollbackLines;
223      cursor-shape = pcfg.cursorShape;
224      cursor-blink-mode = pcfg.cursorBlinkMode;
225      login-shell = pcfg.loginShell;
226      backspace-binding = pcfg.backspaceBinding;
227      delete-binding = pcfg.deleteBinding;
228    } // (if (pcfg.customCommand != null) then {
229      use-custom-command = true;
230      custom-command = pcfg.customCommand;
231    } else {
232      use-custom-command = false;
233    }) // (if (pcfg.font == null) then {
234      use-system-font = true;
235    } else {
236      use-system-font = false;
237      font = pcfg.font;
238    }) // (if (pcfg.colors == null) then {
239      use-theme-colors = true;
240    } else
241      ({
242        use-theme-colors = false;
243        foreground-color = pcfg.colors.foregroundColor;
244        background-color = pcfg.colors.backgroundColor;
245        palette = pcfg.colors.palette;
246      } // optionalAttrs (pcfg.allowBold != null) {
247        allow-bold = pcfg.allowBold;
248      } // (if (pcfg.colors.boldColor == null) then {
249        bold-color-same-as-fg = true;
250      } else {
251        bold-color-same-as-fg = false;
252        bold-color = pcfg.colors.boldColor;
253      }) // optionalAttrs (pcfg.boldIsBright != null) {
254        bold-is-bright = pcfg.boldIsBright;
255      } // (if (pcfg.colors.cursor != null) then {
256        cursor-colors-set = true;
257        cursor-foreground-color = pcfg.colors.cursor.foreground;
258        cursor-background-color = pcfg.colors.cursor.background;
259      } else {
260        cursor-colors-set = false;
261      }) // (if (pcfg.colors.highlight != null) then {
262        highlight-colors-set = true;
263        highlight-foreground-color = pcfg.colors.highlight.foreground;
264        highlight-background-color = pcfg.colors.highlight.background;
265      } else {
266        highlight-colors-set = false;
267      }) // optionalAttrs (pcfg.transparencyPercent != null) {
268        background-transparency-percent = pcfg.transparencyPercent;
269        use-theme-transparency = false;
270        use-transparent-background = true;
271      }));
272
273in {
274  meta.maintainers = with maintainers; [ kamadorueda rycee ];
275
276  options = {
277    programs.gnome-terminal = {
278      enable = mkEnableOption "Gnome Terminal";
279
280      showMenubar = mkOption {
281        default = true;
282        type = types.bool;
283        description = "Whether to show the menubar by default";
284      };
285
286      themeVariant = mkOption {
287        default = "default";
288        type = types.enum [ "default" "light" "dark" "system" ];
289        description = "The theme variation to request";
290      };
291
292      profile = mkOption {
293        default = { };
294        type = types.attrsOf profileSubModule;
295        description = ''
296          A set of Gnome Terminal profiles. Note, the name of a profile must be
297          a UUID. You can generate one, for example, using {command}`uuidgen`
298          (from `util-linux`).
299        '';
300      };
301    };
302  };
303
304  config = mkIf cfg.enable {
305    assertions = [
306      (let
307        uuidre =
308          "[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}";
309        erroneous =
310          filter (n: builtins.match uuidre n == null) (attrNames cfg.profile);
311      in {
312        assertion = erroneous == [ ];
313        message = ''
314          The attribute name of a Gnome Terminal profile must be a UUID.
315          Incorrect profile names: ${concatStringsSep ", " erroneous}'';
316      })
317    ];
318
319    home.packages = [ pkgs.gnome.gnome-terminal ];
320
321    dconf.settings = let dconfPath = "org/gnome/terminal/legacy";
322    in {
323      "${dconfPath}" = {
324        default-show-menubar = cfg.showMenubar;
325        theme-variant = cfg.themeVariant;
326        schema-version = 3;
327      };
328
329      "${dconfPath}/profiles:" = {
330        default = head (attrNames (filterAttrs (n: v: v.default) cfg.profile));
331        list = attrNames cfg.profile;
332      };
333    } // mapAttrs'
334    (n: v: nameValuePair ("${dconfPath}/profiles:/:${n}") (buildProfileSet v))
335    cfg.profile;
336
337    programs.bash.enableVteIntegration = true;
338    programs.zsh.enableVteIntegration = true;
339  };
340}