vimPlugins.plenary: init from lua package

This commit shows how to convert luarocks packages into (neo)vim ones.
The advantage for neovim lua plugins to register their rockspec (aka
package definition) is that the plugin can express its dependencies and
a few metadata through it.
This commit is contained in:
Matthieu Coudron 2021-08-08 16:55:24 +02:00 committed by Matthieu Coudron
parent be0b03e5a8
commit 06684792fb
6 changed files with 53 additions and 9 deletions

View file

@ -1,4 +1,4 @@
# nix name, luarocks name, server, version,luaversion,maintainers
# nix name,luarocks name,server,version,luaversion,maintainers
alt-getopt,,,,,arobyn
ansicolors,,,,,
argparse,,,,,
@ -16,6 +16,7 @@ cyrussasl,,,,,
digestif,,,,lua5_3,
dkjson,,,,,
fifo,,,,,
gitsigns.nvim,,,,lua5_1,
http,,,,,vcunat
inspect,,,,,
ldbus,,http://luarocks.org/dev,,,

1 # nix name luarocks name server version luaversion maintainers
2 alt-getopt arobyn
3 ansicolors
4 argparse
16 digestif lua5_3
17 dkjson
18 fifo
19 gitsigns.nvim lua5_1
20 http vcunat
21 inspect
22 ldbus http://luarocks.org/dev

View file

@ -1,5 +1,5 @@
# TODO check that no license information gets lost
{ callPackage, config, lib, vimUtils, vim, darwin, llvmPackages }:
{ callPackage, config, lib, vimUtils, vim, darwin, llvmPackages, luaPackages }:
let
@ -7,7 +7,15 @@ let
inherit (lib) extends;
initialPackages = self: {};
initialPackages = self: {
# Convert derivation to a vim plugin.
toVimPlugin = drv:
drv.overrideAttrs(oldAttrs: {
passthru = (oldAttrs.passthru or {}) // {
vimPlugin = true;
};
});
};
plugins = callPackage ./generated.nix {
inherit buildVimPluginFrom2Nix;
@ -22,7 +30,7 @@ let
overrides = callPackage ./overrides.nix {
inherit (darwin.apple_sdk.frameworks) Cocoa CoreFoundation CoreServices;
inherit buildVimPluginFrom2Nix;
inherit llvmPackages;
inherit llvmPackages luaPackages;
};
aliases = if (config.allowAliases or true) then (import ./aliases.nix lib) else final: prev: {};

View file

@ -86,6 +86,8 @@
, iferr
, impl
, reftools
# must be lua51Packages
, luaPackages
}:
self: super: {
@ -282,6 +284,8 @@ self: super: {
dependencies = with self; [ plenary-nvim ];
});
plenary-nvim = super.toVimPlugin(luaPackages.plenary-nvim);
gruvbox-nvim = super.gruvbox-nvim.overrideAttrs (old: {
dependencies = with self; [ lush-nvim ];
});

View file

@ -2,6 +2,7 @@
{ lib, stdenv, vim, vimPlugins, vim_configurable, buildEnv, writeText, writeScriptBin
, nix-prefetch-hg, nix-prefetch-git
, fetchFromGitHub, runtimeShell
, hasLuaModule
}:
/*
@ -186,7 +187,21 @@ let
nativeImpl = packages:
(let
link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}");
# dir is "start" or "opt"
linkLuaPlugin = plugin: packageName: dir: ''
mkdir -p $out/pack/${packageName}/${dir}/${plugin.pname}/lua
ln -sf ${plugin}/share/lua/5.1/* $out/pack/${packageName}/${dir}/${plugin.pname}/lua
ln -sf ${plugin}/${plugin.pname}-${plugin.version}-rocks/${plugin.pname}/${plugin.version}/* $out/pack/${packageName}/${dir}/${plugin.pname}/
'';
linkVimlPlugin = pluginPath: packageName: dir:
"ln -sf ${pluginPath}/${rtpPath}/* $out/pack/${packageName}/${dir}";
# (builtins.trace pluginPath )
link = pluginPath: if hasLuaModule pluginPath
then linkLuaPlugin pluginPath
else linkVimlPlugin pluginPath;
packageLinks = (packageName: {start ? [], opt ? []}:
let
# `nativeImpl` expects packages to be derivations, not strings (as
@ -199,9 +214,9 @@ let
[ "mkdir -p $out/pack/${packageName}/start" ]
# To avoid confusion, even dependencies of optional plugins are added
# to `start` (except if they are explicitly listed as optional plugins).
++ (builtins.map (link packageName "start") (lib.unique (startWithDeps ++ depsOfOptionalPlugins)))
++ (builtins.map (x: link x packageName "start") (lib.unique (startWithDeps ++ depsOfOptionalPlugins)))
++ ["mkdir -p $out/pack/${packageName}/opt"]
++ (builtins.map (link packageName "opt") opt)
++ (builtins.map (x: link x packageName "opt") opt)
);
packDir = (packages:
stdenv.mkDerivation {
@ -217,6 +232,18 @@ let
set runtimepath^=${packDir packages}
'');
/* Generates a vimrc string
packages is an attrset with {name: { start = [ vim derivations ]; opt = [ vim derivations ]; }
Example:
vimrcContent {
packages = { home-manager = { start = [vimPlugins.vim-fugitive]; opt = [];};
beforePlugins = '';
customRc = ''let mapleader = " "'';
};
*/
vimrcContent = {
packages ? null,
vam ? null,

View file

@ -32195,10 +32195,14 @@ with pkgs;
viewnior = callPackage ../applications/graphics/viewnior { };
vimUtils = callPackage ../misc/vim-plugins/vim-utils.nix { };
vimUtils = callPackage ../misc/vim-plugins/vim-utils.nix {
inherit (lua51Packages) hasLuaModule;
};
vimPlugins = recurseIntoAttrs (callPackage ../misc/vim-plugins {
llvmPackages = llvmPackages_6;
luaPackages = lua51Packages;
});
vimb-unwrapped = callPackage ../applications/networking/browsers/vimb { };

View file

@ -83,7 +83,7 @@ with self; {
};
inherit toLuaModule lua-setup-hook;
inherit toLuaModule hasLuaModule lua-setup-hook;
inherit buildLuarocksPackage buildLuaApplication;
inherit requiredLuaModules luaOlder luaAtLeast
isLua51 isLua52 isLua53 isLuaJIT lua callPackage;