diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index fd8e8bb..ca5c614 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -65,10 +65,27 @@ # type= str; # } + # Non-lz.n options + package = mkOption { type = pluginType; + description = "Plugin package"; }; + setupModule = mkOption { + type = nullOr str; + description = "Lua module to run setup function on."; + default = null; + }; + + setupOpts = mkOption { + type = submodule {freeformType = attrsOf anything;}; + description = "Options to pass to the setup function"; + default = {}; + }; + + # lz.n options + before = mkOption { type = nullOr luaInline; description = "Code to run before plugin is loaded"; diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 749a320..5e25939 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -3,15 +3,29 @@ config, ... }: let + inherit (builtins) toJSON; inherit (lib.modules) mkIf; inherit (lib.attrsets) mapAttrsToList; + inherit (lib.generators) mkLuaInline; + inherit (lib.strings) optionalString; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.lazy; - toLuaLznSpec = name: plugin: - (removeAttrs plugin ["package"]) - // {"@1" = name;}; + toLuaLznSpec = name: spec: + (removeAttrs spec ["package" "setupModule" "setupOpts"]) + // { + "@1" = name; + after = mkLuaInline '' + function() + ${ + optionalString (spec.setupModule != null) + "require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})" + } + ${optionalString (spec.after != null) spec.after} + end + ''; + }; lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; in { config.vim = mkIf cfg.enable {