Skip to content

Commit a07d4ce

Browse files
authored
neovim: add extraLuaPackages to wrapNeovimUnstable (NixOS#499571)
2 parents 40206fb + 7906e29 commit a07d4ce

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

doc/languages-frameworks/neovim.section.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ For instance, `sqlite-lua` needs `g:sqlite_clib_path` to be set to work. Nixpkgs
6464
- `wrapRc`: Nix, not being able to write in your `$HOME`, loads the
6565
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`.
6666
- `plugins`: A list of plugins to add to the wrapper.
67+
- `extraLuaPackages`: A function passed on to `lua.withPackages`
6768
- `withPython3`, `withNodeJs`, `withRuby` control when to enable neovim
6869
providers (see `:h provider`).
6970

@@ -90,6 +91,7 @@ wrapNeovimUnstable neovim-unwrapped {
9091
(nvim-treesitter.withPlugins (p: [ p.nix p.python ]))
9192
hex-nvim
9293
];
94+
extraLuaPackages = lp: [ lp.mpack ];
9395
withPython3 = true;
9496
withNodeJs = false;
9597
withRuby = false;

pkgs/applications/editors/neovim/tests/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,12 @@ pkgs.lib.recurseIntoAttrs rec {
348348
configure.packages.foo.start = with vimPlugins; [ deoplete-nvim ];
349349
};
350350

351-
nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig {
351+
nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" {
352352
extraLuaPackages = ps: [ ps.mpack ];
353-
customRC = ''
354-
lua require("mpack")
353+
luaRcContent = ''
354+
require("mpack")
355355
'';
356-
});
356+
};
357357

358358
nvim_with_lua_packages = runTest nvimWithLuaPackages ''
359359
${nvimWithLuaPackages}/bin/nvim -V3log.txt -i NONE --noplugin +quitall! -e

pkgs/applications/editors/neovim/wrapper.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ let
6969
# { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; }
7070
# ]
7171
plugins ? [ ],
72+
# the function you would have passed to lua.withPackages
73+
extraLuaPackages ? (_: [ ]),
7274
...
7375
}@attrs:
7476
assert
@@ -105,8 +107,23 @@ let
105107
packpathDirs.myNeovimPackages = vimPackageInfo.vimPackage;
106108
finalPackdir = neovimUtils.packDir packpathDirs;
107109

110+
luaPathLuaRc =
111+
let
112+
luaEnv = lua.withPackages extraLuaPackages;
113+
114+
# getLuaPath / getLuaCPath are not interpreter dependant at the moment and might thus cause
115+
# errors between luajit/Puc lua
116+
generatedLuaPath = lua.pkgs.getLuaPath luaEnv;
117+
generatedLuaCPath = lua.pkgs.getLuaCPath luaEnv;
118+
in
119+
''
120+
package.path = "${generatedLuaPath}".. ";" .. package.path
121+
package.cpath = "${generatedLuaCPath}".. ";" .. package.cpath
122+
'';
123+
108124
rcContent = lib.concatStringsSep "\n" (
109125
[
126+
luaPathLuaRc
110127
providerLuaRc
111128
]
112129
++ lib.optional (luaRcContent != "") luaRcContent

0 commit comments

Comments
 (0)