diff --git a/doc/languages-frameworks/neovim.section.md b/doc/languages-frameworks/neovim.section.md index 6834819c3c40..3b0db2c03629 100644 --- a/doc/languages-frameworks/neovim.section.md +++ b/doc/languages-frameworks/neovim.section.md @@ -64,6 +64,7 @@ For instance, `sqlite-lua` needs `g:sqlite_clib_path` to be set to work. Nixpkgs - `wrapRc`: Nix, not being able to write in your `$HOME`, loads the generated Neovim configuration via the `$VIMINIT` environment variable, i.e. : `export VIMINIT='lua dofile("/nix/store/…-init.lua")'`. This has side effects like preventing Neovim from sourcing your `init.lua` in `$XDG_CONFIG_HOME/nvim` (see bullet 7 of [`:help startup`](https://neovim.io/doc/user/starting.html#startup) in Neovim). Disable it if you want to generate your own wrapper. You can still reuse the generated vimscript init code via `neovim.passthru.initRc`. - `plugins`: A list of plugins to add to the wrapper. +- `extraLuaPackages`: A function passed on to `lua.withPackages` - `withPython3`, `withNodeJs`, `withRuby` control when to enable neovim providers (see `:h provider`). @@ -90,6 +91,7 @@ wrapNeovimUnstable neovim-unwrapped { (nvim-treesitter.withPlugins (p: [ p.nix p.python ])) hex-nvim ]; + extraLuaPackages = lp: [ lp.mpack ]; withPython3 = true; withNodeJs = false; withRuby = false; diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index 8e1b79cb3036..086bb10a0509 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -348,12 +348,12 @@ pkgs.lib.recurseIntoAttrs rec { configure.packages.foo.start = with vimPlugins; [ deoplete-nvim ]; }; - nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig { + nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" { extraLuaPackages = ps: [ ps.mpack ]; - customRC = '' - lua require("mpack") + luaRcContent = '' + require("mpack") ''; - }); + }; nvim_with_lua_packages = runTest nvimWithLuaPackages '' ${nvimWithLuaPackages}/bin/nvim -V3log.txt -i NONE --noplugin +quitall! -e diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index c3ec13eec25d..fe461dd08977 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -69,6 +69,8 @@ let # { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; } # ] plugins ? [ ], + # the function you would have passed to lua.withPackages + extraLuaPackages ? (_: [ ]), ... }@attrs: assert @@ -105,8 +107,23 @@ let packpathDirs.myNeovimPackages = vimPackageInfo.vimPackage; finalPackdir = neovimUtils.packDir packpathDirs; + luaPathLuaRc = + let + luaEnv = lua.withPackages extraLuaPackages; + + # getLuaPath / getLuaCPath are not interpreter dependant at the moment and might thus cause + # errors between luajit/Puc lua + generatedLuaPath = lua.pkgs.getLuaPath luaEnv; + generatedLuaCPath = lua.pkgs.getLuaCPath luaEnv; + in + '' + package.path = "${generatedLuaPath}".. ";" .. package.path + package.cpath = "${generatedLuaCPath}".. ";" .. package.cpath + ''; + rcContent = lib.concatStringsSep "\n" ( [ + luaPathLuaRc providerLuaRc ] ++ lib.optional (luaRcContent != "") luaRcContent