2024-09-29 14:41:41 +01:00
|
|
|
{ lib }:
|
2024-06-21 15:52:58 +01:00
|
|
|
{
|
2024-02-12 16:13:44 +01:00
|
|
|
# TODO: DEPRECATED: use the `settings` option instead
|
2024-01-25 16:15:55 +01:00
|
|
|
extraOptionsOptions = {
|
2024-08-30 14:49:20 -05:00
|
|
|
extraOptions = lib.mkOption {
|
2024-05-05 19:39:35 +02:00
|
|
|
default = { };
|
2024-08-30 14:49:20 -05:00
|
|
|
type = with lib.types; attrsOf anything;
|
2024-01-25 16:15:55 +01:00
|
|
|
description = ''
|
|
|
|
These attributes will be added to the table parameter for the setup function.
|
2024-02-11 12:51:34 +00:00
|
|
|
Typically, it can override NixVim's default settings.
|
2024-01-25 16:15:55 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-01-31 08:51:39 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
mkNeovimPlugin =
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
maintainers,
|
2024-09-01 09:39:25 +01:00
|
|
|
url ? throw "default",
|
2024-05-05 19:39:35 +02:00
|
|
|
imports ? [ ],
|
|
|
|
description ? null,
|
|
|
|
# deprecations
|
|
|
|
deprecateExtraOptions ? false,
|
|
|
|
optionsRenamedToSettings ? [ ],
|
|
|
|
# colorscheme
|
|
|
|
isColorscheme ? false,
|
|
|
|
colorscheme ? name,
|
2024-08-19 23:31:57 +02:00
|
|
|
# luaConfig
|
|
|
|
configLocation ? if isColorscheme then "extraConfigLuaPre" else "extraConfigLua",
|
2024-12-09 20:40:02 +01:00
|
|
|
# Some plugin are not supposed to generate lua configuration code.
|
|
|
|
# For example, they might just be configured through some other mean, like global variables
|
|
|
|
hasLuaConfig ? true,
|
2024-05-05 19:39:35 +02:00
|
|
|
# options
|
|
|
|
originalName ? name,
|
2024-09-01 09:39:25 +01:00
|
|
|
# Can be a string, a list of strings, or a module option:
|
|
|
|
# - A string will be intrpreted as `pkgs.vimPlugins.${package}`
|
|
|
|
# - A list will be interpreted as a "pkgs path", e.g. `pkgs.${elem1}.${elem2}.${etc...}`
|
|
|
|
# - An option will be used as-is, but should be built using `lib.mkPackageOption`
|
2024-09-02 14:05:11 +01:00
|
|
|
# Defaults to `name`, i.e. `pkgs.vimPlugins.${name}`
|
|
|
|
package ? name,
|
2024-05-05 19:39:35 +02:00
|
|
|
settingsOptions ? { },
|
|
|
|
settingsExample ? null,
|
2024-06-21 15:52:58 +01:00
|
|
|
settingsDescription ? "Options provided to the `require('${luaName}')${setup}` function.",
|
2024-06-25 22:17:45 +01:00
|
|
|
hasSettings ? true,
|
2024-05-05 19:39:35 +02:00
|
|
|
extraOptions ? { },
|
|
|
|
# config
|
|
|
|
luaName ? name,
|
2024-06-21 15:52:58 +01:00
|
|
|
setup ? ".setup",
|
2024-05-05 19:39:35 +02:00
|
|
|
extraConfig ? cfg: { },
|
|
|
|
extraPlugins ? [ ],
|
|
|
|
extraPackages ? [ ],
|
|
|
|
callSetup ? true,
|
2024-09-01 09:39:25 +01:00
|
|
|
}@args:
|
2024-05-05 19:39:35 +02:00
|
|
|
let
|
|
|
|
namespace = if isColorscheme then "colorschemes" else "plugins";
|
2024-09-01 09:39:25 +01:00
|
|
|
|
|
|
|
module =
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
options,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.${namespace}.${name};
|
2024-11-19 13:55:33 +00:00
|
|
|
opts = options.${namespace}.${name};
|
2024-08-19 23:31:57 +02:00
|
|
|
|
|
|
|
setupCode = ''
|
|
|
|
require('${luaName}')${setup}(${
|
2024-09-29 14:41:41 +01:00
|
|
|
lib.optionalString (cfg ? settings) (lib.nixvim.toLuaObject cfg.settings)
|
2024-08-19 23:31:57 +02:00
|
|
|
})
|
|
|
|
'';
|
|
|
|
|
|
|
|
setLuaConfig = lib.setAttrByPath (lib.toList configLocation);
|
2024-09-01 09:39:25 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
|
|
|
inherit description;
|
2024-11-19 13:55:33 +00:00
|
|
|
url = args.url or opts.package.default.meta.homepage;
|
2024-09-01 09:39:25 +01:00
|
|
|
path = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
options.${namespace}.${name} =
|
|
|
|
{
|
2024-08-30 14:49:20 -05:00
|
|
|
enable = lib.mkEnableOption originalName;
|
2024-12-02 13:50:48 -06:00
|
|
|
lazyLoad = lib.nixvim.mkLazyLoadOption originalName;
|
2024-09-01 09:39:25 +01:00
|
|
|
package =
|
|
|
|
if lib.isOption package then
|
|
|
|
package
|
|
|
|
else
|
|
|
|
lib.mkPackageOption pkgs originalName {
|
|
|
|
default =
|
|
|
|
if builtins.isList package then
|
|
|
|
package
|
|
|
|
else
|
|
|
|
[
|
|
|
|
"vimPlugins"
|
|
|
|
package
|
|
|
|
];
|
|
|
|
};
|
2024-11-15 17:28:47 +00:00
|
|
|
packageDecorator = lib.mkOption {
|
|
|
|
type = lib.types.functionTo lib.types.package;
|
|
|
|
default = lib.id;
|
|
|
|
defaultText = lib.literalExpression "x: x";
|
|
|
|
description = ''
|
|
|
|
Additional transformations to apply to the final installed package.
|
|
|
|
The result of these transformations is **not** visible in the `package` option's value.
|
|
|
|
'';
|
|
|
|
internal = true;
|
|
|
|
};
|
2024-09-01 09:39:25 +01:00
|
|
|
}
|
2024-08-30 14:49:20 -05:00
|
|
|
// lib.optionalAttrs hasSettings {
|
2024-09-29 14:41:41 +01:00
|
|
|
settings = lib.nixvim.mkSettingsOption {
|
2024-09-01 09:39:25 +01:00
|
|
|
description = settingsDescription;
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
|
|
|
};
|
|
|
|
}
|
2024-12-09 20:40:02 +01:00
|
|
|
// lib.optionalAttrs hasLuaConfig {
|
2024-08-19 23:31:57 +02:00
|
|
|
luaConfig = lib.mkOption {
|
2024-09-27 08:07:20 +01:00
|
|
|
type = lib.types.pluginLuaConfig;
|
2024-08-19 23:31:57 +02:00
|
|
|
default = { };
|
|
|
|
description = "The plugin's lua configuration";
|
|
|
|
};
|
|
|
|
}
|
2024-09-01 09:39:25 +01:00
|
|
|
// extraOptions;
|
|
|
|
|
2024-08-19 23:31:57 +02:00
|
|
|
config =
|
|
|
|
assert lib.assertMsg (
|
2024-12-09 20:40:02 +01:00
|
|
|
callSetup -> hasLuaConfig
|
|
|
|
) "This plugin is supposed to call the `setup()` function but has `hasLuaConfig` set to false";
|
2024-08-19 23:31:57 +02:00
|
|
|
lib.mkIf cfg.enable (
|
|
|
|
lib.mkMerge (
|
|
|
|
[
|
|
|
|
{
|
|
|
|
inherit extraPackages;
|
2024-11-15 17:28:47 +00:00
|
|
|
extraPlugins = extraPlugins ++ [
|
|
|
|
(cfg.packageDecorator cfg.package)
|
|
|
|
];
|
2024-08-19 23:31:57 +02:00
|
|
|
}
|
2024-12-09 20:40:02 +01:00
|
|
|
|
2024-08-19 23:31:57 +02:00
|
|
|
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
|
|
|
|
colorscheme = lib.mkDefault colorscheme;
|
2024-08-30 14:49:20 -05:00
|
|
|
})
|
2024-12-09 20:40:02 +01:00
|
|
|
|
|
|
|
# Apply any additional configuration added to `extraConfig`
|
2024-11-19 13:55:33 +00:00
|
|
|
(lib.optionalAttrs (args ? extraConfig) (
|
|
|
|
lib.nixvim.modules.applyExtraConfig {
|
|
|
|
inherit extraConfig cfg opts;
|
|
|
|
}
|
|
|
|
))
|
2024-08-19 23:31:57 +02:00
|
|
|
]
|
2024-12-09 20:40:02 +01:00
|
|
|
# Lua configuration code generation
|
|
|
|
++ (lib.optionals hasLuaConfig [
|
|
|
|
|
|
|
|
# Add the plugin setup code `require('foo').setup(...)` to the lua configuration
|
2024-08-19 23:31:57 +02:00
|
|
|
(lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; })
|
2024-12-09 20:40:02 +01:00
|
|
|
|
2024-12-02 13:50:48 -06:00
|
|
|
# Write the lua configuration `luaConfig.content` to the config file when lazy loading is not enabled
|
2024-10-11 21:34:28 -05:00
|
|
|
(lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content))
|
2024-12-02 13:50:48 -06:00
|
|
|
|
|
|
|
# When lazy loading is enabled for this plugin, route its configuration to the enabled provider
|
|
|
|
(lib.mkIf cfg.lazyLoad.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = (isColorscheme && colorscheme != null) || cfg.lazyLoad.settings != { };
|
|
|
|
message = "You have enabled lazy loading for ${originalName} but have not provided any configuration.";
|
|
|
|
}
|
|
|
|
];
|
2024-12-02 12:23:45 -06:00
|
|
|
plugins.lz-n = {
|
|
|
|
plugins = [
|
2024-12-02 13:50:48 -06:00
|
|
|
(
|
|
|
|
{
|
|
|
|
__unkeyed-1 = originalName;
|
2024-12-05 21:58:33 -06:00
|
|
|
# Use provided after, otherwise fallback to normal function wrapped lua content
|
2024-12-02 13:50:48 -06:00
|
|
|
after =
|
2024-12-05 21:58:33 -06:00
|
|
|
let
|
|
|
|
after = cfg.lazyLoad.settings.after or null;
|
|
|
|
default = "function()\n " + cfg.luaConfig.content + " \nend";
|
|
|
|
in
|
|
|
|
if (lib.isString after || lib.types.rawLua.check after) then after else default;
|
|
|
|
colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme);
|
2024-12-02 13:50:48 -06:00
|
|
|
}
|
|
|
|
// lib.removeAttrs cfg.lazyLoad.settings [
|
|
|
|
"after"
|
|
|
|
"colorscheme"
|
|
|
|
]
|
|
|
|
)
|
2024-12-02 12:23:45 -06:00
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
])
|
2024-08-19 23:31:57 +02:00
|
|
|
)
|
|
|
|
);
|
2024-09-01 09:39:25 +01:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports =
|
|
|
|
let
|
|
|
|
basePluginPath = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
settingsPath = basePluginPath ++ [ "settings" ];
|
|
|
|
in
|
|
|
|
imports
|
2024-09-01 09:39:25 +01:00
|
|
|
++ [ module ]
|
2024-08-30 14:49:20 -05:00
|
|
|
++ (lib.optional deprecateExtraOptions (
|
|
|
|
lib.mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
|
2024-05-05 19:39:35 +02:00
|
|
|
))
|
2024-08-30 14:49:20 -05:00
|
|
|
++ (lib.nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2024-01-25 16:15:55 +01:00
|
|
|
}
|