helpers/mkPlugin: add extraConfig option

This commit is contained in:
Gaetan Lepage 2024-01-07 11:01:13 +01:00 committed by Gaétan Lepage
parent 563ab0660b
commit 97fb6d6a29
3 changed files with 39 additions and 7 deletions

View file

@ -322,16 +322,27 @@ with lib; rec {
...
}: let
cfg = config.plugins.${name};
description =
if description is null
then name
else description;
# TODO support nested options!
pluginOptions = mapAttrs (k: v: v.option) options;
pluginOptions =
mapAttrs
(
optName: opt:
opt.option
)
options;
globals =
mapAttrs'
(name: opt: {
(optName: opt: {
name = globalPrefix + opt.global;
value =
if cfg.${name} != null
then opt.value cfg.${name}
else null;
ifNonNull' cfg.${optName}
(opt.value cfg.${optName});
})
options;
# does this evaluate package?
@ -341,11 +352,31 @@ with lib; rec {
else {
package = mkPackageOption name package;
};
extraConfigOption =
if (isString globalPrefix) && (globalPrefix != "")
then {
extraConfig = mkOption {
type = with types; attrsOf anything;
description = ''
The configuration options for ${name} without the '${globalPrefix}' prefix.
Example: To set '${globalPrefix}_foo_bar' to 1, write
```nix
extraConfig = {
foo_bar = true;
};
```
'';
default = {};
};
}
else {};
in {
options.plugins.${name} =
{
enable = mkEnableOption description;
}
// extraConfigOption
// packageOption
// pluginOptions;

View file

@ -13,6 +13,6 @@ in
package = pkgs.vimPlugins.vim-fugitive;
extraPackages = [pkgs.git];
# In typical tpope fashin, this plugin has no config options
# In typical tpope fashion, this plugin has no config options
options = {};
}

View file

@ -11,12 +11,13 @@ in
name = "zig";
description = "Enable zig";
package = pkgs.vimPlugins.zig-vim;
globalPrefix = "zig_";
# Possibly add option to disable Treesitter highlighting if this is installed
options = {
formatOnSave = mkDefaultOpt {
type = types.bool;
global = "zig_fmt_autosave";
global = "fmt_autosave";
description = "Run zig fmt on save";
};
};