2020-05-19 02:39:54 +02:00
|
|
|
{ stdenv, symlinkJoin, lib, makeWrapper
|
2020-10-20 12:26:39 +02:00
|
|
|
, writeText
|
2018-11-07 21:38:18 +01:00
|
|
|
, nodePackages
|
2021-12-01 10:15:46 +01:00
|
|
|
, python3
|
2017-12-11 09:26:41 +01:00
|
|
|
, python3Packages
|
2021-06-08 00:52:17 +02:00
|
|
|
, callPackage
|
2023-04-01 16:33:37 +02:00
|
|
|
, neovimUtils
|
|
|
|
, vimUtils
|
2023-06-27 11:00:51 +02:00
|
|
|
, perl
|
2023-06-12 22:54:57 +02:00
|
|
|
, lndir
|
2017-12-11 09:26:41 +01:00
|
|
|
}:
|
2023-06-12 22:54:57 +02:00
|
|
|
|
2023-10-10 01:17:11 +02:00
|
|
|
neovim-unwrapped:
|
2017-12-11 09:26:41 +01:00
|
|
|
|
|
|
|
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 ? []
|
2023-04-01 16:33:37 +02:00
|
|
|
# a limited RC script used only to generate the manifest for remote plugins
|
2020-10-29 09:50:26 +01:00
|
|
|
, manifestRc ? null
|
2021-05-01 02:29:59 +02:00
|
|
|
, withPython2 ? false
|
2021-12-01 10:15:46 +01:00
|
|
|
, withPython3 ? true, python3Env ? python3
|
2020-11-02 21:59:00 +01:00
|
|
|
, withNodeJs ? false
|
2023-06-27 11:00:51 +02:00
|
|
|
, withPerl ? false
|
2020-11-02 21:59:00 +01:00
|
|
|
, 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
|
2023-12-27 20:38:59 +01:00
|
|
|
# vimL code that should be sourced as part of the generated init.lua file
|
|
|
|
, neovimRcContent ? null
|
|
|
|
# lua code to put into the generated init.lua file
|
|
|
|
, luaRcContent ? ""
|
2023-04-01 16:33:37 +02:00
|
|
|
# entry to load in packpath
|
|
|
|
, packpathDirs
|
2020-10-29 09:50:26 +01:00
|
|
|
, ...
|
2023-06-27 11:00:51 +02:00
|
|
|
}:
|
2023-11-22 00:42:43 +01:00
|
|
|
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
|
2023-12-27 20:38:59 +01:00
|
|
|
|
2023-11-22 00:42:43 +01:00
|
|
|
stdenv.mkDerivation (finalAttrs:
|
2017-12-11 09:26:41 +01:00
|
|
|
let
|
|
|
|
|
2023-12-27 20:38:59 +01:00
|
|
|
rcContent = ''
|
|
|
|
${luaRcContent}
|
|
|
|
'' + lib.optionalString (!isNull neovimRcContent) ''
|
|
|
|
vim.cmd.source "${writeText "init.vim" neovimRcContent}"
|
|
|
|
'';
|
|
|
|
|
2023-01-21 23:06:40 +01:00
|
|
|
wrapperArgsStr = if lib.isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
|
2021-05-25 22:37:57 +02:00
|
|
|
|
2023-11-22 00:42:43 +01:00
|
|
|
generatedWrapperArgs =
|
2023-04-01 16:33:37 +02:00
|
|
|
# vim accepts a limited number of commands so we join them all
|
2023-09-25 11:04:15 +02:00
|
|
|
[
|
2023-04-01 16:33:37 +02:00
|
|
|
"--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}"''
|
|
|
|
]
|
|
|
|
;
|
|
|
|
|
2023-06-27 11:00:51 +02:00
|
|
|
providerLuaRc = neovimUtils.generateProviderRc {
|
|
|
|
inherit withPython3 withNodeJs withPerl;
|
|
|
|
withRuby = rubyEnv != null;
|
|
|
|
};
|
2023-04-01 16:33:37 +02:00
|
|
|
|
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 =
|
2023-10-10 01:17:11 +02:00
|
|
|
[ "${neovim-unwrapped}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
|
2021-05-28 23:44:43 +02:00
|
|
|
++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
|
2023-11-22 00:42:43 +01:00
|
|
|
++ lib.optionals finalAttrs.wrapRc [ "--add-flags" "-u ${writeText "init.lua" rcContent}" ]
|
|
|
|
++ finalAttrs.generatedWrapperArgs
|
2021-05-28 23:44:43 +02:00
|
|
|
;
|
2023-07-06 01:38:58 +02:00
|
|
|
|
|
|
|
perlEnv = perl.withPackages (p: [ p.NeovimExt p.Appcpanminus ]);
|
2024-04-17 16:09:19 +02:00
|
|
|
|
|
|
|
pname = "neovim";
|
|
|
|
version = lib.getVersion neovim-unwrapped;
|
2023-11-22 00:42:43 +01:00
|
|
|
in {
|
2024-04-17 16:09:19 +02:00
|
|
|
name = "${pname}-${version}${extraName}";
|
|
|
|
inherit pname version;
|
2023-06-12 22:54:57 +02:00
|
|
|
|
|
|
|
__structuredAttrs = true;
|
|
|
|
dontUnpack = true;
|
|
|
|
inherit viAlias vimAlias withNodeJs withPython3 withPerl;
|
2023-10-10 01:17:11 +02:00
|
|
|
inherit wrapRc providerLuaRc packpathDirs;
|
|
|
|
inherit python3Env rubyEnv;
|
|
|
|
withRuby = rubyEnv != null;
|
2023-11-22 00:42:43 +01:00
|
|
|
inherit wrapperArgs generatedWrapperArgs;
|
2023-12-27 20:38:59 +01:00
|
|
|
luaRcContent = rcContent;
|
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
|
2023-10-10 01:17:11 +02:00
|
|
|
substitute ${neovim-unwrapped}/share/applications/nvim.desktop $out/share/applications/nvim.desktop \
|
2022-11-30 18:02:11 +01:00
|
|
|
--replace 'Name=Neovim' 'Name=Neovim wrapper'
|
2017-12-11 09:26:41 +01:00
|
|
|
''
|
2023-06-12 22:54:57 +02:00
|
|
|
+ lib.optionalString finalAttrs.withPython3 ''
|
2024-01-23 05:58:49 +01:00
|
|
|
makeWrapper ${python3Env.interpreter} $out/bin/nvim-python3 --unset PYTHONPATH --unset PYTHONSAFEPATH
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
2023-10-10 01:17:11 +02:00
|
|
|
+ lib.optionalString (finalAttrs.rubyEnv != null) ''
|
|
|
|
ln -s ${finalAttrs.rubyEnv}/bin/neovim-ruby-host $out/bin/nvim-ruby
|
2020-05-19 02:39:54 +02:00
|
|
|
''
|
2023-06-12 22:54:57 +02:00
|
|
|
+ lib.optionalString finalAttrs.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
|
|
|
''
|
2023-06-12 22:54:57 +02:00
|
|
|
+ lib.optionalString finalAttrs.withPerl ''
|
2023-07-06 01:38:58 +02:00
|
|
|
ln -s ${perlEnv}/bin/perl $out/bin/nvim-perl
|
2023-06-27 11:00:51 +02:00
|
|
|
''
|
2023-06-12 22:54:57 +02:00
|
|
|
+ lib.optionalString finalAttrs.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
|
|
|
''
|
2023-06-12 22:54:57 +02:00
|
|
|
+ lib.optionalString finalAttrs.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
|
|
|
''
|
2023-01-21 23:06:40 +01:00
|
|
|
+ lib.optionalString (manifestRc != null) (let
|
2020-10-29 09:50:26 +01:00
|
|
|
manifestWrapperArgs =
|
2023-11-22 00:42:43 +01:00
|
|
|
[ "${neovim-unwrapped}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ] ++ finalAttrs.generatedWrapperArgs;
|
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 \
|
2022-09-21 23:56:19 +02:00
|
|
|
-V1rplugins.log \
|
2018-12-30 20:37:44 +01:00
|
|
|
+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
|
|
|
|
2023-06-12 22:54:57 +02:00
|
|
|
buildPhase = ''
|
2023-10-10 01:17:11 +02:00
|
|
|
runHook preBuild
|
2023-06-12 22:54:57 +02:00
|
|
|
mkdir -p $out
|
2023-10-10 01:17:11 +02:00
|
|
|
for i in ${neovim-unwrapped}; do
|
2023-06-12 22:54:57 +02:00
|
|
|
lndir -silent $i $out
|
|
|
|
done
|
2023-10-10 01:17:11 +02:00
|
|
|
runHook postBuild
|
2023-06-12 22:54:57 +02:00
|
|
|
'';
|
2020-05-19 02:39:54 +02:00
|
|
|
|
2017-12-11 09:26:41 +01:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2023-06-12 22:54:57 +02:00
|
|
|
nativeBuildInputs = [ makeWrapper lndir ];
|
2021-05-28 23:44:43 +02:00
|
|
|
passthru = {
|
2023-04-01 16:33:37 +02:00
|
|
|
inherit providerLuaRc packpathDirs;
|
2023-10-10 01:17:11 +02:00
|
|
|
unwrapped = neovim-unwrapped;
|
2021-05-28 23:44:43 +02:00
|
|
|
initRc = neovimRcContent;
|
2021-06-08 00:52:17 +02:00
|
|
|
|
2022-08-18 01:06:54 +02:00
|
|
|
tests = callPackage ./tests {
|
2021-06-08 00:52:17 +02:00
|
|
|
};
|
2021-05-28 23:44:43 +02:00
|
|
|
};
|
2017-12-11 09:26:41 +01:00
|
|
|
|
2023-10-10 01:17:11 +02:00
|
|
|
meta = neovim-unwrapped.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
|
2023-10-10 01:17:11 +02:00
|
|
|
priority = (neovim-unwrapped.meta.priority or 0) - 1;
|
2017-12-11 09:26:41 +01:00
|
|
|
};
|
2023-06-12 22:54:57 +02:00
|
|
|
});
|
2017-12-11 09:26:41 +01:00
|
|
|
in
|
|
|
|
lib.makeOverridable wrapper
|