@ -1,5 +1,7 @@
{ stdenv , vim , vimPlugins , vim_configurable , neovim , buildEnv , writeText , writeScriptBin
, nix-prefetch-hg , nix-prefetch-git } :
{ stdenv , vim , vimPlugins , vim_configurable , neovim , buildEnv , writeText , writeScriptBin
, nix-prefetch-hg , nix-prefetch-git
, fetchFromGitHub
} :
/*
@ -150,20 +152,23 @@ vim_with_plugins can be installed like any other application within Nix.
let
inherit ( stdenv ) lib ;
# transitive closure of plugin dependencies
transitiveClosure = knownPlugins : plugin :
let
# vam puts out a list of strings as the dependency list, we need to be able to deal with that.
# Because of that, "plugin" may be a string or a derivation. If it is a string, it is resolved
# using `knownPlugins`. Otherwise `knownPlugins` can be null.
knownPlugins' = if knownPlugins == null then vimPlugins else knownPlugins ;
pluginDrv = if builtins . isString plugin then knownPlugins' . ${ plugin } else plugin ;
in
[ pluginDrv ] ++ (
lib . unique ( builtins . concatLists ( map ( transitiveClosure knownPlugins ) pluginDrv . dependencies or [ ] ) )
# make sure a plugin is a derivation. If plugin already is a derivation, this
# is a no-op. If it is a string, it is looked up in knownPlugins.
pluginToDrv = knownPlugins : plugin :
if builtins . isString plugin then
# make sure `pname` is set to that we are able to convert the derivation
# back to a string.
( knownPlugins . ${ plugin } // { pname = plugin ; } )
else
plugin ;
# transitive closure of plugin dependencies (plugin needs to be a derivation)
transitiveClosure = plugin :
[ plugin ] ++ (
lib . unique ( builtins . concatLists ( map transitiveClosure plugin . dependencies or [ ] ) )
) ;
findDependenciesRecursively = knownPlugins : plugins : lib . concatMap ( transitiveClosure knownPlugins ) plugins ;
findDependenciesRecursively = plugins : lib . concatMap transitiveClosure plugins ;
attrnamesToPlugins = { knownPlugins , names }:
map ( name : if builtins . isString name then knownPlugins . ${ name } else name ) knownPlugins ;
@ -195,7 +200,7 @@ let
( let
knownPlugins = pathogen . knownPlugins or vimPlugins ;
plugins = findDependenciesRecursively knownPlugins pathogen . pluginNames ;
plugins = findDependenciesRecursively ( map ( pluginToDrv knownPlugins ) pathogen . pluginNames ) ;
pluginsEnv = buildEnv {
name = " p a t h o g e n - p l u g i n - e n v " ;
@ -240,7 +245,10 @@ let
( let
knownPlugins = vam . knownPlugins or vimPlugins ;
plugins = findDependenciesRecursively knownPlugins ( lib . concatMap vamDictToNames vam . pluginDictionaries ) ;
# plugins specified by the user
specifiedPlugins = map ( pluginToDrv knownPlugins ) ( lib . concatMap vamDictToNames vam . pluginDictionaries ) ;
# plugins with dependencies
plugins = findDependenciesRecursively specifiedPlugins ;
# Vim almost reads JSON, so eventually JSON support should be added to Nix
# TODO: proper quoting
@ -298,8 +306,8 @@ let
# opposed to older implementations that have to maintain backwards
# compatibility). Therefore we don't need to deal with "knownPlugins"
# and can simply pass `null`.
depsOfOptionalPlugins = lib . subtractLists opt ( findDependenciesRecursively null opt ) ;
startWithDeps = findDependenciesRecursively null start ;
depsOfOptionalPlugins = lib . subtractLists opt ( findDependenciesRecursively opt ) ;
startWithDeps = findDependenciesRecursively start ;
in
[ " m k d i r - p $ o u t / p a c k / ${ packageName } / s t a r t " ]
# To avoid confusion, even dependencies of optional plugins are added
@ -421,8 +429,8 @@ rec {
if vam != null && vam ? knownPlugins then vam . knownPlugins else
if pathogen != null && pathogen ? knownPlugins then pathogen . knownPlugins else
vimPlugins ;
pathogenPlugins = findDependenciesRecursively knownPlugins pathogen . pluginNames ;
vamPlugins = findDependenciesRecursively knownPlugins ( lib . concatMap vamDictToNames vam . pluginDictionaries ) ;
pathogenPlugins = findDependenciesRecursively ( ( map pluginToDrv knownPlugins ) pathogen . pluginNames ) ;
vamPlugins = findDependenciesRecursively ( map ( pluginToDrv knownPlugins ) ( lib . concatMap vamDictToNames vam . pluginDictionaries ) ) ;
nonNativePlugins = ( lib . optionals ( pathogen != null ) pathogenPlugins )
++ ( lib . optionals ( vam != null ) vamPlugins )
++ ( lib . optionals ( plug != null ) plug . plugins ) ;
@ -457,4 +465,26 @@ rec {
test_nvim_with_vim_nix_using_pathogen = neovim . override {
configure . pathogen . pluginNames = [ " v i m - n i x " ] ;
} ;
# regression test for https://github.com/NixOS/nixpkgs/issues/53112
# The user may have specified their own plugins which may not be formatted
# exactly as the generated ones. In particular, they may not have the `pname`
# attribute.
test_vim_with_custom_plugin = vim_configurable . customize {
name = " v i m _ w i t h _ c u s t o m _ p l u g i n " ;
vimrcConfig . vam . knownPlugins =
vimPlugins // ( {
" v i m - t r a i l i n g - w h i t e s p a c e " = buildVimPluginFrom2Nix {
name = " v i m - t r a i l i n g - w h i t e s p a c e " ;
src = fetchFromGitHub {
owner = " b r o n s o n " ;
repo = " v i m - t r a i l i n g - w h i t e s p a c e " ;
rev = " 4 c 5 9 6 5 4 8 2 1 6 b 7 c 1 9 9 7 1 f 8 f c 9 4 e 3 8 e f 1 a 2 b 5 5 f e e 6 " ;
sha256 = " 0 f 1 c p n p 1 n x b 4 i 5 h g y m j n 2 y n 3 k 1 j w k q m l g w 1 g 0 2 s q 2 7 0 l a v p 2 d z s 9 " ;
} ;
dependencies = [ ] ;
} ;
} ) ;
vimrcConfig . vam . pluginDictionaries = [ { names = [ " v i m - t r a i l i n g - w h i t e s p a c e " ] ; } ] ;
} ;
}