1 { stdenv, symlinkJoin, lib, makeWrapper
18 # inherit interpreter from neovim
19 lua = neovim-unwrapped.lua;
23 # certain plugins need a custom configuration (available in passthru.initLua)
25 # if true, the wrapper automatically appends those snippets when necessary
26 , autoconfigure ? false
27 # should contain all args but the binary. Can be either a string or list
31 /* the function you would have passed to python3.withPackages */
32 , extraPython3Packages ? (_: [ ])
38 # wether to create symlinks in $out/bin/vi(m) -> $out/bin/nvim
42 # additional argument not generated by makeNeovimConfig
43 # it will append "-u <customRc>" to the wrapped arguments
44 # set to false if you want to control where to save the generated config
45 # (e.g., in ~/.config/init.vim or project/.nvimrc)
47 # vimL code that should be sourced as part of the generated init.lua file
48 , neovimRcContent ? null
49 # lua code to put into the generated init.lua file
51 # DEPRECATED: entry to load in packpath
52 # use 'plugins' instead
53 , packpathDirs ? null # not used anymore
55 # a list of neovim plugin derivations, for instance
57 # { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; }
62 assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
64 assert packpathDirs != null -> throw "packpathdirs is not used anymore: pass a list of neovim plugin derivations in 'plugins' instead.";
66 stdenv.mkDerivation (finalAttrs:
68 pluginsNormalized = neovimUtils.normalizePlugins finalAttrs.plugins;
70 myVimPackage = neovimUtils.normalizedPluginsToVimPackage pluginsNormalized;
72 rubyEnv = bundlerEnv {
73 name = "neovim-ruby-env";
74 gemdir = ./ruby_provider;
76 ln -sf ${ruby}/bin/* $out/bin
80 pluginRC = lib.foldl (acc: p: if p.config != null then acc ++ [p.config] else acc) [] pluginsNormalized;
82 # a limited RC script used only to generate the manifest for remote plugins
83 manifestRc = vimUtils.vimrcContent { customRC = ""; };
84 # we call vimrcContent without 'packages' to avoid the init.vim generation
85 neovimRcContent' = vimUtils.vimrcContent {
87 customRC = lib.concatStringsSep "\n" (pluginRC ++ lib.optional (neovimRcContent != null) neovimRcContent);
91 packpathDirs.myNeovimPackages = myVimPackage;
92 finalPackdir = neovimUtils.packDir packpathDirs;
95 op = acc: normalizedPlugin:
96 acc ++ lib.optional (finalAttrs.autoconfigure && normalizedPlugin.plugin.passthru ? initLua) normalizedPlugin.plugin.passthru.initLua;
98 lib.foldl' op [] pluginsNormalized;
102 '' + lib.optionalString (neovimRcContent' != null) ''
103 vim.cmd.source "${writeText "init.vim" neovimRcContent'}"
105 lib.concatStringsSep "\n" luaPluginRC
108 getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));
110 requiredPlugins = vimUtils.requiredPluginsForPackage myVimPackage;
111 pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins;
113 python3Env = lib.warnIf (attrs ? python3Env) "Pass your python packages via the `extraPython3Packages`, e.g., `extraPython3Packages = ps: [ ps.pandas ]`"
114 python3.pkgs.python.withPackages (ps:
116 ++ (extraPython3Packages ps)
117 ++ (lib.concatMap (f: f ps) pluginPython3Packages));
120 wrapperArgsStr = if lib.isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
122 generatedWrapperArgs = let
123 binPath = lib.makeBinPath (lib.optional finalAttrs.withRuby rubyEnv ++ lib.optional finalAttrs.withNodeJs nodejs);
126 # vim accepts a limited number of commands so we join them all
128 "--add-flags" ''--cmd "lua ${providerLuaRc}"''
130 ++ lib.optionals (packpathDirs.myNeovimPackages.start != [] || packpathDirs.myNeovimPackages.opt != []) [
131 "--add-flags" ''--cmd "set packpath^=${finalPackdir}"''
132 "--add-flags" ''--cmd "set rtp^=${finalPackdir}"''
134 ++ lib.optionals finalAttrs.withRuby [
135 "--set" "GEM_HOME" "${rubyEnv}/${rubyEnv.ruby.gemPath}"
136 ] ++ lib.optionals (binPath != "") [
137 "--suffix" "PATH" ":" binPath
141 providerLuaRc = neovimUtils.generateProviderRc {
142 inherit (finalAttrs) withPython3 withNodeJs withPerl withRuby;
145 # If configure != {}, we can't generate the rplugin.vim file with e.g
146 # NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
147 # the wrapper. That's why only when configure != {} (tested both here and
148 # when postBuild is evaluated), we call makeWrapper once to generate a
149 # wrapper with most arguments we need, excluding those that cause problems to
150 # generate rplugin.vim, but still required for the final wrapper.
151 finalMakeWrapperArgs =
152 [ "${neovim-unwrapped}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
153 ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
154 ++ lib.optionals finalAttrs.wrapRc [ "--add-flags" "-u ${writeText "init.lua" rcContent}" ]
155 ++ finalAttrs.generatedWrapperArgs
158 perlEnv = perl.withPackages (p: [ p.NeovimExt p.Appcpanminus ]);
161 version = lib.getVersion neovim-unwrapped;
163 name = "${pname}-${version}${extraName}";
164 inherit pname version;
167 __structuredAttrs = true;
169 inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby;
170 inherit autoconfigure wrapRc providerLuaRc packpathDirs;
171 inherit python3Env rubyEnv;
172 inherit wrapperArgs generatedWrapperArgs;
173 luaRcContent = rcContent;
174 # Remove the symlinks created by symlinkJoin which we need to perform
176 postBuild = lib.optionalString stdenv.hostPlatform.isLinux ''
177 rm $out/share/applications/nvim.desktop
178 substitute ${neovim-unwrapped}/share/applications/nvim.desktop $out/share/applications/nvim.desktop \
179 --replace-warn 'Name=Neovim' 'Name=Neovim wrapper'
181 + lib.optionalString finalAttrs.withPython3 ''
182 makeWrapper ${python3Env.interpreter} $out/bin/nvim-python3 --unset PYTHONPATH --unset PYTHONSAFEPATH
184 + lib.optionalString (finalAttrs.withRuby) ''
185 ln -s ${finalAttrs.rubyEnv}/bin/neovim-ruby-host $out/bin/nvim-ruby
187 + lib.optionalString finalAttrs.withNodeJs ''
188 ln -s ${neovim-node-client}/bin/neovim-node-host $out/bin/nvim-node
190 + lib.optionalString finalAttrs.withPerl ''
191 ln -s ${perlEnv}/bin/perl $out/bin/nvim-perl
193 + lib.optionalString finalAttrs.vimAlias ''
194 ln -s $out/bin/nvim $out/bin/vim
196 + lib.optionalString finalAttrs.viAlias ''
197 ln -s $out/bin/nvim $out/bin/vi
199 + lib.optionalString (manifestRc != null) (let
200 manifestWrapperArgs =
201 [ "${neovim-unwrapped}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ] ++ finalAttrs.generatedWrapperArgs;
203 echo "Generating remote plugin manifest"
204 export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
205 makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgsStr}
207 # Some plugins assume that the home directory is accessible for
208 # initializing caches, temporary files, etc. Even if the plugin isn't
209 # actively used, it may throw an error as soon as Neovim is launched
210 # (e.g., inside an autoload script), causing manifest generation to
211 # fail. Therefore, let's create a fake home directory before generating
212 # the manifest, just to satisfy the needs of these plugins.
214 # See https://github.com/Yggdroot/LeaderF/blob/v1.21/autoload/lfMru.vim#L10
215 # for an example of this behavior.
216 export HOME="$(mktemp -d)"
217 # Launch neovim with a vimrc file containing only the generated plugin
218 # code. Pass various flags to disable temp file generation
219 # (swap/viminfo) and redirect errors to stderr.
220 # Only display the log on error since it will contain a few normally
221 # irrelevant messages.
222 if ! $out/bin/nvim-wrapper \
223 -u ${writeText "manifest.vim" manifestRc} \
226 +UpdateRemotePlugins +quit! > outfile 2>&1; then
228 echo -e "\nGenerating rplugin.vim failed!"
231 rm "${placeholder "out"}/bin/nvim-wrapper"
235 touch $out/rplugin.vim
237 echo "Looking for lua dependencies..."
238 source ${lua}/nix-support/utils.sh
240 _addToLuaPath "${finalPackdir}"
242 echo "LUA_PATH towards the end of packdir: $LUA_PATH"
244 makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr} \
245 --prefix LUA_PATH ';' "$LUA_PATH" \
246 --prefix LUA_CPATH ';' "$LUA_CPATH"
252 for i in ${neovim-unwrapped}; do
253 lndir -silent $i $out
258 preferLocalBuild = true;
260 nativeBuildInputs = [ makeWrapper lndir ];
262 # A Vim "package", see ':h packages'
263 vimPackage = myVimPackage;
268 $out/bin/nvim -i NONE -e +quitall!
273 inherit providerLuaRc packpathDirs;
274 unwrapped = neovim-unwrapped;
275 initRc = neovimRcContent';
277 tests = callPackage ./tests {
282 inherit (neovim-unwrapped.meta)
291 # To prevent builds on hydra
293 # prefer wrapper over the package
294 priority = (neovim-unwrapped.meta.priority or lib.meta.defaultPriority) - 1;
298 lib.makeOverridable wrapper