diff options
author | Matthieu Coudron <teto@users.noreply.github.com> | 2022-06-19 14:18:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-19 14:18:16 +0200 |
commit | ce505a39845b93e48f125ededeaaec6f597df43f (patch) | |
tree | aa20f405dd2b51ce097bbd76ee3d7c9876544f34 /pkgs/applications/editors/neovim | |
parent | 849bf88af107eeb0135433fa6f577e6f4efe36a2 (diff) | |
download | nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.tar nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.tar.gz nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.tar.bz2 nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.tar.lz nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.tar.xz nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.tar.zst nixlib-ce505a39845b93e48f125ededeaaec6f597df43f.zip |
vimPlugins: use lua derivation if it exists (#178180)
Neovim plugins are now more often than not written in lua. One advantage of the lua ecosystem over vim's is the existence of luarocks and the rockspec format, which allows to specify a package dependencies formally. I would like more neovim plugins to have a formal description, "rockspec" being the current candidate. This MR allows to use nix lua packages as neovim plugins, so as to enjoy every benefit that rockspecs bring: - dependdency discovery - ability to run test suite - luarocks versioning - rockspec metadata the vim update.py script will check if an attribute with the vim plugin pname exists in lua51Packages. If it does, it uses buildNeovimPluginFrom2Nix on it, which modifies the luarocks config to do an almost flat install (luarocks will install the package in the lua folder instead of share/5.1/lua etc). It also calls toVimPlugin on it to get all the vim plugin niceties. The list of packages that could benefit from this is available at https://luarocks.org/labels/neovim but I hope it grows.
Diffstat (limited to 'pkgs/applications/editors/neovim')
-rw-r--r-- | pkgs/applications/editors/neovim/build-neovim-plugin.nix | 35 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/utils.nix | 7 |
2 files changed, 42 insertions, 0 deletions
diff --git a/pkgs/applications/editors/neovim/build-neovim-plugin.nix b/pkgs/applications/editors/neovim/build-neovim-plugin.nix new file mode 100644 index 000000000000..cb69b5ecacdb --- /dev/null +++ b/pkgs/applications/editors/neovim/build-neovim-plugin.nix @@ -0,0 +1,35 @@ +{ lib +, stdenv +, buildVimPluginFrom2Nix +, buildLuarocksPackage +, lua51Packages +, toVimPlugin +}: +let + # sanitizeDerivationName + normalizeName = lib.replaceStrings [ "." ] [ "-" ]; +in + + # function to create vim plugin from lua packages that are already packaged in + # luaPackages + { + # the lua attribute name that matches this vim plugin. Both should be equal + # in the majority of cases but we make it possible to have different attribute names + luaAttr ? (normalizeName attrs.pname) + , ... + }@attrs: + let + originalLuaDrv = lua51Packages.${luaAttr}; + luaDrv = lua51Packages.lib.overrideLuarocks originalLuaDrv (drv: { + extraConfig = '' + -- to create a flat hierarchy + lua_modules_path = "lua" + ''; + }); + finalDrv = toVimPlugin (luaDrv.overrideAttrs(oa: { + nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ + lua51Packages.luarocksMoveDataFolder + ]; + })); + in + finalDrv diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index ee0abb582891..16b19f63d2d3 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -1,4 +1,6 @@ { lib +, buildLuarocksPackage +, callPackage , vimUtils , nodejs , neovim-unwrapped @@ -184,4 +186,9 @@ in { inherit makeNeovimConfig; inherit legacyWrapper; + + buildNeovimPluginFrom2Nix = callPackage ./build-neovim-plugin.nix { + inherit (vimUtils) buildVimPluginFrom2Nix toVimPlugin; + inherit buildLuarocksPackage; + }; } |