fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
18.4 KiB570 linesraw
1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.zsh.prezto;
8
9  relToDotDir = file:
10    (optionalString (config.programs.zsh.dotDir != null)
11      (config.programs.zsh.dotDir + "/")) + file;
12
13  preztoModule = types.submodule {
14    options = {
15      enable = mkEnableOption "prezto";
16
17      caseSensitive = mkOption {
18        type = types.nullOr types.bool;
19        default = null;
20        example = true;
21        description =
22          "Set case-sensitivity for completion, history lookup, etc.";
23      };
24
25      color = mkOption {
26        type = types.nullOr types.bool;
27        default = true;
28        example = false;
29        description = ''
30          Color output (automatically set to `false` on dumb terminals).
31        '';
32      };
33
34      pmoduleDirs = mkOption {
35        type = types.listOf types.path;
36        default = [ ];
37        example = [ "$HOME/.zprezto-contrib" ];
38        description = "Add additional directories to load prezto modules from.";
39      };
40
41      extraConfig = mkOption {
42        type = types.lines;
43        default = "";
44        description = ''
45          Additional configuration to add to {file}`.zpreztorc`.
46        '';
47      };
48
49      extraModules = mkOption {
50        type = types.listOf types.str;
51        default = [ ];
52        example = [ "attr" "stat" ];
53        description = ''
54          Set the Zsh modules to load ({manpage}`zshmodules(1)`).
55        '';
56      };
57
58      extraFunctions = mkOption {
59        type = types.listOf types.str;
60        default = [ ];
61        example = [ "zargs" "zmv" ];
62        description = ''
63          Set the Zsh functions to load ({manpage}`zshcontrib(1)`).
64        '';
65      };
66
67      pmodules = mkOption {
68        type = types.listOf types.str;
69        default = [
70          "environment"
71          "terminal"
72          "editor"
73          "history"
74          "directory"
75          "spectrum"
76          "utility"
77          "completion"
78          "prompt"
79        ];
80        description =
81          "Set the Prezto modules to load (browse modules). The order matters.";
82      };
83
84      autosuggestions.color = mkOption {
85        type = types.nullOr types.str;
86        default = null;
87        example = "fg=blue";
88        description = "Set the query found color.";
89      };
90
91      completions.ignoredHosts = mkOption {
92        type = types.listOf types.str;
93        default = [ ];
94        example = [ "0.0.0.0" "127.0.0.1" ];
95        description = ''
96          Set the entries to ignore in static {file}`/etc/hosts` for
97          host completion.
98        '';
99      };
100
101      editor = {
102        keymap = mkOption {
103          type = types.nullOr (types.enum [ "emacs" "vi" ]);
104          default = "emacs";
105          example = "vi";
106          description = ''
107            Set the key mapping style to `emacs` or `vi`.
108          '';
109        };
110
111        dotExpansion = mkOption {
112          type = types.nullOr types.bool;
113          default = null;
114          example = true;
115          description = ''
116            Automatically convert `....` to `../..`
117          '';
118        };
119
120        promptContext = mkOption {
121          type = types.nullOr types.bool;
122          default = null;
123          example = true;
124          description = "Allow the Zsh prompt context to be shown.";
125        };
126      };
127
128      git.submoduleIgnore = mkOption {
129        type = types.nullOr (types.enum [ "dirty" "untracked" "all" "none" ]);
130        default = null;
131        example = "all";
132        description = ''
133          Ignore submodules when they are `dirty`, `untracked`, `all`,
134          or `none`.
135        '';
136      };
137
138      gnuUtility.prefix = mkOption {
139        type = types.nullOr types.str;
140        default = null;
141        example = "g";
142        description = "Set the command prefix on non-GNU systems.";
143      };
144
145      historySubstring = {
146        foundColor = mkOption {
147          type = types.nullOr types.str;
148          default = null;
149          example = "fg=blue";
150          description = "Set the query found color.";
151        };
152
153        notFoundColor = mkOption {
154          type = types.nullOr types.str;
155          default = null;
156          example = "fg=red";
157          description = "Set the query not found color.";
158        };
159
160        globbingFlags = mkOption {
161          type = types.nullOr types.str;
162          default = null;
163          description = "Set the search globbing flags.";
164        };
165      };
166
167      macOS.dashKeyword = mkOption {
168        type = types.nullOr types.str;
169        default = null;
170        example = "manpages";
171        description = ''
172          Set the keyword used by {command}`mand` to open man pages
173          in Dash.app.
174        '';
175      };
176
177      prompt = {
178        theme = mkOption {
179          type = types.nullOr types.str;
180          default = "sorin";
181          example = "pure";
182          description = ''
183            Set the prompt theme to load. Setting it to `random`
184            loads a random theme. Automatically set to `off` on dumb
185            terminals.
186          '';
187        };
188
189        pwdLength = mkOption {
190          type = types.nullOr (types.enum [ "short" "long" "full" ]);
191          default = null;
192          example = "short";
193          description = ''
194            Set the working directory prompt display length. By
195            default, it is set to `short`. Set it to `long` (without `~`
196            expansion) for longer or `full` (with `~` expansion) for
197            even longer prompt display.
198          '';
199        };
200
201        showReturnVal = mkOption {
202          type = types.nullOr types.bool;
203          default = null;
204          example = true;
205          description = ''
206            Set the prompt to display the return code along with an
207            indicator for non-zero return codes. This is not supported by all prompts.
208          '';
209        };
210      };
211
212      python = {
213        virtualenvAutoSwitch = mkOption {
214          type = types.nullOr types.bool;
215          default = null;
216          example = true;
217          description = "Auto switch to Python virtualenv on directory change.";
218        };
219
220        virtualenvInitialize = mkOption {
221          type = types.nullOr types.bool;
222          default = null;
223          example = true;
224          description =
225            "Automatically initialize virtualenvwrapper if pre-requisites are met.";
226        };
227      };
228
229      ruby.chrubyAutoSwitch = mkOption {
230        type = types.nullOr types.bool;
231        default = null;
232        example = true;
233        description = "Auto switch the Ruby version on directory change.";
234      };
235
236      screen = {
237        autoStartLocal = mkOption {
238          type = types.nullOr types.bool;
239          default = null;
240          example = true;
241          description =
242            "Auto start a session when Zsh is launched in a local terminal.";
243        };
244
245        autoStartRemote = mkOption {
246          type = types.nullOr types.bool;
247          default = null;
248          example = true;
249          description =
250            "Auto start a session when Zsh is launched in a SSH connection.";
251        };
252      };
253
254      ssh.identities = mkOption {
255        type = types.listOf types.str;
256        default = [ ];
257        example = [ "id_rsa" "id_rsa2" "id_github" ];
258        description = "Set the SSH identities to load into the agent.";
259      };
260
261      syntaxHighlighting = {
262        highlighters = mkOption {
263          type = types.listOf types.str;
264          default = [ ];
265          example = [ "main" "brackets" "pattern" "line" "cursor" "root" ];
266          description = ''
267            Set syntax highlighters. By default, only the main
268            highlighter is enabled.
269          '';
270        };
271
272        styles = mkOption {
273          type = types.attrsOf types.str;
274          default = { };
275          example = {
276            builtin = "bg=blue";
277            command = "bg=blue";
278            function = "bg=blue";
279          };
280          description = "Set syntax highlighting styles.";
281        };
282
283        pattern = mkOption {
284          type = types.attrsOf types.str;
285          default = { };
286          example = { "rm*-rf*" = "fg=white,bold,bg=red"; };
287          description = "Set syntax pattern styles.";
288        };
289      };
290
291      terminal = {
292        autoTitle = mkOption {
293          type = types.nullOr types.bool;
294          default = null;
295          example = true;
296          description = "Auto set the tab and window titles.";
297        };
298
299        windowTitleFormat = mkOption {
300          type = types.nullOr types.str;
301          default = null;
302          example = "%n@%m: %s";
303          description = "Set the window title format.";
304        };
305
306        tabTitleFormat = mkOption {
307          type = types.nullOr types.str;
308          default = null;
309          example = "%m: %s";
310          description = "Set the tab title format.";
311        };
312
313        multiplexerTitleFormat = mkOption {
314          type = types.nullOr types.str;
315          default = null;
316          example = "%s";
317          description = "Set the multiplexer title format.";
318        };
319      };
320
321      tmux = {
322        autoStartLocal = mkOption {
323          type = types.nullOr types.bool;
324          default = null;
325          example = true;
326          description =
327            "Auto start a session when Zsh is launched in a local terminal.";
328        };
329
330        autoStartRemote = mkOption {
331          type = types.nullOr types.bool;
332          default = null;
333          example = true;
334          description =
335            "Auto start a session when Zsh is launched in a SSH connection.";
336        };
337
338        itermIntegration = mkOption {
339          type = types.nullOr types.bool;
340          default = null;
341          example = true;
342          description = "Integrate with iTerm2.";
343        };
344
345        defaultSessionName = mkOption {
346          type = types.nullOr types.str;
347          default = null;
348          example = "YOUR DEFAULT SESSION NAME";
349          description = "Set the default session name.";
350        };
351      };
352
353      utility.safeOps = mkOption {
354        type = types.nullOr types.bool;
355        default = null;
356        example = true;
357        description = ''
358          Enabled safe options. This aliases {command}`cp`,
359          {command}`ln`, {command}`mv` and {command}`rm` so that they
360          prompt before deleting or overwriting files. Set to `no` to
361          disable this safer behavior.
362        '';
363      };
364    };
365  };
366
367in {
368  meta.maintainers = [ maintainers.nickhu ];
369  options = {
370    programs.zsh = {
371      prezto = mkOption {
372        type = preztoModule;
373        default = { };
374        description = "Options to configure prezto.";
375      };
376    };
377  };
378  config = mkIf cfg.enable (mkMerge [{
379    home.file."${relToDotDir ".zprofile"}".text =
380      builtins.readFile "${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zprofile";
381    home.file."${relToDotDir ".zlogin"}".text =
382      builtins.readFile "${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zlogin";
383    home.file."${relToDotDir ".zlogout"}".text =
384      builtins.readFile "${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zlogout";
385    home.packages = with pkgs; [ zsh-prezto ];
386
387    home.file."${relToDotDir ".zshenv"}".text =
388      builtins.readFile "${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zshenv";
389    home.file."${relToDotDir ".zpreztorc"}".text = ''
390      # Generated by Nix
391      ${optionalString (cfg.caseSensitive != null) ''
392        zstyle ':prezto:*:*' case-sensitive '${
393          lib.hm.booleans.yesNo cfg.caseSensitive
394        }'
395      ''}
396      ${optionalString (cfg.color != null) ''
397        zstyle ':prezto:*:*' color '${lib.hm.booleans.yesNo cfg.color}'
398      ''}
399      ${optionalString (cfg.pmoduleDirs != [ ]) ''
400        zstyle ':prezto:load' pmodule-dirs ${
401          builtins.concatStringsSep " " cfg.pmoduleDirs
402        }
403      ''}
404      ${optionalString (cfg.extraModules != [ ]) ''
405        zstyle ':prezto:load' zmodule ${
406          strings.concatMapStringsSep " " strings.escapeShellArg
407          cfg.extraModules
408        }
409      ''}
410      ${optionalString (cfg.extraFunctions != [ ]) ''
411        zstyle ':prezto:load' zfunction ${
412          strings.concatMapStringsSep " " strings.escapeShellArg
413          cfg.extraFunctions
414        }
415      ''}
416      ${optionalString (cfg.pmodules != [ ]) ''
417        zstyle ':prezto:load' pmodule \
418          ${
419            strings.concatMapStringsSep " \\\n  " strings.escapeShellArg
420            cfg.pmodules
421          }
422      ''}
423      ${optionalString (cfg.autosuggestions.color != null) ''
424        zstyle ':prezto:module:autosuggestions:color' found '${cfg.autosuggestions.color}'
425      ''}
426      ${optionalString (cfg.completions.ignoredHosts != [ ]) ''
427        zstyle ':prezto:module:completion:*:hosts' etc-host-ignores \
428          ${
429            strings.concatMapStringsSep " " strings.escapeShellArg
430            cfg.completions.ignoredHosts
431          }
432      ''}
433      ${optionalString (cfg.editor.keymap != null) ''
434        zstyle ':prezto:module:editor' key-bindings '${cfg.editor.keymap}'
435      ''}
436      ${optionalString (cfg.editor.dotExpansion != null) ''
437        zstyle ':prezto:module:editor' dot-expansion '${
438          lib.hm.booleans.yesNo cfg.editor.dotExpansion
439        }'
440      ''}
441      ${optionalString (cfg.editor.promptContext != null) ''
442        zstyle ':prezto:module:editor' ps-context '${
443          lib.hm.booleans.yesNo cfg.editor.promptContext
444        }'
445      ''}
446      ${optionalString (cfg.git.submoduleIgnore != null) ''
447        zstyle ':prezto:module:git:status:ignore' submodules '${cfg.git.submoduleIgnore}'
448      ''}
449      ${optionalString (cfg.gnuUtility.prefix != null) ''
450        zstyle ':prezto:module:gnu-utility' prefix '${cfg.gnuUtility.prefix}'
451      ''}
452      ${optionalString (cfg.historySubstring.foundColor != null) ''
453        zstyle ':prezto:module:history-substring-search:color' found '${cfg.historySubstring.foundColor}'
454      ''}
455      ${optionalString (cfg.historySubstring.notFoundColor != null) ''
456        zstyle ':prezto:module:history-substring-search:color' not-found '${cfg.historySubstring.notFoundColor}'
457      ''}
458      ${optionalString (cfg.historySubstring.globbingFlags != null) ''
459        zstyle ':prezto:module:history-substring-search:color' globbing-flags '${cfg.historySubstring.globbingFlags}'
460      ''}
461      ${optionalString (cfg.macOS.dashKeyword != null) ''
462        zstyle ':prezto:module:osx:man' dash-keyword '${cfg.macOS.dashKeyword}'
463      ''}
464      ${optionalString (cfg.prompt.theme != null) ''
465        zstyle ':prezto:module:prompt' theme '${cfg.prompt.theme}'
466      ''}
467      ${optionalString (cfg.prompt.pwdLength != null) ''
468        zstyle ':prezto:module:prompt' pwd-length '${cfg.prompt.pwdLength}'
469      ''}
470      ${optionalString (cfg.prompt.showReturnVal != null) ''
471        zstyle ':prezto:module:prompt' show-return-val '${
472          lib.hm.booleans.yesNo cfg.prompt.showReturnVal
473        }'
474      ''}
475      ${optionalString (cfg.python.virtualenvAutoSwitch != null) ''
476        zstyle ':prezto:module:python:virtualenv' auto-switch '${
477          lib.hm.booleans.yesNo cfg.python.virtualenvAutoSwitch
478        }'
479      ''}
480      ${optionalString (cfg.python.virtualenvInitialize != null) ''
481        zstyle ':prezto:module:python:virtualenv' initialize '${
482          lib.hm.booleans.yesNo cfg.python.virtualenvInitialize
483        }'
484      ''}
485      ${optionalString (cfg.ruby.chrubyAutoSwitch != null) ''
486        zstyle ':prezto:module:ruby:chruby' auto-switch '${
487          lib.hm.booleans.yesNo cfg.ruby.chrubyAutoSwitch
488        }'
489      ''}
490      ${optionalString (cfg.screen.autoStartLocal != null) ''
491        zstyle ':prezto:module:screen:auto-start' local '${
492          lib.hm.booleans.yesNo cfg.screen.autoStartLocal
493        }'
494      ''}
495      ${optionalString (cfg.screen.autoStartRemote != null) ''
496        zstyle ':prezto:module:screen:auto-start' remote '${
497          lib.hm.booleans.yesNo cfg.screen.autoStartRemote
498        }'
499      ''}
500      ${optionalString (cfg.ssh.identities != [ ]) ''
501        zstyle ':prezto:module:ssh:load' identities \
502          ${
503            strings.concatMapStringsSep " " strings.escapeShellArg
504            cfg.ssh.identities
505          }
506      ''}
507      ${optionalString (cfg.syntaxHighlighting.highlighters != [ ]) ''
508        zstyle ':prezto:module:syntax-highlighting' highlighters \
509          ${
510            strings.concatMapStringsSep " \\\n  " strings.escapeShellArg
511            cfg.syntaxHighlighting.highlighters
512          }
513      ''}
514      ${optionalString (cfg.syntaxHighlighting.styles != { }) ''
515        zstyle ':prezto:module:syntax-highlighting' styles \
516          ${
517            builtins.concatStringsSep " \\\n" (attrsets.mapAttrsToList
518              (k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v)
519              cfg.syntaxHighlighting.styles)
520          }
521      ''}
522      ${optionalString (cfg.syntaxHighlighting.pattern != { }) ''
523        zstyle ':prezto:module:syntax-highlighting' pattern \
524          ${
525            builtins.concatStringsSep " \\\n" (attrsets.mapAttrsToList
526              (k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v)
527              cfg.syntaxHighlighting.pattern)
528          }
529      ''}
530      ${optionalString (cfg.terminal.autoTitle != null) ''
531        zstyle ':prezto:module:terminal' auto-title '${
532          lib.hm.booleans.yesNo cfg.terminal.autoTitle
533        }'
534      ''}
535      ${optionalString (cfg.terminal.windowTitleFormat != null) ''
536        zstyle ':prezto:module:terminal:window-title' format '${cfg.terminal.windowTitleFormat}'
537      ''}
538      ${optionalString (cfg.terminal.tabTitleFormat != null) ''
539        zstyle ':prezto:module:terminal:tab-title' format '${cfg.terminal.tabTitleFormat}'
540      ''}
541      ${optionalString (cfg.terminal.multiplexerTitleFormat != null) ''
542        zstyle ':prezto:module:terminal:multiplexer-title' format '${cfg.terminal.multiplexerTitleFormat}'
543      ''}
544      ${optionalString (cfg.tmux.autoStartLocal != null) ''
545        zstyle ':prezto:module:tmux:auto-start' local '${
546          lib.hm.booleans.yesNo cfg.tmux.autoStartLocal
547        }'
548      ''}
549      ${optionalString (cfg.tmux.autoStartRemote != null) ''
550        zstyle ':prezto:module:tmux:auto-start' remote '${
551          lib.hm.booleans.yesNo cfg.tmux.autoStartRemote
552        }'
553      ''}
554      ${optionalString (cfg.tmux.itermIntegration != null) ''
555        zstyle ':prezto:module:tmux:iterm' integrate '${
556          lib.hm.booleans.yesNo cfg.tmux.itermIntegration
557        }'
558      ''}
559      ${optionalString (cfg.tmux.defaultSessionName != null) ''
560        zstyle ':prezto:module:tmux:session' name '${cfg.tmux.defaultSessionName}'
561      ''}
562      ${optionalString (cfg.utility.safeOps != null) ''
563        zstyle ':prezto:module:utility' safe-ops '${
564          lib.hm.booleans.yesNo cfg.utility.safeOps
565        }'
566      ''}
567      ${cfg.extraConfig}
568    '';
569  }]);
570}