git.iko.soy/typeable/nixpkgs
on master help sign in
vimUtils: derive pname from the plugin string (#53121)

For backwards compatibility. The user may specify their own plugins without the pname attribute. In that case the attrname of the plugin (given as a string) is the pname. Fixes #53112

commita0dc57e27bcc8762d3bc7b9951ebd1a4a6388d15 authorTimo Kaufmann <timokau@zoho.com> dateMon 31 Dec 2018, 16:26 (8 years ago) parentced0be5
1 file changed+50−20
pkgs/misc/vim-plugins/vim-utils.nix+50−20
pkgs/misc/vim-plugins/vim-utils.nix+50−20
@@ -1,5 +1,7 @@
1−{stdenv, vim, vimPlugins, vim_configurable, neovim, buildEnv, writeText, writeScriptBin
2−, nix-prefetch-hg, nix-prefetch-git }:
1+{ stdenv, vim, vimPlugins, vim_configurable, neovim, buildEnv, writeText, writeScriptBin
2+, nix-prefetch-hg, nix-prefetch-git
3+, fetchFromGitHub
4+}:
35
46/*
57
@@ -150,20 +152,23 @@ vim_with_plugins can be installed like any other application within Nix.
150152let
151153 inherit (stdenv) lib;
152154
153− # transitive closure of plugin dependencies
154− transitiveClosure = knownPlugins: plugin:
155− let
156− # vam puts out a list of strings as the dependency list, we need to be able to deal with that.
157− # Because of that, "plugin" may be a string or a derivation. If it is a string, it is resolved
158− # using `knownPlugins`. Otherwise `knownPlugins` can be null.
159− knownPlugins' = if knownPlugins == null then vimPlugins else knownPlugins;
160− pluginDrv = if builtins.isString plugin then knownPlugins'.${plugin} else plugin;
161− in
162− [ pluginDrv ] ++ (
163− lib.unique (builtins.concatLists (map (transitiveClosure knownPlugins) pluginDrv.dependencies or []))
155+ # make sure a plugin is a derivation. If plugin already is a derivation, this
156+ # is a no-op. If it is a string, it is looked up in knownPlugins.
157+ pluginToDrv = knownPlugins: plugin:
158+ if builtins.isString plugin then
159+ # make sure `pname` is set to that we are able to convert the derivation
160+ # back to a string.
161+ ( knownPlugins.${plugin} // { pname = plugin; })
162+ else
163+ plugin;
164+
165+ # transitive closure of plugin dependencies (plugin needs to be a derivation)
166+ transitiveClosure = plugin:
167+ [ plugin ] ++ (
168+ lib.unique (builtins.concatLists (map transitiveClosure plugin.dependencies or []))
164169 );
165170
166− findDependenciesRecursively = knownPlugins: plugins: lib.concatMap (transitiveClosure knownPlugins) plugins;
171+ findDependenciesRecursively = plugins: lib.concatMap transitiveClosure plugins;
167172
168173 attrnamesToPlugins = { knownPlugins, names }:
169174 map (name: if builtins.isString name then knownPlugins.${name} else name) knownPlugins;
@@ -195,7 +200,7 @@ let
195200 (let
196201 knownPlugins = pathogen.knownPlugins or vimPlugins;
197202
198− plugins = findDependenciesRecursively knownPlugins pathogen.pluginNames;
203+ plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames);
199204
200205 pluginsEnv = buildEnv {
201206 name = "pathogen-plugin-env";
@@ -240,7 +245,10 @@ let
240245 (let
241246 knownPlugins = vam.knownPlugins or vimPlugins;
242247
243− plugins = findDependenciesRecursively knownPlugins (lib.concatMap vamDictToNames vam.pluginDictionaries);
248+ # plugins specified by the user
249+ specifiedPlugins = map (pluginToDrv knownPlugins) (lib.concatMap vamDictToNames vam.pluginDictionaries);
250+ # plugins with dependencies
251+ plugins = findDependenciesRecursively specifiedPlugins;
244252
245253 # Vim almost reads JSON, so eventually JSON support should be added to Nix
246254 # TODO: proper quoting
@@ -298,8 +306,8 @@ let
298306 # opposed to older implementations that have to maintain backwards
299307 # compatibility). Therefore we don't need to deal with "knownPlugins"
300308 # and can simply pass `null`.
301− depsOfOptionalPlugins = lib.subtractLists opt (findDependenciesRecursively null opt);
302− startWithDeps = findDependenciesRecursively null start;
309+ depsOfOptionalPlugins = lib.subtractLists opt (findDependenciesRecursively opt);
310+ startWithDeps = findDependenciesRecursively start;
303311 in
304312 ["mkdir -p $out/pack/${packageName}/start"]
305313 # To avoid confusion, even dependencies of optional plugins are added
@@ -421,8 +429,8 @@ rec {
421429 if vam != null && vam ? knownPlugins then vam.knownPlugins else
422430 if pathogen != null && pathogen ? knownPlugins then pathogen.knownPlugins else
423431 vimPlugins;
424− pathogenPlugins = findDependenciesRecursively knownPlugins pathogen.pluginNames;
425− vamPlugins = findDependenciesRecursively knownPlugins (lib.concatMap vamDictToNames vam.pluginDictionaries);
432+ pathogenPlugins = findDependenciesRecursively ((map pluginToDrv knownPlugins) pathogen.pluginNames);
433+ vamPlugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) (lib.concatMap vamDictToNames vam.pluginDictionaries));
426434 nonNativePlugins = (lib.optionals (pathogen != null) pathogenPlugins)
427435 ++ (lib.optionals (vam != null) vamPlugins)
428436 ++ (lib.optionals (plug != null) plug.plugins);
@@ -457,4 +465,26 @@ rec {
457465 test_nvim_with_vim_nix_using_pathogen = neovim.override {
458466 configure.pathogen.pluginNames = [ "vim-nix" ];
459467 };
468+
469+ # regression test for https://github.com/NixOS/nixpkgs/issues/53112
470+ # The user may have specified their own plugins which may not be formatted
471+ # exactly as the generated ones. In particular, they may not have the `pname`
472+ # attribute.
473+ test_vim_with_custom_plugin = vim_configurable.customize {
474+ name = "vim_with_custom_plugin";
475+ vimrcConfig.vam.knownPlugins =
476+ vimPlugins // ({
477+ "vim-trailing-whitespace" = buildVimPluginFrom2Nix {
478+ name = "vim-trailing-whitespace";
479+ src = fetchFromGitHub {
480+ owner = "bronson";
481+ repo = "vim-trailing-whitespace";
482+ rev = "4c596548216b7c19971f8fc94e38ef1a2b55fee6";
483+ sha256 = "0f1cpnp1nxb4i5hgymjn2yn3k1jwkqmlgw1g02sq270lavp2dzs9";
484+ };
485+ dependencies = [];
486+ };
487+ });
488+ vimrcConfig.vam.pluginDictionaries = [ { names = [ "vim-trailing-whitespace" ]; } ];
489+ };
460490}