Add vPlug option to modules.

This commit is contained in:
Kevin Baensch 2024-11-28 22:53:41 +01:00
parent bd20996cf1
commit ca7310c274
Signed by: derped
GPG key ID: C0F1D326C7626543
5 changed files with 47 additions and 15 deletions

View file

@ -2,6 +2,12 @@
let let
mkOption = lib.mkOption; mkOption = lib.mkOption;
types = lib.types; 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 = ( keyBind = (
{ ... }: { ... }:
{ {
@ -44,6 +50,7 @@ let
nullOr (oneOf [ nullOr (oneOf [
path path
package package
vPlugFunctionType
]); ]);
default = null; default = null;
description = ''A vim plugin package or a path pointing to a local plugin.''; description = ''A vim plugin package or a path pointing to a local plugin.'';
@ -92,9 +99,12 @@ let
type = type =
with types; with types;
nullOr ( nullOr (
listOf (oneOf [ (oneOf [
str vPlugFunctionType
package (listOf (oneOf [
str
package
]))
]) ])
); );
default = null; default = null;
@ -212,6 +222,11 @@ in
default = pkgs.neovim-unwrapped; default = pkgs.neovim-unwrapped;
description = ''The neovim-unwrapped package to use.''; 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 { luaRcContent = mkOption {
type = types.str; type = types.str;
default = ""; default = "";

View file

@ -15,7 +15,7 @@ in
_module.check = lib.mkDefault false; _module.check = lib.mkDefault false;
home.packages = [ home.packages = [
(wrapNeovimLazy cfg.package { (wrapNeovimLazy cfg.package {
inherit (cfg) luaRcContent lazyConfig lazyPlugins; inherit (cfg) luaRcContent lazyConfig lazyPlugins vPlug;
}) })
]; ];
}; };

View file

@ -15,7 +15,7 @@ in
_module.check = lib.mkDefault false; _module.check = lib.mkDefault false;
environment.systemPackages = [ environment.systemPackages = [
(wrapNeovimLazy cfg.package { (wrapNeovimLazy cfg.package {
inherit (cfg) luaRcContent lazyConfig lazyPlugins; inherit (cfg) luaRcContent lazyConfig lazyPlugins vPlug;
}) })
]; ];
}; };

View file

@ -75,6 +75,9 @@ let
- plugin (set) - plugin (set)
Type: Type:
pluginWrapper :: (Lambda -> String) -> Set
pluginWrapper :: (Lambda -> Derivation) -> Set
pluginWrapper :: (Lambda -> Set) -> Set
pluginWrapper :: String -> Set pluginWrapper :: String -> Set
pluginWrapper :: Derivation -> Set pluginWrapper :: Derivation -> Set
pluginWrapper :: Set -> Set pluginWrapper :: Set -> Set
@ -84,10 +87,12 @@ let
if (builtins.isString pluginOrPackage) then if (builtins.isString pluginOrPackage) then
{ short = pluginOrPackage; } { short = pluginOrPackage; }
else if else if
assert (lib.isDerivation pluginOrPackage || builtins.isAttrs pluginOrPackage); assert (builtins.isAttrs pluginOrPackage || builtins.isFunction pluginOrPackage);
(lib.isDerivation pluginOrPackage) (lib.isDerivation pluginOrPackage || builtins.isFunction pluginOrPackage)
then then
{ dir = pluginOrPackage; } {
dir = pluginOrPackage;
}
else else
pluginOrPackage; pluginOrPackage;
@ -112,20 +117,29 @@ let
if (builtins.isNull val) then val else fn val; if (builtins.isNull val) then val else fn val;
# Wrap function arguments in function so they are inserted as is when parsed. # Wrap function arguments in function so they are inserted as is when parsed.
stringLiteral = value: if (builtins.isString value) then (_: value) else value; stringLiteral = value: if (builtins.isString value) then (_: value) else value;
resolvePlugin = value: if (builtins.isFunction value) then value vPlug else value;
in in
lib.pipe plugin [ 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:
plugin plugin
// { // {
__posArgs = runIfSet lib.flatten "short"; __posArgs = runIfSet lib.flatten "short";
#if (builtins.isNull short) then short else [ short ];
name = getName plugin; name = getName plugin;
enabled = runIfSet stringLiteral "enabled"; enabled = runIfSet stringLiteral "enabled";
cond = runIfSet stringLiteral "cond"; cond = runIfSet stringLiteral "cond";
dependencies = runIfSet (map (
pluginOrPackage: getName (pluginWrapper pluginOrPackage)
)) "dependencies";
init = runIfSet stringLiteral "init"; init = runIfSet stringLiteral "init";
opts = runIfSet stringLiteral "opts"; opts = runIfSet stringLiteral "opts";
config = runIfSet stringLiteral "config"; config = runIfSet stringLiteral "config";

View file

@ -10,6 +10,7 @@
callPackage, callPackage,
neovimUtils, neovimUtils,
vimUtils, vimUtils,
vimPlugins,
perl, perl,
lndir, lndir,
lazyUtils, lazyUtils,
@ -40,6 +41,7 @@ let
luaRcContent ? "", luaRcContent ? "",
lazyPlugins ? [ ], lazyPlugins ? [ ],
lazyConfig ? { }, lazyConfig ? { },
vPlug ? vimPlugins,
... ...
}: }:
assert assert
@ -49,11 +51,12 @@ let
stdenv.mkDerivation ( stdenv.mkDerivation (
finalAttrs: finalAttrs:
let let
lazyUtilsOverride = lazyUtils.override { inherit vPlug; };
rcContent = # lua rcContent = # lua
'' ''
${luaRcContent} ${luaRcContent}
vim.opt.rtp:prepend("${lazyUtils.lazyPluginsJoin { inherit lazyConfig lazyPlugins; }}") vim.opt.rtp:prepend("${lazyUtilsOverride.lazyPluginsJoin { inherit lazyConfig lazyPlugins; }}")
require("lazyWrapper") require("lazyWrapper")
'' ''
+ lib.optionalString (!isNull neovimRcContent) '' + lib.optionalString (!isNull neovimRcContent) ''
@ -118,7 +121,7 @@ let
withPython3 withPython3
withPerl withPerl
; ;
inherit providerLuaRc lazyPlugins lazyConfig; inherit providerLuaRc lazyConfig;
inherit python3Env rubyEnv; inherit python3Env rubyEnv;
withRuby = rubyEnv != null; withRuby = rubyEnv != null;
inherit wrapperArgs generatedWrapperArgs; inherit wrapperArgs generatedWrapperArgs;
@ -210,7 +213,7 @@ let
lndir lndir
]; ];
passthru = { passthru = {
inherit providerLuaRc lazyPlugins lazyConfig; inherit providerLuaRc lazyConfig;
unwrapped = neovim-unwrapped; unwrapped = neovim-unwrapped;
initRc = neovimRcContent; initRc = neovimRcContent;