lazy: add setupOpts support

This commit is contained in:
Pei Yang Ching 2024-07-24 12:52:47 +02:00
parent b10c525ffe
commit 5c105b8182
2 changed files with 34 additions and 3 deletions

View file

@ -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";

View file

@ -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 {