You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+32-21Lines changed: 32 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,10 +34,10 @@ To add a new plugin you need to do the following.
34
34
35
35
The vast majority of plugins fall into one of those two categories:
36
36
-_vim plugins_: They are configured through **global variables** (`g:plugin_foo_option` in vimscript and `vim.g.plugin_foo_option` in lua).\
37
-
For those, you should use the `helpers.vim-plugin.mkVimPlugin`.\
37
+
For those, you should use the `lib.nixvim.vim-plugin.mkVimPlugin`.\
38
38
-> See [this plugin](plugins/utils/direnv.nix) for an example.
39
39
-_neovim plugins_: They are configured through a `setup` function (`require('plugin').setup({opts})`).\
40
-
For those, you should use the `helpers.neovim-plugin.mkNeovimPlugin`.\
40
+
For those, you should use the `lib.nixvim.neovim-plugin.mkNeovimPlugin`.\
41
41
-> See the [template](plugins/TEMPLATE.nix).
42
42
43
43
2. Add the necessary parameters for the `mkNeovimPlugin`/`mkVimPlugin`:
@@ -47,38 +47,49 @@ The vast majority of plugins fall into one of those two categories:
47
47
-`package`: The nixpkgs package attr for this plugin
48
48
e.g. `"foo-bar-nvim` for `pkgs.vimPlugins.foo-bar-nvim`, or `[ "hello" "world" ]` for `pkgs.hello.world`.
49
49
-`maintainers`: Register yourself as a maintainer for this plugin:
50
-
-`[lib.maintainers.JosephFourier]` if you are already registered as a [`nixpkgs` maintainer](https://github.com/NixOS/nixpkgs/blob/master/maintainers/maintainer-list.nix)
51
-
-`[helpers.maintainers.GaspardMonge]` otherwise. (Also add yourself to [`maintainers.nix`](lib/maintainers.nix))
50
+
- e.g. `maintainers = [ lib.maintainers.JosephFourier ]`
51
+
- If you are already registered as a [`nixpkgs` maintainer][nixpkgs-maintainers], there is nothing more to do.
52
+
- Otherwise, you should add yourself to our [`maintainers.nix`](lib/maintainers.nix) list.
53
+
- See the documentation at the top of the [`nixpkgs` maintainers list][nixpkgs-maintainers] for more detail.
52
54
-`settingsOptions`: All or some (only the most important ones) option declarations for this plugin settings.\
53
55
See below for more information
54
56
-`settingsExample`: An example of what could the `settings` attrs look like.
55
57
56
-
#### Declaring plugin options
57
-
58
-
You will then need to add Nix options for all (or some) of the upstream plugin options.
59
-
These option declarations should be in `settingsOptions` and their names should match exactly the upstream plugin.
60
-
There are a number of helpers to help you correctly implement them:
58
+
3. Add to plugins/default.nix
59
+
- As a final step, please add your plugin to `plugins/default.nix` to ensure it gets imported.
60
+
- Note: the imports list is sorted and grouped. In vim, you can usually use `V` (visual-line mode) with the `:sort` command to achieve the desired result.
61
61
62
-
-`helpers.defaultNullOpts.{mkBool,mkInt,mkStr,...}`: This family of helpers takes a default value and a description, and sets the Nix default to `null`. These are the main functions you should use to define options.
63
-
-`helpers.defaultNullOpts.mkNullable`: This takes a type, a default and a description. This is useful for more complex options.
64
-
-`helpers.nixvimTypes.rawLua`: A type to represent raw lua code. The values are of the form `{ __raw = "<code>";}`. This should not be used if the option can only be raw lua code, `mkLua`/`mkLuaFn` should be used in this case.
The resulting `settings` attrs will be directly translated to `lua` and will be forwarded the plugin:
67
-
- Using globals (`vim.g.<globalPrefix><option-name>`) for plugins using `mkVimPlugin`
68
-
- Using the `require('<plugin>').setup()` function for the plugins using `mkNeovimPlugin`
64
+
#### Declaring plugin options
69
65
70
-
In either case, you don't need to bother implementing this part. It is done automatically.
66
+
> [!CAUTION]
67
+
> Declaring `settings`-options is **not required**, because the `settings` option is a freeform type.
68
+
>
69
+
> While `settings` options can be helpful for documentation and type-checking purposes, this is a double-edged sword because we have to ensure the options are correctly typed and documented to avoid unnecessary restrictions or confusion.
71
70
72
71
> [!TIP]
73
72
> Learn more about the [RFC 42](https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md) which motivated this new approach.
74
73
75
-
> [!NOTE]
76
-
> `settings` has a "freeform" type `attrsOf anything`, meaning it can be configured with _anything_.
77
-
> Declaring `settingsOptions` is therefore optional and just adds type-checking and documentation.
74
+
If you feel having nix options for some of the upstream plugin options adds value and is worth the maintenance cost, you can declare these in `settingsOptions`.
78
75
79
-
#### Add to plugins/default.nix
80
-
As a final step, please add your plugin to `plugins/default.nix`. Please maintain the file hierarchy.
76
+
Take care to ensure option names exactly match the upstream plugin's option names (without `globalsPrefix`, if used).
77
+
You must also ensure that the option type is permissive enough to avoid unnecessarily restricting config definitions.
78
+
If unsure, you can forego declaring the option or use a permissive type such as `lib.types.anything`.
81
79
80
+
There are a number of helpers added into `lib` that can help you correctly implement them:
81
+
82
+
-`lib.nixvim.defaultNullOpts.{mkBool,mkInt,mkStr,...}`: This family of helpers takes a default value and a description, and sets the Nix default to `null`.
83
+
These are the main functions you should use to define options.
84
+
-`lib.nixvim.defaultNullOpts.<name>'`: These "prime" variants of the above helpers do the same thing, but expect a "structured" attrs argument.
85
+
This allows more flexibility in what arguments are passed through to the underlying `lib.mkOption` call.
86
+
-`lib.types.rawLua`: A type to represent raw lua code. The values are of the form `{ __raw = "<code>";}`.
87
+
88
+
The resulting `settings` attrs will be directly translated to `lua` and will be forwarded the plugin:
89
+
- Using globals (`vim.g.<globalPrefix><option-name>`) for plugins using `mkVimPlugin`
90
+
- Using the `require('<plugin>').setup(<options>)` function for the plugins using `mkNeovimPlugin`
91
+
92
+
In either case, you don't need to bother implementing this part. It is done automatically.
0 commit comments