nixeovim/modules/plugin.nix
Dmitriy Pleshevskiy f3926f6365
modules/plugin: remove isDependency
do not import to local variable by default. Instead you should
set varName option.
2024-05-10 02:17:00 +03:00

97 lines
2.2 KiB
Nix

{ lib, pkgs, ... }:
let
inherit (lib.nix2lua) require var local set pipe1 call;
pluginOpts = ({ name, config, ... }: {
options = with lib; with types; {
enable = mkEnableOption "Enable plugin <name>" // { default = true; };
name = mkOption {
type = str;
};
extraImports = mkOption {
type = attrsOf (either str attrs);
default = { };
example = { hint = "hop.hint"; };
};
varName = mkOption {
type = nullOr str;
default = null;
};
var = mkOption {
type = attrs;
internal = true;
};
package = mkPackageOption pkgs.vimPlugins name { };
beforeSetup = mkOption {
type = listOf attrs;
default = [ ];
};
setupFnName = mkOption {
type = str;
default = "setup";
};
setupSettings = mkOption {
type = nullOr (either attrs (listOf anything));
default = null;
};
afterSetup = mkOption {
type = listOf attrs;
default = [ ];
};
extra = mkOption {
type = listOf attrs;
default = [ ];
};
genConfig = mkOption {
type = listOf attrs;
readOnly = true;
internal = true;
};
luaConfig = mkOption {
type = str;
readOnly = true;
internal = true;
};
};
config = {
name = lib.mkDefault name;
var = if config.varName != null then var config.varName else require config.name;
genConfig = with lib; mkIf config.enable (flatten [
(lib.optional (config.varName != null) (local (set config.varName (require config.name))))
(mapAttrsToList
(k: v: local (set k (if builtins.isString v then require v else v)))
config.extraImports
)
config.beforeSetup
(optional (config.setupSettings != null)
(pipe1
config.var
(call config.setupFnName config.setupSettings)
)
)
config.afterSetup
config.extra
]);
luaConfig = with lib.nix2lua; toLua (spaceBetween config.genConfig);
};
});
in
{
options.plugin = with lib; mkOption {
type = with types; attrsOf (submodule pluginOpts);
default = { };
};
}