2024-04-30 00:48:10 +03:00
|
|
|
{ lib, pkgs, ... }:
|
2024-04-26 02:08:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
let
|
2024-05-17 22:32:46 +03:00
|
|
|
inherit (lib.nix2lua) require requireTo var lset pipe1 call;
|
2024-05-10 01:31:47 +03:00
|
|
|
|
2024-04-26 02:08:23 +03:00
|
|
|
pluginOpts = ({ name, config, ... }: {
|
|
|
|
options = with lib; with types; {
|
2024-05-10 01:31:47 +03:00
|
|
|
enable = mkEnableOption "Enable plugin <name>" // { default = true; };
|
2024-04-26 02:08:23 +03:00
|
|
|
name = mkOption {
|
|
|
|
type = str;
|
|
|
|
};
|
2024-04-30 01:25:36 +03:00
|
|
|
extraImports = mkOption {
|
2024-05-10 01:31:47 +03:00
|
|
|
type = attrsOf (either str attrs);
|
2024-04-30 01:25:36 +03:00
|
|
|
default = { };
|
|
|
|
example = { hint = "hop.hint"; };
|
|
|
|
};
|
2024-04-26 02:08:23 +03:00
|
|
|
varName = mkOption {
|
2024-05-10 01:31:47 +03:00
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
2024-04-26 02:08:23 +03:00
|
|
|
};
|
2024-05-10 01:31:47 +03:00
|
|
|
var = mkOption {
|
|
|
|
type = attrs;
|
|
|
|
internal = true;
|
2024-04-26 02:08:23 +03:00
|
|
|
};
|
2024-05-10 01:31:47 +03:00
|
|
|
package = mkPackageOption pkgs.vimPlugins name { };
|
2024-04-26 02:08:23 +03:00
|
|
|
|
|
|
|
beforeSetup = mkOption {
|
|
|
|
type = listOf attrs;
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
setupFnName = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "setup";
|
|
|
|
};
|
|
|
|
setupSettings = mkOption {
|
2024-05-06 16:30:56 +03:00
|
|
|
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-10 01:31:47 +03:00
|
|
|
var = if config.varName != null then var config.varName else require config.name;
|
|
|
|
|
|
|
|
genConfig = with lib; mkIf config.enable (flatten [
|
2024-05-17 22:32:46 +03:00
|
|
|
(lib.optional (config.varName != null) (requireTo config.varName config.name))
|
2024-05-10 01:31:47 +03:00
|
|
|
(mapAttrsToList
|
2024-05-17 22:32:46 +03:00
|
|
|
(k: v: lset k (if builtins.isString v then require v else v))
|
2024-05-10 01:31:47 +03:00
|
|
|
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-05-10 01:31:47 +03:00
|
|
|
(pipe1
|
|
|
|
config.var
|
|
|
|
(call config.setupFnName config.setupSettings)
|
|
|
|
)
|
2024-04-26 02:08:23 +03:00
|
|
|
)
|
|
|
|
config.afterSetup
|
2024-05-10 01:31:47 +03:00
|
|
|
|
2024-04-26 02:08:23 +03:00
|
|
|
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 = { };
|
|
|
|
};
|
|
|
|
}
|