From 06684792fb7b739f4081e21824952911d35c1bc7 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 8 Aug 2021 16:55:24 +0200 Subject: [PATCH] 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. --- maintainers/scripts/luarocks-packages.csv | 3 ++- pkgs/misc/vim-plugins/default.nix | 14 +++++++--- pkgs/misc/vim-plugins/overrides.nix | 4 +++ pkgs/misc/vim-plugins/vim-utils.nix | 33 ++++++++++++++++++++--- pkgs/top-level/all-packages.nix | 6 ++++- pkgs/top-level/lua-packages.nix | 2 +- 6 files changed, 53 insertions(+), 9 deletions(-) diff --git a/maintainers/scripts/luarocks-packages.csv b/maintainers/scripts/luarocks-packages.csv index b092a58b2d10..c5cee697c8fd 100644 --- a/maintainers/scripts/luarocks-packages.csv +++ b/maintainers/scripts/luarocks-packages.csv @@ -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,,, diff --git a/pkgs/misc/vim-plugins/default.nix b/pkgs/misc/vim-plugins/default.nix index cbc6ec7380ba..b56dced89717 100644 --- a/pkgs/misc/vim-plugins/default.nix +++ b/pkgs/misc/vim-plugins/default.nix @@ -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: {}; diff --git a/pkgs/misc/vim-plugins/overrides.nix b/pkgs/misc/vim-plugins/overrides.nix index 669ca2cb9eed..b2dd6f0f5f0d 100644 --- a/pkgs/misc/vim-plugins/overrides.nix +++ b/pkgs/misc/vim-plugins/overrides.nix @@ -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 ]; }); diff --git a/pkgs/misc/vim-plugins/vim-utils.nix b/pkgs/misc/vim-plugins/vim-utils.nix index 5ca3aef23588..ca5381c59724 100644 --- a/pkgs/misc/vim-plugins/vim-utils.nix +++ b/pkgs/misc/vim-plugins/vim-utils.nix @@ -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, diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f3273d52d553..cf4e86402b87 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { }; diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index 62ddc14ff93a..f16917a94394 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -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;