mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
CONTRIBUTING: add documentation for mkCompositeOption (#303)
This commit is contained in:
parent
2b85290c12
commit
72c3f5ea02
1 changed files with 36 additions and 0 deletions
|
@ -87,6 +87,42 @@ Because the options may not have the same case (and may require some pre-process
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### A note on composite/nested options
|
||||||
|
|
||||||
|
Here is how to handle options that have several suboptions:
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
options.my-plugin = {
|
||||||
|
...
|
||||||
|
option1 = ...
|
||||||
|
|
||||||
|
myCompositeOption = helpers.mkCompositeOption "Description of my composite option" {
|
||||||
|
|
||||||
|
subOption1 = helpers.defaultNullOpts.mkStr "foo" "This is subOption1 which does X";
|
||||||
|
subOption2 = helpers.defaultNullOpts.mkStr "baz" "This is subOption2 which does Y";
|
||||||
|
};
|
||||||
|
...
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enabled {
|
||||||
|
option_1 = cfg.option1;
|
||||||
|
my_composite_option = with cfg.myCompositeOption;
|
||||||
|
helpers.ifNonNull' cfg.myCompositeOption {
|
||||||
|
sub_option_1 = subOption1;
|
||||||
|
sub_option_2 = subOption2;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
`mkCompositeOption` creates an option which default is `null` and which type is a `types.submodule`
|
||||||
|
with the provided options.
|
||||||
|
Because the default value for `myCompositeOption` is `null`, we have to handle this case in the
|
||||||
|
implementation part using `helpers.ifNonNull'` which is defined as:
|
||||||
|
```nix
|
||||||
|
ifNonNull' = x: y: if x == null then null else y;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
Most of the tests of nixvim consist of creating a neovim derivation with the supplied nixvim configuration, and then try to execute neovim to check for any output. All output is considered to be an error.
|
Most of the tests of nixvim consist of creating a neovim derivation with the supplied nixvim configuration, and then try to execute neovim to check for any output. All output is considered to be an error.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue