Commit da6e66c2 authored by teto's avatar teto
Browse files

neovim: rely exclusively on evaltime deps

Neovim currently resolves its lua dependencies at buildtime in the wrapper, which causes some trouble as it's difficult to debug or replicate the result outside without rebuilding the wrapper.
This change makes lua dependencies available at evaltime. 
We can thus build a luaEnv to avoid building a long LUA_PATH which can help with runtime perf.

The drawback is that we now need to engrave in nix the default LUA_PATH for the various lua interpreters. 
This is what I had initially tried to avoid but the tradeoff proved annoying.
As far as neovim is concerned, we only care about the lua 5.1 and luajit interpreters whose defaults only slightly differ for cpath IIRC. 
So it should mostly transparent except for one or two plugins in which case we can update "getLuaPath" on a per interpreter basis.
parent 41f80e21
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -252,6 +252,11 @@

- `wrapNeovimUnstable` now sets provider-related configuration in its generated config rather than as wrapper arguments. It should not affect configuration unless you set `wrapRc` to false or are using the `legacyWrapper`.

- neovim lua dependencies are now set in the generated init.lua instead of
  modifying LUA_PATH in the wrapper. Commands run pre-vimrc via `nvim --cmd
  "require'LUA_MODULE'"` may
  not find their lua dependencies anymore. Use `nvim -c "lua require'LUA_MODULE'"` instead to run these commands after loading `init.lua`.

- We now use the upstream wrapper script for Gradle, supporting both the `JAVA_HOME` and `GRADLE_OPTS` environment variables.

- the `autossh-ng` NixOS module was introduced as a simpler alternative to the existing `autossh` module.
+1 −1
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ pkgs.lib.recurseIntoAttrs rec {
  # check that bringing in one plugin with lua deps makes those deps visible from wrapper
  # for instance luasnip has a dependency on jsregexp
  can_require_transitive_deps = runTest nvim-with-luasnip ''
    ${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e +quitall!
    ${nvim-with-luasnip}/bin/nvim -i NONE -c "lua require'jsregexp'" -e +quitall!
  '';

  inherit nvim_with_rocks_nvim;
+5 −12
Original line number Diff line number Diff line
@@ -107,9 +107,11 @@ let
        packpathDirs.myNeovimPackages = vimPackageInfo.vimPackage;
        finalPackdir = neovimUtils.packDir packpathDirs;

        luaDeps = extraLuaPackages lua.pkgs ++ vimPackageInfo.luaDependencies;

        luaPathLuaRc =
          let
            luaEnv = lua.withPackages (lp: extraLuaPackages lp ++ vimPackageInfo.luaDependencies);
            luaEnv = lua.withPackages (_: luaDeps);

            # getLuaPath / getLuaCPath are not interpreter dependant at the moment and might thus cause
            # errors between luajit/Puc lua
@@ -122,7 +124,7 @@ let
          '';

        rcContent = lib.concatStringsSep "\n" (
          lib.optional (extraLuaPackages lua.pkgs != [ ]) luaPathLuaRc
          lib.optional (luaDeps != [ ]) luaPathLuaRc
          ++ [ providerLuaRc ]
          ++ lib.optional (luaRcContent != "") luaRcContent
          ++ lib.optional (neovimRcContent' != "") ''
@@ -327,16 +329,7 @@ let
            rm $out/bin/nvim
            touch $out/rplugin.vim

            echo "Looking for lua dependencies..."
            source ${lua}/nix-support/utils.sh

            _addToLuaPath "${finalPackdir}"

            echo "LUA_PATH towards the end of packdir: $LUA_PATH"

            makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr} \
                --prefix LUA_PATH ';' "$LUA_PATH" \
                --prefix LUA_CPATH ';' "$LUA_CPATH"
            makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr}
          '';

        buildPhase = ''