2020-05-19 02:39:54 +02:00
|
|
|
{ stdenv, symlinkJoin, lib, makeWrapper
|
2020-10-20 12:26:39 +02:00
|
|
|
, writeText
|
2017-12-11 09:26:41 +01:00
|
|
|
, bundlerEnv, ruby
|
2018-11-07 21:38:18 +01:00
|
|
|
, nodejs
|
|
|
|
, nodePackages
|
2017-12-11 09:26:41 +01:00
|
|
|
, python3Packages
|
2021-06-08 00:52:17 +02:00
|
|
|
, callPackage
|
2017-12-11 09:26:41 +01:00
|
|
|
}:
|
2021-01-15 14:21:58 +01:00
|
|
|
with lib;
|
2017-12-11 09:26:41 +01:00
|
|
|
|
|
|
|
neovim:
|
|
|
|
|
|
|
|
let
|
|
|
|
wrapper = {
|
2021-05-21 12:44:02 +02:00
|
|
|
extraName ? ""
|
2021-05-25 22:37:57 +02:00
|
|
|
# should contain all args but the binary. Can be either a string or list
|
|
|
|
, wrapperArgs ? []
|
2020-10-29 09:50:26 +01:00
|
|
|
, manifestRc ? null
|
2021-05-01 02:29:59 +02:00
|
|
|
, withPython2 ? false
|
2020-10-29 09:50:26 +01:00
|
|
|
, withPython3 ? true, python3Env ? null
|
2020-11-02 21:59:00 +01:00
|
|
|
, withNodeJs ? false
|
|
|
|
, rubyEnv ? null
|
2017-12-11 09:26:41 +01:00
|
|
|
, vimAlias ? false
|
|
|
|
, viAlias ? false
|
2021-05-25 22:37:57 +02:00
|
|
|
|
|
|
|
# additional argument not generated by makeNeovimConfig
|
|
|
|
# it will append "-u <customRc>" to the wrapped arguments
|
|
|
|
# set to false if you want to control where to save the generated config
|
|
|
|
# (e.g., in ~/.config/init.vim or project/.nvimrc)
|
|
|
|
, wrapRc ? true
|
2021-05-28 23:44:43 +02:00
|
|
|
, neovimRcContent ? ""
|
2020-10-29 09:50:26 +01:00
|
|
|
, ...
|
2021-05-25 22:37:57 +02:00
|
|
|
}@args:
|
2017-12-11 09:26:41 +01:00
|
|
|
let
|
|
|
|
|
2021-05-25 22:37:57 +02:00
|
|
|
wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
|
|
|
|
|
2021-05-28 23:44:43 +02: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.
|
|
|
|
finalMakeWrapperArgs =
|
|
|
|
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
|
|
|
|
++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
|
|
|
|
++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ]
|
|
|
|
;
|
2017-12-11 09:26:41 +01:00
|
|
|
in
|
2021-05-01 02:29:59 +02:00
|
|
|
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
|
|
|
|
|
2020-05-19 02:39:54 +02:00
|
|
|
symlinkJoin {
|
2021-05-21 12:44:02 +02:00
|
|
|
name = "neovim-${lib.getVersion neovim}${extraName}";
|
2020-08-04 08:14:09 +02:00
|
|
|
# Remove the symlinks created by symlinkJoin which we need to perform
|
|
|
|
# extra actions upon
|
2020-10-29 09:50:26 +01:00
|
|
|
postBuild = lib.optionalString stdenv.isLinux ''
|
2020-08-04 08:14:09 +02:00
|
|
|
rm $out/share/applications/nvim.desktop
|
2017-12-11 09:26:41 +01:00
|
|
|
substitute ${neovim}/share/applications/nvim.desktop $out/share/applications/nvim.desktop \
|
|
|
|
--replace 'Name=Neovim' 'Name=WrappedNeovim'
|
|
|
|
''
|
2020-05-19 02:39:54 +02:00
|
|
|
+ optionalString withPython3 ''
|
2018-07-11 17:05:51 +02:00
|
|
|
makeWrapper ${python3Env}/bin/python3 $out/bin/nvim-python3 --unset PYTHONPATH
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
2020-11-02 21:59:00 +01:00
|
|
|
+ optionalString (rubyEnv != null) ''
|
2018-12-30 20:27:52 +01:00
|
|
|
ln -s ${rubyEnv}/bin/neovim-ruby-host $out/bin/nvim-ruby
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
|
|
|
+ optionalString withNodeJs ''
|
2020-08-12 14:37:20 +02:00
|
|
|
ln -s ${nodePackages.neovim}/bin/neovim-node-host $out/bin/nvim-node
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
|
|
|
+ optionalString vimAlias ''
|
2018-12-30 20:27:52 +01:00
|
|
|
ln -s $out/bin/nvim $out/bin/vim
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
|
|
|
+ optionalString viAlias ''
|
2018-12-30 20:27:52 +01:00
|
|
|
ln -s $out/bin/nvim $out/bin/vi
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
2020-10-29 09:50:26 +01:00
|
|
|
+ optionalString (manifestRc != null) (let
|
|
|
|
manifestWrapperArgs =
|
2020-10-31 14:24:52 +01:00
|
|
|
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ];
|
2020-10-29 09:50:26 +01:00
|
|
|
in ''
|
2018-12-30 20:37:44 +01:00
|
|
|
echo "Generating remote plugin manifest"
|
|
|
|
export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
|
2021-05-25 22:37:57 +02:00
|
|
|
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgsStr}
|
2020-10-29 09:50:26 +01:00
|
|
|
|
2020-02-21 19:01:37 +01: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 20:37:44 +01: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 09:50:26 +01:00
|
|
|
if ! $out/bin/nvim-wrapper \
|
|
|
|
-u ${writeText "manifest.vim" manifestRc} \
|
2018-12-30 20:37:44 +01: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 09:50:26 +01:00
|
|
|
rm "${placeholder "out"}/bin/nvim-wrapper"
|
|
|
|
'')
|
|
|
|
+ ''
|
|
|
|
rm $out/bin/nvim
|
2021-05-31 00:05:51 +02:00
|
|
|
touch $out/rplugin.vim
|
2021-05-25 22:37:57 +02:00
|
|
|
makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr}
|
2018-12-30 20:27:52 +01:00
|
|
|
'';
|
2017-12-11 09:26:41 +01:00
|
|
|
|
2020-05-19 02:39:54 +02:00
|
|
|
paths = [ neovim ];
|
|
|
|
|
2017-12-11 09:26:41 +01:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2021-02-07 10:17:39 +01:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-05-28 23:44:43 +02:00
|
|
|
passthru = {
|
|
|
|
unwrapped = neovim;
|
|
|
|
initRc = neovimRcContent;
|
2021-06-08 00:52:17 +02:00
|
|
|
|
|
|
|
tests = callPackage ./tests.nix {
|
|
|
|
};
|
2021-05-28 23:44:43 +02:00
|
|
|
};
|
2017-12-11 09:26:41 +01:00
|
|
|
|
|
|
|
meta = neovim.meta // {
|
2020-05-19 02:39:54 +02:00
|
|
|
# To prevent builds on hydra
|
2017-12-11 09:26:41 +01:00
|
|
|
hydraPlatforms = [];
|
|
|
|
# prefer wrapper over the package
|
|
|
|
priority = (neovim.meta.priority or 0) - 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.makeOverridable wrapper
|