From 2319ee082c3152ceaf74b10cdd3f0d531719198f Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 18 Jul 2023 22:21:36 +0300 Subject: [PATCH 1/5] dev: custom type for extraPlugin module --- lib/types/default.nix | 2 +- lib/types/plugins.nix | 19 +++++++++++++++++++ modules/core/default.nix | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) 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 111fd8c..6ee0d46 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -97,7 +97,26 @@ with lib; let package ) ); + + extraPluginType = with types; + submodule { + options = { + package = mkOption { + type = pluginsType; + }; + dependencies = mkOption { + type = listOf str; + default = []; + }; + setup = mkOption { + type = lines; + default = ""; + }; + }; + }; in { + inherit extraPluginType; + pluginsOpt = { description, default ? [], diff --git a/modules/core/default.nix b/modules/core/default.nix index 9261caf..48769ec 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -158,6 +158,11 @@ in { description = "List of plugins to optionally load"; }; + extraPlugins = mkOption { + type = types.attrsOf nvim.types.extraPluginType; + default = {}; + }; + globals = mkOption { default = {}; description = "Set containing global variable values"; From 2167481cc2096e6b712f7977bedf0afc522374fe Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 21 Jul 2023 15:25:40 +0200 Subject: [PATCH 2/5] implement extraPluginConfigs --- modules/core/default.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/core/default.nix b/modules/core/default.nix index 48769ec..5d87c9c 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -302,6 +302,7 @@ in { result; in { vim = { + startPlugins = concatMap (x: x.package) (attrValues cfg.extraPlugins); configRC = { globalsScript = nvim.dag.entryAnywhere (concatStringsSep "\n" globalsScript); @@ -319,6 +320,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 (_: { + dependencies, + setup, + ... + }: + nvim.dag.entryAfter dependencies 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 = [ From afec39f3d98d3486d38a6f58d28df15ba6754fa2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 21 Jul 2023 15:30:03 +0200 Subject: [PATCH 3/5] make extraPluginType singular instead of a list --- lib/types/plugins.nix | 16 ++++++++-------- modules/core/default.nix | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 6ee0d46..f4dde65 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -89,20 +89,20 @@ with lib; let "nvim-dap-ui" ]; # 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 = pluginsType; + type = pluginType; }; dependencies = mkOption { type = listOf str; diff --git a/modules/core/default.nix b/modules/core/default.nix index 5d87c9c..1515ca0 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -302,7 +302,7 @@ in { result; in { vim = { - startPlugins = concatMap (x: x.package) (attrValues cfg.extraPlugins); + startPlugins = map (x: x.package) (attrValues cfg.extraPlugins); configRC = { globalsScript = nvim.dag.entryAnywhere (concatStringsSep "\n" globalsScript); From 5981cd14f8637492b55648258c1514387f5ff802 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 26 Jul 2023 15:27:08 +0200 Subject: [PATCH 4/5] rename for clarity --- lib/types/plugins.nix | 2 +- modules/core/default.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index f4dde65..c5b6e54 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -104,7 +104,7 @@ with lib; let package = mkOption { type = pluginType; }; - dependencies = mkOption { + after = mkOption { type = listOf str; default = []; }; diff --git a/modules/core/default.nix b/modules/core/default.nix index 1515ca0..bab8803 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -327,11 +327,11 @@ in { ''; mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r))); extraPluginsDag = mapAttrs (_: { - dependencies, + after, setup, ... }: - nvim.dag.entryAfter dependencies setup) + nvim.dag.entryAfter after setup) cfg.extraPlugins; pluginConfig = resolveDag { name = "extra plugins config"; From 8d72e28c4d61e6efd891d8771b79a2bc5db4e5c5 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 26 Jul 2023 15:27:34 +0200 Subject: [PATCH 5/5] add descriptions for extraPlugins --- lib/types/plugins.nix | 3 +++ modules/core/default.nix | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index c5b6e54..7db0019 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -107,10 +107,13 @@ with lib; let 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 {}"; }; }; }; diff --git a/modules/core/default.nix b/modules/core/default.nix index bab8803..fd097ef 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -161,6 +161,22 @@ in { 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 {