2020-05-19 01:39:54 +01:00
|
|
|
{ stdenv, symlinkJoin, lib, makeWrapper
|
2020-10-20 11:26:39 +01:00
|
|
|
, writeText
|
2017-12-11 08:26:41 +00:00
|
|
|
, bundlerEnv, ruby
|
2018-11-07 20:38:18 +00:00
|
|
|
, nodejs
|
|
|
|
, nodePackages
|
2021-12-01 09:15:46 +00:00
|
|
|
, python3
|
2017-12-11 08:26:41 +00:00
|
|
|
, python3Packages
|
2021-06-07 23:52:17 +01:00
|
|
|
, callPackage
|
2017-12-11 08:26:41 +00:00
|
|
|
}:
|
2021-01-15 13:21:58 +00:00
|
|
|
with lib;
|
2017-12-11 08:26:41 +00:00
|
|
|
|
|
|
|
neovim:
|
|
|
|
|
|
|
|
let
|
|
|
|
wrapper = {
|
2021-05-21 11:44:02 +01:00
|
|
|
extraName ? ""
|
2021-05-25 21:37:57 +01:00
|
|
|
# should contain all args but the binary. Can be either a string or list
|
|
|
|
, wrapperArgs ? []
|
2020-10-29 08:50:26 +00:00
|
|
|
, manifestRc ? null
|
2021-05-01 01:29:59 +01:00
|
|
|
, withPython2 ? false
|
2021-12-01 09:15:46 +00:00
|
|
|
, withPython3 ? true, python3Env ? python3
|
2020-11-02 20:59:00 +00:00
|
|
|
, withNodeJs ? false
|
|
|
|
, rubyEnv ? null
|
2017-12-11 08:26:41 +00:00
|
|
|
, vimAlias ? false
|
|
|
|
, viAlias ? false
|
2021-05-25 21:37:57 +01: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 22:44:43 +01:00
|
|
|
, neovimRcContent ? ""
|
2020-10-29 08:50:26 +00:00
|
|
|
, ...
|
2021-05-25 21:37:57 +01:00
|
|
|
}@args:
|
2017-12-11 08:26:41 +00:00
|
|
|
let
|
|
|
|
|
2021-05-25 21:37:57 +01:00
|
|
|
wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
|
|
|
|
|
2021-05-28 22:44:43 +01: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 08:26:41 +00:00
|
|
|
in
|
2021-05-01 01:29:59 +01:00
|
|
|
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
|
|
|
|
|
2020-05-19 01:39:54 +01:00
|
|
|
symlinkJoin {
|
2021-05-21 11:44:02 +01:00
|
|
|
name = "neovim-${lib.getVersion neovim}${extraName}";
|
2020-08-04 07:14:09 +01: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 07:14:09 +01: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-05-19 01:39:54 +01:00
|
|
|
+ optionalString withPython3 ''
|
2021-12-01 09:15:46 +00:00
|
|
|
makeWrapper ${python3Env.interpreter} $out/bin/nvim-python3 --unset PYTHONPATH
|
2020-05-19 01:39:54 +01: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 01:39:54 +01:00
|
|
|
''
|
|
|
|
+ optionalString withNodeJs ''
|
2020-08-12 13:37:20 +01:00
|
|
|
ln -s ${nodePackages.neovim}/bin/neovim-node-host $out/bin/nvim-node
|
2020-05-19 01:39:54 +01:00
|
|
|
''
|
|
|
|
+ optionalString vimAlias ''
|
2018-12-30 19:27:52 +00:00
|
|
|
ln -s $out/bin/nvim $out/bin/vim
|
2020-05-19 01:39:54 +01:00
|
|
|
''
|
|
|
|
+ optionalString viAlias ''
|
2018-12-30 19:27:52 +00:00
|
|
|
ln -s $out/bin/nvim $out/bin/vi
|
2020-05-19 01:39:54 +01: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
|
2021-05-25 21:37:57 +01:00
|
|
|
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgsStr}
|
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
|
2021-05-30 23:05:51 +01:00
|
|
|
touch $out/rplugin.vim
|
2021-05-25 21:37:57 +01:00
|
|
|
makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr}
|
2018-12-30 19:27:52 +00:00
|
|
|
'';
|
2017-12-11 08:26:41 +00:00
|
|
|
|
2020-05-19 01:39:54 +01:00
|
|
|
paths = [ neovim ];
|
|
|
|
|
2017-12-11 08:26:41 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2021-02-07 09:17:39 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-05-28 22:44:43 +01:00
|
|
|
passthru = {
|
|
|
|
unwrapped = neovim;
|
|
|
|
initRc = neovimRcContent;
|
2021-06-07 23:52:17 +01:00
|
|
|
|
|
|
|
tests = callPackage ./tests.nix {
|
|
|
|
};
|
2021-05-28 22:44:43 +01:00
|
|
|
};
|
2017-12-11 08:26:41 +00:00
|
|
|
|
|
|
|
meta = neovim.meta // {
|
2020-05-19 01:39:54 +01: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
|