2024-01-24 22:49:29 +01:00
|
|
|
{
|
|
|
|
lib,
|
2024-01-25 15:43:06 +01:00
|
|
|
nixvimOptions,
|
2024-02-19 10:29:19 +01:00
|
|
|
nixvimUtils,
|
2024-01-24 22:49:29 +01:00
|
|
|
}:
|
|
|
|
with lib;
|
2024-02-09 14:21:22 +01:00
|
|
|
{
|
|
|
|
mkVimPlugin =
|
|
|
|
config:
|
2024-05-05 19:39:35 +02:00
|
|
|
{
|
2024-01-24 22:49:29 +01:00
|
|
|
name,
|
2024-02-20 21:20:59 +01:00
|
|
|
url ? if defaultPackage != null then defaultPackage.meta.homepage else null,
|
2024-03-04 09:35:48 +01:00
|
|
|
maintainers,
|
2024-02-13 16:35:48 +01:00
|
|
|
imports ? [ ],
|
2024-03-21 12:04:09 +01:00
|
|
|
description ? null,
|
2024-02-19 10:19:39 +01:00
|
|
|
# deprecations
|
|
|
|
deprecateExtraConfig ? false,
|
2024-02-19 10:29:19 +01:00
|
|
|
optionsRenamedToSettings ? [ ],
|
2024-03-12 22:30:45 +01:00
|
|
|
# colorscheme
|
|
|
|
isColorscheme ? false,
|
|
|
|
colorscheme ? name,
|
2024-02-12 16:13:52 +01:00
|
|
|
# options
|
2024-02-13 23:25:13 +01:00
|
|
|
originalName ? name,
|
2024-02-15 09:51:43 +01:00
|
|
|
defaultPackage ? null,
|
2024-02-12 16:13:52 +01:00
|
|
|
settingsOptions ? { },
|
|
|
|
settingsExample ? null,
|
2024-01-24 22:49:29 +01:00
|
|
|
globalPrefix ? "",
|
2024-02-13 17:05:49 +01:00
|
|
|
extraOptions ? { },
|
2024-02-12 16:13:52 +01:00
|
|
|
# config
|
2024-02-13 17:05:53 +01:00
|
|
|
extraConfig ? cfg: { },
|
2024-02-12 16:13:52 +01:00
|
|
|
extraPlugins ? [ ],
|
|
|
|
extraPackages ? [ ],
|
2024-01-24 22:49:29 +01:00
|
|
|
}:
|
|
|
|
let
|
2024-03-08 12:06:00 +01:00
|
|
|
namespace = if isColorscheme then "colorschemes" else "plugins";
|
|
|
|
|
2024-02-13 15:03:28 +01:00
|
|
|
cfg = config.${namespace}.${name};
|
2024-01-24 22:49:29 +01:00
|
|
|
|
2024-03-15 00:26:18 +01:00
|
|
|
globals = cfg.settings or { };
|
2024-02-12 16:13:52 +01:00
|
|
|
|
2024-01-24 22:49:29 +01:00
|
|
|
# does this evaluate package?
|
|
|
|
packageOption =
|
2024-02-15 09:51:43 +01:00
|
|
|
if defaultPackage == null then
|
2024-01-24 22:49:29 +01:00
|
|
|
{ }
|
|
|
|
else
|
2024-05-17 14:09:20 +02:00
|
|
|
{ package = nixvimOptions.mkPluginPackageOption name defaultPackage; };
|
2024-01-24 22:49:29 +01:00
|
|
|
|
2024-02-12 12:07:50 +01:00
|
|
|
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
|
|
|
|
|
|
|
|
settingsOption = optionalAttrs createSettingsOption {
|
2024-02-12 16:13:52 +01:00
|
|
|
settings = nixvimOptions.mkSettingsOption {
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
2024-01-24 22:49:29 +01:00
|
|
|
description = ''
|
2024-03-01 23:02:09 +01:00
|
|
|
The configuration options for **${name}** without the `${globalPrefix}` prefix.
|
|
|
|
|
2024-03-02 23:06:39 +01:00
|
|
|
Example: To set `${globalPrefix}foo_bar` to `1`, write
|
2024-01-24 22:49:29 +01:00
|
|
|
```nix
|
2024-02-12 16:13:52 +01:00
|
|
|
settings = {
|
2024-01-24 22:49:29 +01:00
|
|
|
foo_bar = true;
|
|
|
|
};
|
|
|
|
```
|
|
|
|
'';
|
|
|
|
};
|
2024-02-12 12:07:50 +01:00
|
|
|
};
|
2024-01-24 22:49:29 +01:00
|
|
|
in
|
|
|
|
{
|
2024-02-20 21:20:59 +01:00
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
2024-03-21 12:04:09 +01:00
|
|
|
inherit description name url;
|
2024-02-20 21:20:59 +01:00
|
|
|
kind = namespace;
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2024-02-20 21:20:59 +01:00
|
|
|
};
|
2024-02-13 15:03:28 +01:00
|
|
|
options.${namespace}.${name} = {
|
2024-02-13 23:25:13 +01:00
|
|
|
enable = mkEnableOption originalName;
|
2024-02-12 16:13:52 +01:00
|
|
|
} // settingsOption // packageOption // extraOptions;
|
2024-01-24 22:49:29 +01:00
|
|
|
|
2024-02-19 10:29:19 +01:00
|
|
|
imports =
|
|
|
|
let
|
|
|
|
basePluginPath = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
settingsPath = basePluginPath ++ [ "settings" ];
|
|
|
|
in
|
2024-02-13 16:35:48 +01:00
|
|
|
imports
|
2024-02-19 10:29:19 +01:00
|
|
|
++ (optional (deprecateExtraConfig && createSettingsOption) (
|
|
|
|
mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
|
|
|
|
))
|
|
|
|
++ (map (
|
|
|
|
option:
|
|
|
|
let
|
|
|
|
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
|
|
|
|
|
|
|
|
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
|
|
|
|
in
|
|
|
|
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
|
|
|
|
) optionsRenamedToSettings);
|
2024-02-12 12:07:50 +01:00
|
|
|
|
2024-02-13 17:05:53 +01:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
inherit extraPackages;
|
|
|
|
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
|
2024-03-07 19:44:13 +01:00
|
|
|
# does this evaluate package? it would not be desired to evaluate package if we use another package.
|
2024-02-15 09:51:43 +01:00
|
|
|
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
|
2024-02-13 17:05:53 +01:00
|
|
|
}
|
2024-05-28 21:22:35 +02:00
|
|
|
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
|
2024-02-13 17:05:53 +01:00
|
|
|
(extraConfig cfg)
|
|
|
|
]);
|
2024-01-24 22:49:29 +01:00
|
|
|
};
|
|
|
|
}
|