2024-07-28 22:30:11 +01:00
|
|
|
{ lib, helpers }:
|
2024-05-05 19:39:35 +02:00
|
|
|
with 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 = {
|
|
|
|
extraOptions = mkOption {
|
2024-05-05 19:39:35 +02:00
|
|
|
default = { };
|
2024-01-25 16:15:55 +01:00
|
|
|
type = with types; attrsOf anything;
|
|
|
|
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,
|
|
|
|
# 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-07-06 12:32:54 +01:00
|
|
|
installPackage ? 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};
|
|
|
|
opt = options.${namespace}.${name};
|
|
|
|
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
|
|
|
inherit description;
|
|
|
|
url = args.url or opt.package.default.meta.homepage;
|
|
|
|
path = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
options.${namespace}.${name} =
|
|
|
|
{
|
|
|
|
enable = mkEnableOption originalName;
|
|
|
|
package =
|
|
|
|
if lib.isOption package then
|
|
|
|
package
|
|
|
|
else
|
|
|
|
lib.mkPackageOption pkgs originalName {
|
|
|
|
default =
|
|
|
|
if builtins.isList package then
|
|
|
|
package
|
|
|
|
else
|
|
|
|
[
|
|
|
|
"vimPlugins"
|
|
|
|
package
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// optionalAttrs hasSettings {
|
|
|
|
settings = helpers.mkSettingsOption {
|
|
|
|
description = settingsDescription;
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// extraOptions;
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
|
|
|
|
inherit extraPackages;
|
|
|
|
}
|
|
|
|
(optionalAttrs callSetup {
|
|
|
|
${extraConfigNamespace} = ''
|
|
|
|
require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
|
|
|
|
(extraConfig cfg)
|
|
|
|
]);
|
|
|
|
};
|
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-05-05 19:39:35 +02:00
|
|
|
++ (optional deprecateExtraOptions (
|
|
|
|
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
|
|
|
|
))
|
2024-09-01 09:39:25 +01:00
|
|
|
++ (nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
|
2024-05-05 19:39:35 +02:00
|
|
|
};
|
2024-01-25 16:15:55 +01:00
|
|
|
}
|