2020-08-20 17:08:02 +00:00
|
|
|
{ stdenv, symlinkJoin, lib, makeWrapper
|
2020-10-20 17:27:49 +00:00
|
|
|
, writeText
|
2020-04-24 23:36:52 +00:00
|
|
|
, nodePackages
|
2021-12-06 16:07:01 +00:00
|
|
|
, python3
|
2020-04-24 23:36:52 +00:00
|
|
|
, python3Packages
|
2021-06-28 23:13:55 +00:00
|
|
|
, callPackage
|
2023-04-12 12:48:02 +00:00
|
|
|
, neovimUtils
|
|
|
|
, vimUtils
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
neovim:
|
|
|
|
|
|
|
|
let
|
|
|
|
wrapper = {
|
2021-05-28 09:39:13 +00:00
|
|
|
extraName ? ""
|
|
|
|
# should contain all args but the binary. Can be either a string or list
|
|
|
|
, wrapperArgs ? []
|
2023-04-12 12:48:02 +00:00
|
|
|
# a limited RC script used only to generate the manifest for remote plugins
|
2020-11-03 02:18:15 +00:00
|
|
|
, manifestRc ? null
|
2021-05-03 20:48:10 +00:00
|
|
|
, withPython2 ? false
|
2021-12-06 16:07:01 +00:00
|
|
|
, withPython3 ? true, python3Env ? python3
|
2020-11-03 02:18:15 +00:00
|
|
|
, withNodeJs ? false
|
|
|
|
, rubyEnv ? null
|
2020-04-24 23:36:52 +00:00
|
|
|
, vimAlias ? false
|
|
|
|
, viAlias ? false
|
2021-05-28 09:39:13 +00: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-06-28 23:13:55 +00:00
|
|
|
, neovimRcContent ? ""
|
2023-04-12 12:48:02 +00:00
|
|
|
# entry to load in packpath
|
|
|
|
, packpathDirs
|
2020-11-03 02:18:15 +00:00
|
|
|
, ...
|
2021-05-28 09:39:13 +00:00
|
|
|
}@args:
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
wrapperArgsStr = if lib.isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
|
2021-05-28 09:39:13 +00:00
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
# "--add-flags" (lib.escapeShellArgs flags)
|
|
|
|
# wrapper args used both when generating the manifest and in the final neovim executable
|
|
|
|
commonWrapperArgs = (lib.optionals (lib.isList wrapperArgs) wrapperArgs)
|
|
|
|
# vim accepts a limited number of commands so we join them all
|
|
|
|
++ [
|
|
|
|
"--add-flags" ''--cmd "lua ${providerLuaRc}"''
|
|
|
|
# (lib.intersperse "|" hostProviderViml)
|
|
|
|
] ++ lib.optionals (packpathDirs.myNeovimPackages.start != [] || packpathDirs.myNeovimPackages.opt != []) [
|
|
|
|
"--add-flags" ''--cmd "set packpath^=${vimUtils.packDir packpathDirs}"''
|
|
|
|
"--add-flags" ''--cmd "set rtp^=${vimUtils.packDir packpathDirs}"''
|
|
|
|
]
|
|
|
|
;
|
|
|
|
|
|
|
|
providerLuaRc = neovimUtils.generateProviderRc args;
|
|
|
|
# providerLuaRc = "toto";
|
|
|
|
|
2021-06-28 23:13:55 +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.
|
|
|
|
finalMakeWrapperArgs =
|
|
|
|
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
|
|
|
|
++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
|
2023-02-02 18:25:31 +00:00
|
|
|
++ lib.optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ]
|
2023-04-12 12:48:02 +00:00
|
|
|
++ commonWrapperArgs
|
2021-06-28 23:13:55 +00:00
|
|
|
;
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
2021-05-03 20:48:10 +00:00
|
|
|
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
symlinkJoin {
|
2021-05-28 09:39:13 +00:00
|
|
|
name = "neovim-${lib.getVersion neovim}${extraName}";
|
2020-08-20 17:08:02 +00:00
|
|
|
# Remove the symlinks created by symlinkJoin which we need to perform
|
|
|
|
# extra actions upon
|
2020-11-03 02:18:15 +00:00
|
|
|
postBuild = lib.optionalString stdenv.isLinux ''
|
2020-08-20 17:08:02 +00:00
|
|
|
rm $out/share/applications/nvim.desktop
|
2020-04-24 23:36:52 +00:00
|
|
|
substitute ${neovim}/share/applications/nvim.desktop $out/share/applications/nvim.desktop \
|
2022-12-02 08:20:57 +00:00
|
|
|
--replace 'Name=Neovim' 'Name=Neovim wrapper'
|
2020-04-24 23:36:52 +00:00
|
|
|
''
|
2023-02-02 18:25:31 +00:00
|
|
|
+ lib.optionalString withPython3 ''
|
2021-12-06 16:07:01 +00:00
|
|
|
makeWrapper ${python3Env.interpreter} $out/bin/nvim-python3 --unset PYTHONPATH
|
2020-08-20 17:08:02 +00:00
|
|
|
''
|
2023-02-02 18:25:31 +00:00
|
|
|
+ lib.optionalString (rubyEnv != null) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
ln -s ${rubyEnv}/bin/neovim-ruby-host $out/bin/nvim-ruby
|
2020-08-20 17:08:02 +00:00
|
|
|
''
|
2023-02-02 18:25:31 +00:00
|
|
|
+ lib.optionalString withNodeJs ''
|
2020-08-20 17:08:02 +00:00
|
|
|
ln -s ${nodePackages.neovim}/bin/neovim-node-host $out/bin/nvim-node
|
|
|
|
''
|
2023-02-02 18:25:31 +00:00
|
|
|
+ lib.optionalString vimAlias ''
|
2020-04-24 23:36:52 +00:00
|
|
|
ln -s $out/bin/nvim $out/bin/vim
|
2020-08-20 17:08:02 +00:00
|
|
|
''
|
2023-02-02 18:25:31 +00:00
|
|
|
+ lib.optionalString viAlias ''
|
2020-04-24 23:36:52 +00:00
|
|
|
ln -s $out/bin/nvim $out/bin/vi
|
2020-08-20 17:08:02 +00:00
|
|
|
''
|
2023-02-02 18:25:31 +00:00
|
|
|
+ lib.optionalString (manifestRc != null) (let
|
2020-11-03 02:18:15 +00:00
|
|
|
manifestWrapperArgs =
|
2023-04-12 12:48:02 +00:00
|
|
|
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ] ++ commonWrapperArgs;
|
2020-11-03 02:18:15 +00:00
|
|
|
in ''
|
2020-04-24 23:36:52 +00:00
|
|
|
echo "Generating remote plugin manifest"
|
|
|
|
export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
|
2021-05-28 09:39:13 +00:00
|
|
|
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgsStr}
|
2020-11-03 02:18:15 +00:00
|
|
|
|
2020-04-24 23:36:52 +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)"
|
|
|
|
# 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-11-03 02:18:15 +00:00
|
|
|
if ! $out/bin/nvim-wrapper \
|
|
|
|
-u ${writeText "manifest.vim" manifestRc} \
|
2020-04-24 23:36:52 +00:00
|
|
|
-i NONE -n \
|
2022-09-22 12:36:57 +00:00
|
|
|
-V1rplugins.log \
|
2020-04-24 23:36:52 +00:00
|
|
|
+UpdateRemotePlugins +quit! > outfile 2>&1; then
|
|
|
|
cat outfile
|
|
|
|
echo -e "\nGenerating rplugin.vim failed!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-11-03 02:18:15 +00:00
|
|
|
rm "${placeholder "out"}/bin/nvim-wrapper"
|
|
|
|
'')
|
|
|
|
+ ''
|
|
|
|
rm $out/bin/nvim
|
2021-06-01 10:57:12 +00:00
|
|
|
touch $out/rplugin.vim
|
2021-05-28 09:39:13 +00:00
|
|
|
makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
paths = [ neovim ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-06-28 23:13:55 +00:00
|
|
|
passthru = {
|
2023-04-12 12:48:02 +00:00
|
|
|
inherit providerLuaRc packpathDirs;
|
2021-06-28 23:13:55 +00:00
|
|
|
unwrapped = neovim;
|
|
|
|
initRc = neovimRcContent;
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
tests = callPackage ./tests {
|
2021-06-28 23:13:55 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
meta = neovim.meta // {
|
2020-08-20 17:08:02 +00:00
|
|
|
# To prevent builds on hydra
|
2020-04-24 23:36:52 +00:00
|
|
|
hydraPlatforms = [];
|
|
|
|
# prefer wrapper over the package
|
|
|
|
priority = (neovim.meta.priority or 0) - 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.makeOverridable wrapper
|