mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-25 02:08:40 +02:00
helpers/vim-plugin/mkVimPlugin: make use of helpers.mkSettingsOption
This commit is contained in:
parent
100876b7a3
commit
a70f580340
1 changed files with 26 additions and 17 deletions
|
@ -5,13 +5,17 @@
|
||||||
with lib; {
|
with lib; {
|
||||||
mkVimPlugin = config: {
|
mkVimPlugin = config: {
|
||||||
name,
|
name,
|
||||||
|
# options
|
||||||
description ? null,
|
description ? null,
|
||||||
package ? null,
|
package ? null,
|
||||||
extraPlugins ? [],
|
|
||||||
extraPackages ? [],
|
|
||||||
options ? {},
|
options ? {},
|
||||||
|
settingsOptions ? {},
|
||||||
|
settingsExample ? null,
|
||||||
globalPrefix ? "",
|
globalPrefix ? "",
|
||||||
addExtraConfigRenameWarning ? false,
|
addExtraConfigRenameWarning ? false,
|
||||||
|
# config
|
||||||
|
extraPlugins ? [],
|
||||||
|
extraPackages ? [],
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
cfg = config.plugins.${name};
|
cfg = config.plugins.${name};
|
||||||
|
@ -24,19 +28,23 @@ with lib; {
|
||||||
opt.option
|
opt.option
|
||||||
)
|
)
|
||||||
options;
|
options;
|
||||||
globals =
|
|
||||||
|
globalsFromOptions =
|
||||||
mapAttrs'
|
mapAttrs'
|
||||||
(optName: opt: {
|
(optName: opt: {
|
||||||
name = let
|
name =
|
||||||
optGlobal =
|
if opt.global == null
|
||||||
if opt.global == null
|
then optName
|
||||||
then optName
|
else opt.global;
|
||||||
else opt.global;
|
|
||||||
in
|
|
||||||
globalPrefix + optGlobal;
|
|
||||||
value = cfg.${optName};
|
value = cfg.${optName};
|
||||||
})
|
})
|
||||||
options;
|
options;
|
||||||
|
globalsFromSettings =
|
||||||
|
if (hasAttr "settings" cfg) && (cfg.settings != null)
|
||||||
|
then cfg.settings
|
||||||
|
else {};
|
||||||
|
globals = globalsFromOptions // globalsFromSettings;
|
||||||
|
|
||||||
# does this evaluate package?
|
# does this evaluate package?
|
||||||
packageOption =
|
packageOption =
|
||||||
if package == null
|
if package == null
|
||||||
|
@ -47,21 +55,21 @@ with lib; {
|
||||||
|
|
||||||
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
|
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
|
||||||
|
|
||||||
extraConfigOption =
|
settingsOption =
|
||||||
optionalAttrs createSettingsOption
|
optionalAttrs createSettingsOption
|
||||||
{
|
{
|
||||||
settings = mkOption {
|
settings = nixvimOptions.mkSettingsOption {
|
||||||
type = with types; attrsOf anything;
|
options = settingsOptions;
|
||||||
|
example = settingsExample;
|
||||||
description = ''
|
description = ''
|
||||||
The configuration options for ${name} without the '${globalPrefix}' prefix.
|
The configuration options for ${name} without the '${globalPrefix}' prefix.
|
||||||
Example: To set '${globalPrefix}_foo_bar' to 1, write
|
Example: To set '${globalPrefix}_foo_bar' to 1, write
|
||||||
```nix
|
```nix
|
||||||
extraConfig = {
|
settings = {
|
||||||
foo_bar = true;
|
foo_bar = true;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
'';
|
'';
|
||||||
default = {};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
|
@ -73,7 +81,7 @@ with lib; {
|
||||||
else description
|
else description
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// extraConfigOption
|
// settingsOption
|
||||||
// packageOption
|
// packageOption
|
||||||
// pluginOptions;
|
// pluginOptions;
|
||||||
|
|
||||||
|
@ -84,7 +92,8 @@ with lib; {
|
||||||
);
|
);
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
inherit extraPackages globals;
|
inherit extraPackages;
|
||||||
|
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
|
||||||
# does this evaluate package? it would not be desired to evaluate pacakge if we use another package.
|
# does this evaluate package? it would not be desired to evaluate pacakge if we use another package.
|
||||||
extraPlugins = extraPlugins ++ optional (package != null) cfg.package;
|
extraPlugins = extraPlugins ++ optional (package != null) cfg.package;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue