2020-05-19 00:39:54 +00:00
|
|
|
{ stdenv, symlinkJoin, lib, makeWrapper
|
2017-12-11 08:26:41 +00:00
|
|
|
, vimUtils
|
2020-10-20 10:26:39 +00:00
|
|
|
, writeText
|
2017-12-11 08:26:41 +00:00
|
|
|
, bundlerEnv, ruby
|
2018-11-07 20:38:18 +00:00
|
|
|
, nodejs
|
|
|
|
, nodePackages
|
2017-12-11 08:26:41 +00:00
|
|
|
, pythonPackages
|
|
|
|
, python3Packages
|
|
|
|
}:
|
2021-01-15 13:21:58 +00:00
|
|
|
with lib;
|
2017-12-11 08:26:41 +00:00
|
|
|
|
|
|
|
neovim:
|
|
|
|
|
|
|
|
let
|
|
|
|
wrapper = {
|
2020-10-29 08:50:26 +00:00
|
|
|
# should contain all args but the binary
|
2020-10-31 13:24:52 +00:00
|
|
|
wrapperArgs ? ""
|
2020-10-29 08:50:26 +00:00
|
|
|
, manifestRc ? null
|
|
|
|
, withPython2 ? true, python2Env ? null
|
|
|
|
, withPython3 ? true, python3Env ? null
|
2020-11-02 20:59:00 +00:00
|
|
|
, withNodeJs ? false
|
|
|
|
, rubyEnv ? null
|
2017-12-11 08:26:41 +00:00
|
|
|
, vimAlias ? false
|
|
|
|
, viAlias ? false
|
2020-10-29 08:50:26 +00:00
|
|
|
, ...
|
2017-12-11 08:26:41 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
|
2020-05-19 00:39:54 +00:00
|
|
|
# If configure != {}, we can't generate the rplugin.vim file with e.g
|
|
|
|
# NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
|
|
|
|
# the wrapper. That's why only when configure != {} (tested both here and
|
|
|
|
# when postBuild is evaluated), we call makeWrapper once to generate a
|
|
|
|
# wrapper with most arguments we need, excluding those that cause problems to
|
|
|
|
# generate rplugin.vim, but still required for the final wrapper.
|
2020-10-29 08:50:26 +00:00
|
|
|
finalMakeWrapperArgs =
|
2020-10-31 13:24:52 +00:00
|
|
|
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ] ++
|
2020-10-29 08:50:26 +00:00
|
|
|
[ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ];
|
2017-12-11 08:26:41 +00:00
|
|
|
in
|
2020-05-19 00:39:54 +00:00
|
|
|
symlinkJoin {
|
2021-01-15 13:21:58 +00:00
|
|
|
name = "neovim-${lib.getVersion neovim}";
|
2020-08-04 06:14:09 +00:00
|
|
|
# Remove the symlinks created by symlinkJoin which we need to perform
|
|
|
|
# extra actions upon
|
2020-10-29 08:50:26 +00:00
|
|
|
postBuild = lib.optionalString stdenv.isLinux ''
|
2020-08-04 06:14:09 +00:00
|
|
|
rm $out/share/applications/nvim.desktop
|
2017-12-11 08:26:41 +00:00
|
|
|
substitute ${neovim}/share/applications/nvim.desktop $out/share/applications/nvim.desktop \
|
|
|
|
--replace 'Name=Neovim' 'Name=WrappedNeovim'
|
|
|
|
''
|
2020-10-29 08:50:26 +00:00
|
|
|
+ optionalString withPython2 ''
|
|
|
|
makeWrapper ${python2Env}/bin/python $out/bin/nvim-python --unset PYTHONPATH
|
2020-05-19 00:39:54 +00:00
|
|
|
''
|
|
|
|
+ optionalString withPython3 ''
|
2018-07-11 15:05:51 +00:00
|
|
|
makeWrapper ${python3Env}/bin/python3 $out/bin/nvim-python3 --unset PYTHONPATH
|
2020-05-19 00:39:54 +00:00
|
|
|
''
|
2020-11-02 20:59:00 +00:00
|
|
|
+ optionalString (rubyEnv != null) ''
|
2018-12-30 19:27:52 +00:00
|
|
|
ln -s ${rubyEnv}/bin/neovim-ruby-host $out/bin/nvim-ruby
|
2020-05-19 00:39:54 +00:00
|
|
|
''
|
|
|
|
+ optionalString withNodeJs ''
|
2020-08-12 12:37:20 +00:00
|
|
|
ln -s ${nodePackages.neovim}/bin/neovim-node-host $out/bin/nvim-node
|
2020-05-19 00:39:54 +00:00
|
|
|
''
|
|
|
|
+ optionalString vimAlias ''
|
2018-12-30 19:27:52 +00:00
|
|
|
ln -s $out/bin/nvim $out/bin/vim
|
2020-05-19 00:39:54 +00:00
|
|
|
''
|
|
|
|
+ optionalString viAlias ''
|
2018-12-30 19:27:52 +00:00
|
|
|
ln -s $out/bin/nvim $out/bin/vi
|
2020-05-19 00:39:54 +00:00
|
|
|
''
|
2020-10-29 08:50:26 +00:00
|
|
|
+ optionalString (manifestRc != null) (let
|
|
|
|
manifestWrapperArgs =
|
2020-10-31 13:24:52 +00:00
|
|
|
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ];
|
2020-10-29 08:50:26 +00:00
|
|
|
in ''
|
2018-12-30 19:37:44 +00:00
|
|
|
echo "Generating remote plugin manifest"
|
|
|
|
export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
|
2020-10-31 13:24:52 +00:00
|
|
|
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgs}
|
2020-10-29 08:50:26 +00:00
|
|
|
|
2020-02-21 18:01:37 +00:00
|
|
|
# Some plugins assume that the home directory is accessible for
|
|
|
|
# initializing caches, temporary files, etc. Even if the plugin isn't
|
|
|
|
# actively used, it may throw an error as soon as Neovim is launched
|
|
|
|
# (e.g., inside an autoload script), causing manifest generation to
|
|
|
|
# fail. Therefore, let's create a fake home directory before generating
|
|
|
|
# the manifest, just to satisfy the needs of these plugins.
|
|
|
|
#
|
|
|
|
# See https://github.com/Yggdroot/LeaderF/blob/v1.21/autoload/lfMru.vim#L10
|
|
|
|
# for an example of this behavior.
|
|
|
|
export HOME="$(mktemp -d)"
|
2018-12-30 19:37:44 +00:00
|
|
|
# Launch neovim with a vimrc file containing only the generated plugin
|
|
|
|
# code. Pass various flags to disable temp file generation
|
|
|
|
# (swap/viminfo) and redirect errors to stderr.
|
|
|
|
# Only display the log on error since it will contain a few normally
|
|
|
|
# irrelevant messages.
|
2020-10-29 08:50:26 +00:00
|
|
|
if ! $out/bin/nvim-wrapper \
|
|
|
|
-u ${writeText "manifest.vim" manifestRc} \
|
2018-12-30 19:37:44 +00:00
|
|
|
-i NONE -n \
|
|
|
|
-E -V1rplugins.log -s \
|
|
|
|
+UpdateRemotePlugins +quit! > outfile 2>&1; then
|
|
|
|
cat outfile
|
|
|
|
echo -e "\nGenerating rplugin.vim failed!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-10-29 08:50:26 +00:00
|
|
|
rm "${placeholder "out"}/bin/nvim-wrapper"
|
|
|
|
'')
|
|
|
|
+ ''
|
|
|
|
rm $out/bin/nvim
|
2020-10-31 13:24:52 +00:00
|
|
|
makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgs}
|
2018-12-30 19:27:52 +00:00
|
|
|
'';
|
2017-12-11 08:26:41 +00:00
|
|
|
|
2020-05-19 00:39:54 +00:00
|
|
|
paths = [ neovim ];
|
|
|
|
|
2017-12-11 08:26:41 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2021-02-07 09:17:39 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-10-29 08:50:26 +00:00
|
|
|
passthru = { unwrapped = neovim; };
|
2017-12-11 08:26:41 +00:00
|
|
|
|
|
|
|
meta = neovim.meta // {
|
2020-05-19 00:39:54 +00:00
|
|
|
# To prevent builds on hydra
|
2017-12-11 08:26:41 +00:00
|
|
|
hydraPlatforms = [];
|
|
|
|
# prefer wrapper over the package
|
|
|
|
priority = (neovim.meta.priority or 0) - 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.makeOverridable wrapper
|