diff --git a/lib/types/default.nix b/lib/types/default.nix index 6d5777d..bfaa38d 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -4,6 +4,6 @@ typesLanguage = import ./languages.nix {inherit lib;}; in { inherit (typesDag) dagOf; - inherit (typesPlugin) pluginsOpt; + inherit (typesPlugin) pluginsOpt extraPluginType; inherit (typesLanguage) diagnostics mkGrammarOption; } diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index aed65f4..47b9ab2 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -90,15 +90,37 @@ with lib; let "copilot-cmp" ]; # You can either use the name of the plugin or a package. - pluginsType = with types; - listOf ( - nullOr ( - either - (enum availablePlugins) - package - ) + pluginType = with types; + nullOr ( + either + package + (enum availablePlugins) ); + + pluginsType = types.listOf pluginType; + + extraPluginType = with types; + submodule { + options = { + package = mkOption { + type = pluginType; + }; + after = mkOption { + type = listOf str; + default = []; + description = "Setup this plugin after the following ones."; + }; + setup = mkOption { + type = lines; + default = ""; + description = "Lua code to run during setup."; + example = "require('aerial').setup {}"; + }; + }; + }; in { + inherit extraPluginType; + pluginsOpt = { description, default ? [], diff --git a/modules/core/default.nix b/modules/core/default.nix index 9261caf..fd097ef 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -158,6 +158,27 @@ in { description = "List of plugins to optionally load"; }; + extraPlugins = mkOption { + type = types.attrsOf nvim.types.extraPluginType; + default = {}; + description = '' + List of plugins and related config. + Note that these are setup after builtin plugins. + ''; + example = literalExpression '' + with pkgs.vimPlugins; { + aerial = { + package = aerial-nvim; + setup = "require('aerial').setup {}"; + }; + harpoon = { + package = harpoon; + setup = "require('harpoon').setup {}"; + after = ["aerial"]; + }; + }''; + }; + globals = mkOption { default = {}; description = "Set containing global variable values"; @@ -297,6 +318,7 @@ in { result; in { vim = { + startPlugins = map (x: x.package) (attrValues cfg.extraPlugins); configRC = { globalsScript = nvim.dag.entryAnywhere (concatStringsSep "\n" globalsScript); @@ -314,6 +336,27 @@ in { in nvim.dag.entryAfter ["globalsScript"] luaConfig; + extraPluginConfigs = let + mkSection = r: '' + -- SECTION: ${r.name} + ${r.data} + ''; + mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r))); + extraPluginsDag = mapAttrs (_: { + after, + setup, + ... + }: + nvim.dag.entryAfter after setup) + cfg.extraPlugins; + pluginConfig = resolveDag { + name = "extra plugins config"; + dag = extraPluginsDag; + inherit mapResult; + }; + in + nvim.dag.entryAfter ["luaScript"] pluginConfig; + # This is probably not the right way to set the config. I'm not sure how it should look like. mappings = let maps = [