summaryrefslogtreecommitdiffstats
path: root/modules/wrapper/rc/options.nix
blob: 3ca0a11e115a97a6af76cd516651b1f2b6fa924d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
{lib, ...}: let
  inherit (lib.options) mkOption literalMD literalExpression;
  inherit (lib.types) str bool int enum attrsOf lines listOf oneOf either path submodule anything;
  inherit (lib.nvim.types) dagOf;
  inherit (lib) isString isPath isDerivation;

  runtimePathType = submodule {
    options = {
      path = mkOption {
        type = either path str;
        description = "Path to add into the runtime path";
      };

      position = mkOption {
        type = enum ["append" "prepend"];
        default = "prepend";
        description = ''
          Decides whether the path should be appended or prepended into the runtime path.
        '';
      };
    };
  };
in {
  options.vim = {
    enableLuaLoader = mkOption {
      type = bool;
      default = false;
      example = true;
      description = ''
        [official documentation]: https://neovim.io/doc/user/lua.html#vim.loader.enable()

        Whether to enable the experimental Lua module loader to speed up the start
        up process. If `true`, this will enable the experimental Lua module loader
        which:

        * overrides loadfile
        * adds the lua loader using the byte-compilation cache
        * adds the libs loader
        * removes the default Neovim loader

        ::: {.note}
        The Lua module loader is *disabled* by default. Before setting this option, please
        take a look at the {option}`[official documentation]`. This option may be enabled by
        default in the future.
        :::
      '';
    };

    additionalRuntimePaths = mkOption {
      type = listOf (oneOf [path str runtimePathType]);
      apply = map (p:
        if isPath p || isString p
        then {
          path = p;
          position = "append";
        }
        else if isDerivation p
        then {
          path = p.out;
          position = "append";
        }
        else p);
      default = [];
      example = literalExpression ''
        [
          # Absolute path, as a string. This is the impure option.
          "$HOME/.config/nvim-extra"

          # Relative path inside your configuration. If your config
          # is version controlled, then this is pure and reproducible.
          ./nvim

          # Source type path. This pure and reproducible.
          # See `:doc builtins.path` inside a Nix repl for more options.
          (builtins.path {
            path = ./runtime; # this must be a relative path
            name = "nvim-runtime"; # name is arbitrary
          })
        ]
      '';

      description = ''
        Additional runtime paths that will be appended or prepended to the active
        runtimepath of the Neovim. This can be used to add additional
        lookup paths for configs, plugins, spell languages and other
        things you would generally place in your {file}`$HOME/.config/nvim`.

        This is meant as a declarative alternative to throwing files into
        {file}`~/.config/nvim` and having the Neovim wrapper pick them up.

        > [!NOTE]
        > When not explicitly defining a position via the attribute set,
        > nvf defaults to appending.

        For more details on `vim.o.runtimepath`, and what paths to use, please see
        [the official documentation](https://neovim.io/doc/user/options.html#'runtimepath').
      '';
    };

    extraLuaFiles = mkOption {
      type = listOf (either path str);
      default = [];
      example = literalExpression ''
        [
          # Absolute path, as a string - impure
          "$HOME/.config/nvim/my-lua-file.lua"

          # Relative path, as a path - pure
          ./nvim/my-lua-file.lua

          # Source type path - pure and reproducible
          (builtins.path {
            path = ./nvim/my-lua-file.lua;
            name = "my-lua-file";
          })
        ]
      '';

      description = ''
        Additional Lua files that will be sourced by Neovim.

        Takes both absolute and relative paths, all of which will be called
        via the `luafile` command in Neovim.

        See [lua-commands](https://neovim.io/doc/user/lua.html#lua-commands)
        on the Neovim documentation for more details.

        ::: {.warning}
        All paths passed to this option must be valid. If Neovim cannot
        resolve the path you are attempting to source, then your configuration
        will error, and Neovim will not start. Please ensure that all paths
        are correct before using this option.
        :::
      '';
    };

    globals = mkOption {
      default = {};
      type = submodule {
        freeformType = attrsOf anything;
        options = {
          mapleader = mkOption {
            type = str;
            default = " ";
            description = "The key used for `<leader>` mappings";
          };

          maplocalleader = mkOption {
            type = str;
            default = ",";
            description = "The key used for `<localleader>` mappings";
          };

          editorconfig = mkOption {
            type = bool;
            default = true;
            description = ''
              Whether to enable EditorConfig integration in Neovim.

              This defaults to true as it is enabled by default in stock
              Neovim, setting this option to false disables EditorConfig
              integration entirely.

              See [Neovim documentation](https://neovim.io/doc/user/editorconfig.html)
              for more details on configuring EditorConfig behaviour.
            '';
          };
        };
      };

      example = {"some_variable" = 42;};
      description = ''
        A freeform attribute set containing global variable values for setting vim
        variables as early as possible. If populated, this option will set vim variables
        in the built {option}`luaConfigRC` as the first item.

        ::: {.note}
        `{foo = "bar";}` will set `vim.g.foo` to "bar", where the type of `bar` in the
        resulting Lua value will be inferred from the type of the value in the
        `{name = value;}` pair passed to the option.
        :::
      '';
    };

    options = mkOption {
      default = {};
      type = submodule {
        freeformType = attrsOf anything;
        options = {
          termguicolors = mkOption {
            type = bool;
            default = true;
            description = "Set terminal up for 256 colours";
          };

          mouse = mkOption {
            type = str;
            default = "nvi";
            example = "a";
            description = ''
              Set modes for mouse support.

              * n - normal
              * v - visual
              * i - insert
              * c - command-line
              * h - all modes when editing a help file
              * a - all modes
              * r - for hit-enter and more-prompt prompt

              [neovim documentation]: https://neovim.io/doc/user/options.html#'mouse'"

              This option takes a string to ensure proper conversion to the corresponding Lua type.
              As such, we do not check the value passed to this option. Please ensure that any value
              that is set here is a valid value as per [neovim documentation].
            '';
          };

          cmdheight = mkOption {
            type = int;
            default = 1;
            description = "Height of the command pane";
          };

          updatetime = mkOption {
            type = int;
            default = 300;
            description = "The number of milliseconds till Cursor Hold event is fired";
          };

          tm = mkOption {
            type = int;
            default = 500;
            description = "Timeout in ms that Neovim will wait for mapped action to complete";
          };

          cursorlineopt = mkOption {
            type = enum ["line" "screenline" "number" "both"];
            default = "line";
            description = "Highlight the text line of the cursor with CursorLine hl-CursorLine";
          };

          splitbelow = mkOption {
            type = bool;
            default = true;
            description = "New splits will open below instead of on top";
          };

          splitright = mkOption {
            type = bool;
            default = true;
            description = "New splits will open to the right";
          };

          autoindent = mkOption {
            type = bool;
            default = true;
            description = "Enable auto indent";
          };

          wrap = mkOption {
            type = bool;
            default = true;
            description = "Enable word wrapping.";
          };

          signcolumn = mkOption {
            type = str;
            default = "yes";
            example = "no";
            description = "Whether to show the sign column";
          };

          tabstop = mkOption {
            type = int;
            default = 8; # Neovim default
            description = ''
              Number of spaces that a `<Tab>` in the file counts for. Also see
              the {command}`:retab` command, and the {option}`softtabstop` option.
            '';
          };

          shiftwidth = mkOption {
            type = int;
            default = 8; # Neovim default
            description = ''
              Number of spaces to use for each step of (auto)indent. Used for
              {option}`cindent`, `>>`, `<<`, etc.

              When zero the {option}`tabstop` value will be used.
            '';
          };
        };
      };

      example = {visualbell = true;};
      description = ''
        A freeform attribute set containing vim options to be set as early as possible.
        If populated, this option will set vim options in the built {option}`luaConfigRC`
        after `basic` and before `pluginConfigs` DAG entries.

        ::: {.note}
        `{foo = "bar";}` will set `vim.opt.foo` to "bar", where the type of
        `bar` in the resulting Lua value will be inferred from the type of the
        value in the `{name = value;}` pair passed to the option.
        :::
      '';
    };

    pluginRC = mkOption {
      type = either (dagOf lines) str;
      default = {};
      description = "The DAG used to configure plugins. If a string is passed, entryAnywhere is automatically applied.";
    };

    luaConfigPre = mkOption {
      type = str;
      default = "";
      defaultText = literalMD ''
        By default, this option will **append** paths in
        {option}`vim.additionalRuntimePaths`
        to the `runtimepath` and enable the experimental Lua module loader
        if {option}`vim.enableLuaLoader` is set to true.
      '';

      example = literalExpression "\${builtins.readFile ./my-lua-config-pre.lua}";

      description = ''
        Verbatim lua code that will be inserted **before**
        the result of `luaConfigRc` DAG has been resolved.

        This option **does not** take a DAG set, but a string
        instead. Useful when you'd like to insert contents
        of lua configs after the DAG result.

        ::: {.warning}
        You do not want to override this option with mkForce
        It is used internally to set certain options as early
        as possible and should be avoided unless you know what
        you're doing. Passing a string to this option will
        merge it with the default contents.
        :::
      '';
    };

    luaConfigRC = mkOption {
      type = either (dagOf lines) str;
      default = {};
      description = ''
        Lua configuration, either as a string or a DAG.

        If this option is passed as a DAG, it will be resolved
        according to the DAG resolution rules (e.g. entryBefore
        or entryAfter) as per the **nvf** extended library.
      '';

      example = literalMD ''
        ```lua
        -- Set the tab size to 4 spaces
        vim.opt.tabstop = 4
        vim.opt.shiftwidth = 4
        vim.opt.expandtab = true
        ```
      '';
    };

    luaConfigPost = mkOption {
      type = str;
      default = "";
      example = literalExpression "\${builtins.readFile ./my-lua-config-post.lua}";
      description = ''
        Verbatim lua code that will be inserted **after**
        the result of the `luaConfigRc` DAG has been resolved

        This option **does not** take a DAG set, but a string
        instead. Useful when you'd like to insert contents
        of lua configs after the DAG result.
      '';
    };

    builtLuaConfigRC = mkOption {
      internal = true;
      type = lines;
      description = "The built lua config for neovim after resolving the DAG";
    };
  };
}