From ca7310c274b6a41de4ebf250ad02c5b62be822cd Mon Sep 17 00:00:00 2001 From: derped Date: Thu, 28 Nov 2024 22:53:41 +0100 Subject: [PATCH] Add vPlug option to modules. --- modules/nvim-lazy/default.nix | 21 ++++++++++++++++++--- modules/nvim-lazy/homeManager.nix | 2 +- modules/nvim-lazy/nixosModule.nix | 2 +- pkgs/lazyUtils.nix | 28 +++++++++++++++++++++------- pkgs/wrapper.nix | 9 ++++++--- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/modules/nvim-lazy/default.nix b/modules/nvim-lazy/default.nix index 59c402d..e1a6f96 100644 --- a/modules/nvim-lazy/default.nix +++ b/modules/nvim-lazy/default.nix @@ -2,6 +2,12 @@ let mkOption = lib.mkOption; types = lib.types; + vPlugFunctionType = types.mkOptionType { + name = "vPlugFunction"; + description = "function taking vimPlugins and returning plugin or plugin list"; + check = builtins.isFunction; + merge = lib.mergeOneOption; + }; keyBind = ( { ... }: { @@ -44,6 +50,7 @@ let nullOr (oneOf [ path package + vPlugFunctionType ]); default = null; description = ''A vim plugin package or a path pointing to a local plugin.''; @@ -92,9 +99,12 @@ let type = with types; nullOr ( - listOf (oneOf [ - str - package + (oneOf [ + vPlugFunctionType + (listOf (oneOf [ + str + package + ])) ]) ); default = null; @@ -212,6 +222,11 @@ in default = pkgs.neovim-unwrapped; description = ''The neovim-unwrapped package to use.''; }; + vPlug = mkOption { + type = with types; lazyAttrsOf anything; + default = pkgs.vimPlugins; + description = ''The vimPlugins attrs to use.''; + }; luaRcContent = mkOption { type = types.str; default = ""; diff --git a/modules/nvim-lazy/homeManager.nix b/modules/nvim-lazy/homeManager.nix index 09b58db..cc5a290 100644 --- a/modules/nvim-lazy/homeManager.nix +++ b/modules/nvim-lazy/homeManager.nix @@ -15,7 +15,7 @@ in _module.check = lib.mkDefault false; home.packages = [ (wrapNeovimLazy cfg.package { - inherit (cfg) luaRcContent lazyConfig lazyPlugins; + inherit (cfg) luaRcContent lazyConfig lazyPlugins vPlug; }) ]; }; diff --git a/modules/nvim-lazy/nixosModule.nix b/modules/nvim-lazy/nixosModule.nix index 41ec6e6..d6df827 100644 --- a/modules/nvim-lazy/nixosModule.nix +++ b/modules/nvim-lazy/nixosModule.nix @@ -15,7 +15,7 @@ in _module.check = lib.mkDefault false; environment.systemPackages = [ (wrapNeovimLazy cfg.package { - inherit (cfg) luaRcContent lazyConfig lazyPlugins; + inherit (cfg) luaRcContent lazyConfig lazyPlugins vPlug; }) ]; }; diff --git a/pkgs/lazyUtils.nix b/pkgs/lazyUtils.nix index 4b9dd22..3d074ef 100644 --- a/pkgs/lazyUtils.nix +++ b/pkgs/lazyUtils.nix @@ -75,6 +75,9 @@ let - plugin (set) Type: + pluginWrapper :: (Lambda -> String) -> Set + pluginWrapper :: (Lambda -> Derivation) -> Set + pluginWrapper :: (Lambda -> Set) -> Set pluginWrapper :: String -> Set pluginWrapper :: Derivation -> Set pluginWrapper :: Set -> Set @@ -84,10 +87,12 @@ let if (builtins.isString pluginOrPackage) then { short = pluginOrPackage; } else if - assert (lib.isDerivation pluginOrPackage || builtins.isAttrs pluginOrPackage); - (lib.isDerivation pluginOrPackage) + assert (builtins.isAttrs pluginOrPackage || builtins.isFunction pluginOrPackage); + (lib.isDerivation pluginOrPackage || builtins.isFunction pluginOrPackage) then - { dir = pluginOrPackage; } + { + dir = pluginOrPackage; + } else pluginOrPackage; @@ -112,20 +117,29 @@ let if (builtins.isNull val) then val else fn val; # Wrap function arguments in function so they are inserted as is when parsed. stringLiteral = value: if (builtins.isString value) then (_: value) else value; + resolvePlugin = value: if (builtins.isFunction value) then value vPlug else value; in lib.pipe plugin [ + # Resolve dir and dependencies first so getName can resolve names + ( + plugin: + plugin + // { + dir = runIfSet resolvePlugin "dir"; + dependencies = runIfSet ( + pluginListFn: + (map (pluginOrPackage: getName (pluginWrapper pluginOrPackage))) (resolvePlugin pluginListFn) + ) "dependencies"; + } + ) ( plugin: plugin // { __posArgs = runIfSet lib.flatten "short"; - #if (builtins.isNull short) then short else [ short ]; name = getName plugin; enabled = runIfSet stringLiteral "enabled"; cond = runIfSet stringLiteral "cond"; - dependencies = runIfSet (map ( - pluginOrPackage: getName (pluginWrapper pluginOrPackage) - )) "dependencies"; init = runIfSet stringLiteral "init"; opts = runIfSet stringLiteral "opts"; config = runIfSet stringLiteral "config"; diff --git a/pkgs/wrapper.nix b/pkgs/wrapper.nix index 7d13e54..13898fd 100644 --- a/pkgs/wrapper.nix +++ b/pkgs/wrapper.nix @@ -10,6 +10,7 @@ callPackage, neovimUtils, vimUtils, + vimPlugins, perl, lndir, lazyUtils, @@ -40,6 +41,7 @@ let luaRcContent ? "", lazyPlugins ? [ ], lazyConfig ? { }, + vPlug ? vimPlugins, ... }: assert @@ -49,11 +51,12 @@ let stdenv.mkDerivation ( finalAttrs: let + lazyUtilsOverride = lazyUtils.override { inherit vPlug; }; rcContent = # lua '' ${luaRcContent} - vim.opt.rtp:prepend("${lazyUtils.lazyPluginsJoin { inherit lazyConfig lazyPlugins; }}") + vim.opt.rtp:prepend("${lazyUtilsOverride.lazyPluginsJoin { inherit lazyConfig lazyPlugins; }}") require("lazyWrapper") '' + lib.optionalString (!isNull neovimRcContent) '' @@ -118,7 +121,7 @@ let withPython3 withPerl ; - inherit providerLuaRc lazyPlugins lazyConfig; + inherit providerLuaRc lazyConfig; inherit python3Env rubyEnv; withRuby = rubyEnv != null; inherit wrapperArgs generatedWrapperArgs; @@ -210,7 +213,7 @@ let lndir ]; passthru = { - inherit providerLuaRc lazyPlugins lazyConfig; + inherit providerLuaRc lazyConfig; unwrapped = neovim-unwrapped; initRc = neovimRcContent;