fork/home-manager

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

Martin Schwaighoferhelix: add extraPackages option9d0f799c

master
6.5 KiB206 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.helix;
7  tomlFormat = pkgs.formats.toml { };
8in {
9  meta.maintainers = [ hm.maintainers.Philipp-M ];
10
11  options.programs.helix = {
12    enable = mkEnableOption "helix text editor";
13
14    package = mkOption {
15      type = types.package;
16      default = pkgs.helix;
17      defaultText = literalExpression "pkgs.helix";
18      description = "The package to use for helix.";
19    };
20
21    extraPackages = mkOption {
22      type = with types; listOf package;
23      default = [ ];
24      example = literalExpression "[ pkgs.marksman ]";
25      description = "Extra packages available to hx.";
26    };
27
28    defaultEditor = mkOption {
29      type = types.bool;
30      default = false;
31      description = ''
32        Whether to configure {command}`hx` as the default
33        editor using the {env}`EDITOR` environment variable.
34      '';
35    };
36
37    settings = mkOption {
38      type = tomlFormat.type;
39      default = { };
40      example = literalExpression ''
41        {
42          theme = "base16";
43          editor = {
44            line-number = "relative";
45            lsp.display-messages = true;
46          };
47          keys.normal = {
48            space.space = "file_picker";
49            space.w = ":w";
50            space.q = ":q";
51            esc = [ "collapse_selection" "keep_primary_selection" ];
52          };
53        }
54      '';
55      description = ''
56        Configuration written to
57        {file}`$XDG_CONFIG_HOME/helix/config.toml`.
58
59        See <https://docs.helix-editor.com/configuration.html>
60        for the full list of options.
61      '';
62    };
63
64    languages = mkOption {
65      type = with types;
66        coercedTo (listOf tomlFormat.type) (language:
67          lib.warn ''
68            The syntax of programs.helix.languages has changed.
69            It now generates the whole languages.toml file instead of just the language array in that file.
70
71            Use
72            programs.helix.languages = { language = <languages list>; }
73            instead.
74          '' { inherit language; }) (addCheck tomlFormat.type builtins.isAttrs);
75      default = { };
76      example = literalExpression ''
77        {
78          # the language-server option currently requires helix from the master branch at https://github.com/helix-editor/helix/
79          language-server.typescript-language-server = with pkgs.nodePackages; {
80            command = "''${typescript-language-server}/bin/typescript-language-server";
81            args = [ "--stdio" "--tsserver-path=''${typescript}/lib/node_modules/typescript/lib" ];
82          };
83
84          language = [{
85            name = "rust";
86            auto-format = false;
87          }];
88        }
89      '';
90      description = ''
91        Language specific configuration at
92        {file}`$XDG_CONFIG_HOME/helix/languages.toml`.
93
94        See <https://docs.helix-editor.com/languages.html>
95        for more information.
96      '';
97    };
98
99    themes = mkOption {
100      type = types.attrsOf tomlFormat.type;
101      default = { };
102      example = literalExpression ''
103        {
104          base16 = let
105            transparent = "none";
106            gray = "#665c54";
107            dark-gray = "#3c3836";
108            white = "#fbf1c7";
109            black = "#282828";
110            red = "#fb4934";
111            green = "#b8bb26";
112            yellow = "#fabd2f";
113            orange = "#fe8019";
114            blue = "#83a598";
115            magenta = "#d3869b";
116            cyan = "#8ec07c";
117          in {
118            "ui.menu" = transparent;
119            "ui.menu.selected" = { modifiers = [ "reversed" ]; };
120            "ui.linenr" = { fg = gray; bg = dark-gray; };
121            "ui.popup" = { modifiers = [ "reversed" ]; };
122            "ui.linenr.selected" = { fg = white; bg = black; modifiers = [ "bold" ]; };
123            "ui.selection" = { fg = black; bg = blue; };
124            "ui.selection.primary" = { modifiers = [ "reversed" ]; };
125            "comment" = { fg = gray; };
126            "ui.statusline" = { fg = white; bg = dark-gray; };
127            "ui.statusline.inactive" = { fg = dark-gray; bg = white; };
128            "ui.help" = { fg = dark-gray; bg = white; };
129            "ui.cursor" = { modifiers = [ "reversed" ]; };
130            "variable" = red;
131            "variable.builtin" = orange;
132            "constant.numeric" = orange;
133            "constant" = orange;
134            "attributes" = yellow;
135            "type" = yellow;
136            "ui.cursor.match" = { fg = yellow; modifiers = [ "underlined" ]; };
137            "string" = green;
138            "variable.other.member" = red;
139            "constant.character.escape" = cyan;
140            "function" = blue;
141            "constructor" = blue;
142            "special" = blue;
143            "keyword" = magenta;
144            "label" = magenta;
145            "namespace" = blue;
146            "diff.plus" = green;
147            "diff.delta" = yellow;
148            "diff.minus" = red;
149            "diagnostic" = { modifiers = [ "underlined" ]; };
150            "ui.gutter" = { bg = black; };
151            "info" = blue;
152            "hint" = dark-gray;
153            "debug" = dark-gray;
154            "warning" = yellow;
155            "error" = red;
156          };
157        }
158      '';
159      description = ''
160        Each theme is written to
161        {file}`$XDG_CONFIG_HOME/helix/themes/theme-name.toml`.
162        Where the name of each attribute is the theme-name (in the example "base16").
163
164        See <https://docs.helix-editor.com/themes.html>
165        for the full list of options.
166      '';
167    };
168  };
169
170  config = mkIf cfg.enable {
171    home.packages = if cfg.extraPackages != [ ] then
172      [
173        (pkgs.symlinkJoin {
174          name =
175            "${lib.getName cfg.package}-wrapped-${lib.getVersion cfg.package}";
176          paths = [ cfg.package ];
177          preferLocalBuild = true;
178          nativeBuildInputs = [ pkgs.makeWrapper ];
179          postBuild = ''
180            wrapProgram $out/bin/hx \
181              --prefix PATH : ${lib.makeBinPath cfg.extraPackages}
182          '';
183        })
184      ]
185    else
186      [ cfg.package ];
187
188    home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "hx"; };
189
190    xdg.configFile = let
191      settings = {
192        "helix/config.toml" = mkIf (cfg.settings != { }) {
193          source = tomlFormat.generate "helix-config" cfg.settings;
194        };
195        "helix/languages.toml" = mkIf (cfg.languages != { }) {
196          source = tomlFormat.generate "helix-languages-config" cfg.languages;
197        };
198      };
199
200      themes = (mapAttrs' (n: v:
201        nameValuePair "helix/themes/${n}.toml" {
202          source = tomlFormat.generate "helix-theme-${n}" v;
203        }) cfg.themes);
204    in settings // themes;
205  };
206}