nixeovim/modules/plugin.nix

81 lines
1.8 KiB
Nix
Raw Normal View History

2024-04-26 02:08:23 +03:00
{ lib, pkgs, nix2lua, ... }:
let
pluginOpts = ({ name, config, ... }: {
options = with lib; with types; {
name = mkOption {
type = str;
};
varName = mkOption {
type = str;
# TODO: add validation
};
package = mkPackageOption pkgs.vimPlugins name { };
isDependency = mkOption {
type = bool;
default = false;
};
beforeSetup = mkOption {
type = listOf attrs;
default = [ ];
};
setupFnName = mkOption {
type = str;
default = "setup";
};
setupSettings = mkOption {
type = nullOr attrs;
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;
varName = lib.mkDefault (builtins.replaceStrings [ "-" "/" ] [ "_" "_" ] config.name);
genConfig = with nix2lua; lib.mkIf (!config.isDependency) (lib.flatten [
(local (set config.varName (require config.name)))
config.beforeSetup
(lib.optional (config.setupSettings != null)
(pipe1 (var config.varName) (call config.setupFnName config.setupSettings))
)
config.afterSetup
config.extra
]);
luaConfig = with nix2lua; toLua (spaceBetween config.genConfig);
};
});
in
{
options.plugin = with lib; with types; mkOption {
type = attrsOf (submodule pluginOpts);
default = { };
};
}