nixeovim/modules/plugin.nix

86 lines
2.0 KiB
Nix
Raw Normal View History

2024-04-30 00:48:10 +03:00
{ lib, pkgs, ... }:
2024-04-26 02:08:23 +03:00
let
pluginOpts = ({ name, config, ... }: {
options = with lib; with types; {
name = mkOption {
type = str;
};
2024-04-30 01:25:36 +03:00
extraImports = mkOption {
type = attrsOf str;
default = { };
example = { hint = "hop.hint"; };
};
2024-04-26 02:08:23 +03:00
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 (either attrs (listOf anything));
2024-04-26 02:08:23 +03:00
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;
2024-05-02 08:55:30 +03:00
varName = lib.mkDefault (builtins.replaceStrings [ "-" "/" "." ] [ "_" "_" "_" ] config.name);
2024-04-26 02:08:23 +03:00
2024-05-09 02:28:24 +03:00
genConfig = with lib; with nix2lua; mkIf (!config.isDependency) (flatten [
2024-04-26 02:08:23 +03:00
(local (set config.varName (require config.name)))
2024-05-09 02:28:24 +03:00
(mapAttrsToList (k: v: local (set k (require v))) config.extraImports)
2024-04-26 02:08:23 +03:00
config.beforeSetup
2024-05-09 02:28:24 +03:00
(optional (config.setupSettings != null)
2024-04-26 02:08:23 +03:00
(pipe1 (var config.varName) (call config.setupFnName config.setupSettings))
)
config.afterSetup
config.extra
]);
2024-04-30 00:48:10 +03:00
luaConfig = with lib.nix2lua; toLua (spaceBetween config.genConfig);
2024-04-26 02:08:23 +03:00
};
});
in
{
2024-05-09 02:28:24 +03:00
options.plugin = with lib; mkOption {
type = with types; attrsOf (submodule pluginOpts);
2024-04-26 02:08:23 +03:00
default = { };
};
}