nix-community.nixvim/lib/neovim-plugin.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.3 KiB
Nix
Raw Normal View History

2024-07-28 22:30:11 +01:00
{ lib, helpers }:
with lib;
{
# TODO: DEPRECATED: use the `settings` option instead
extraOptionsOptions = {
extraOptions = mkOption {
default = { };
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.
'';
};
};
mkNeovimPlugin =
config:
{
name,
maintainers,
url ? defaultPackage.meta.homepage,
imports ? [ ],
description ? null,
# deprecations
deprecateExtraOptions ? false,
optionsRenamedToSettings ? [ ],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage,
settingsOptions ? { },
settingsExample ? null,
settingsDescription ? "Options provided to the `require('${luaName}')${setup}` function.",
hasSettings ? true,
extraOptions ? { },
# config
luaName ? name,
setup ? ".setup",
extraConfig ? cfg: { },
extraPlugins ? [ ],
extraPackages ? [ ],
callSetup ? true,
installPackage ? true,
}:
let
namespace = if isColorscheme then "colorschemes" else "plugins";
in
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description url;
path = [
namespace
name
];
2024-05-05 19:39:35 +02:00
};
};
imports =
let
basePluginPath = [
namespace
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
imports
++ (optional deprecateExtraOptions (
mkRenamedOptionModule (basePluginPath ++ [ "extraOptions" ]) settingsPath
))
++ (map (
option:
let
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
2024-07-28 22:30:11 +01:00
optionPathSnakeCase = map helpers.toSnakeCase optionPath;
in
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
) optionsRenamedToSettings);
options.${namespace}.${name} =
{
enable = mkEnableOption originalName;
2024-07-28 22:30:11 +01:00
package = helpers.mkPluginPackageOption originalName defaultPackage;
}
// optionalAttrs hasSettings {
2024-07-28 22:30:11 +01:00
settings = helpers.mkSettingsOption {
description = settingsDescription;
options = settingsOptions;
example = settingsExample;
};
}
// extraOptions;
config =
let
cfg = config.${namespace}.${name};
extraConfigNamespace = if isColorscheme then "extraConfigLuaPre" else "extraConfigLua";
in
mkIf cfg.enable (mkMerge [
{
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
inherit extraPackages;
}
(optionalAttrs callSetup {
${extraConfigNamespace} = ''
2024-07-28 22:30:11 +01:00
require('${luaName}')${setup}(${optionalString (cfg ? settings) (helpers.toLuaObject cfg.settings)})
'';
})
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
(extraConfig cfg)
]);
};
}