diff --git a/lib/helpers.nix b/lib/helpers.nix index 020c33621d..cbb5ad95c2 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -1,16 +1,21 @@ -{lib, ...}: let +{ + lib, + pkgs, + ... +}: let nixvimTypes = import ./types.nix {inherit lib nixvimOptions;}; nixvimUtils = import ./utils.nix {inherit lib;}; nixvimOptions = import ./options.nix {inherit lib nixvimTypes nixvimUtils;}; + inherit (import ./to-lua.nix {inherit lib;}) toLuaObject; in { maintainers = import ./maintainers.nix; keymaps = import ./keymap-helpers.nix {inherit lib nixvimOptions nixvimTypes;}; autocmd = import ./autocmd-helpers.nix {inherit lib nixvimOptions nixvimTypes;}; - neovim-plugin = import ./neovim-plugin.nix {inherit lib nixvimOptions;}; + neovim-plugin = import ./neovim-plugin.nix {inherit lib nixvimOptions toLuaObject;}; vim-plugin = import ./vim-plugin.nix {inherit lib nixvimOptions;}; - inherit (import ./to-lua.nix {inherit lib;}) toLuaObject; inherit nixvimTypes; + inherit toLuaObject; } // nixvimUtils // nixvimOptions diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 85441ecea8..694177657b 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -1,8 +1,9 @@ { lib, nixvimOptions, + toLuaObject, }: -with lib; { +with lib; rec { mkSettingsOption = { pluginName ? null, options ? {}, @@ -27,4 +28,57 @@ with lib; { ''; }; }; + + mkNeovimPlugin = config: { + name, + namespace ? "plugins", + maintainers, + imports ? [], + # options + originalName ? name, + defaultPackage, + settingsOptions ? {}, + settingsExample ? null, + extraOptions ? {}, + # config + luaName ? name, + extraConfig ? cfg: {}, + extraPlugins ? [], + extraPackages ? [], + }: { + meta.maintainers = maintainers; + + inherit imports; + + options.${namespace}.${name} = + { + enable = mkEnableOption originalName; + + package = nixvimOptions.mkPackageOption originalName defaultPackage; + + settings = mkSettingsOption { + pluginName = name; + options = settingsOptions; + example = settingsExample; + }; + } + // extraOptions; + + config = let + cfg = config.${namespace}.${name}; + in + mkIf cfg.enable ( + mkMerge [ + { + extraPlugins = [cfg.package] ++ extraPlugins; + inherit extraPackages; + + extraConfigLua = '' + require('${luaName}').setup(${toLuaObject cfg.settings}) + ''; + } + (extraConfig cfg) + ] + ); + }; }