Merge pull request #52767 from timokau/vim-plugin-updates

Fix vim-plugin dependencies
This commit is contained in:
Timo Kaufmann 2018-12-28 13:48:21 +01:00 committed by GitHub
commit 22d0f320e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1020 additions and 638 deletions

View file

@ -48,7 +48,7 @@ neovim.override {
## Managing plugins with Vim packages ## Managing plugins with Vim packages
To store you plugins in Vim packages the following example can be used: To store you plugins in Vim packages (the native vim plugin manager, see `:help packages`) the following example can be used:
``` ```
vim_configurable.customize { vim_configurable.customize {
@ -56,6 +56,8 @@ vim_configurable.customize {
# loaded on launch # loaded on launch
start = [ youcompleteme fugitive ]; start = [ youcompleteme fugitive ];
# manually loadable by calling `:packadd $plugin-name` # manually loadable by calling `:packadd $plugin-name`
# however, if a vim plugin has a dependency that is not explicitly listed in
# opt that dependency will always be added to start to avoid confusion.
opt = [ phpCompletion elm-vim ]; opt = [ phpCompletion elm-vim ];
# To automatically load a plugin when opening a filetype, add vimrc lines like: # To automatically load a plugin when opening a filetype, add vimrc lines like:
# autocmd FileType php :packadd phpCompletion # autocmd FileType php :packadd phpCompletion
@ -63,6 +65,7 @@ vim_configurable.customize {
} }
``` ```
`myVimPackage` is an arbitrary name for the generated package. You can choose any name you like.
For Neovim the syntax is: For Neovim the syntax is:
``` ```
@ -74,6 +77,8 @@ neovim.override {
packages.myVimPackage = with pkgs.vimPlugins; { packages.myVimPackage = with pkgs.vimPlugins; {
# see examples below how to use custom packages # see examples below how to use custom packages
start = [ ]; start = [ ];
# If a vim plugin has a dependency that is not explicitly listed in
# opt that dependency will always be added to start to avoid confusion.
opt = [ ]; opt = [ ];
}; };
}; };

View file

@ -0,0 +1,54 @@
{ stdenv
, rtpPath ? "share/vim-plugins"
, vim
}:
rec {
addRtp = path: attrs: derivation:
derivation // { rtp = "${derivation}/${path}"; } // {
overrideAttrs = f: buildVimPlugin (attrs // f attrs);
};
buildVimPlugin = attrs@{
name ? "${attrs.pname}-${attrs.version}",
namePrefix ? "vimplugin-",
src,
unpackPhase ? "",
configurePhase ? "",
buildPhase ? "",
preInstall ? "",
postInstall ? "",
path ? (builtins.parseDrvName name).name,
addonInfo ? null,
...
}:
addRtp "${rtpPath}/${path}" attrs (stdenv.mkDerivation (attrs // {
name = namePrefix + name;
inherit unpackPhase configurePhase buildPhase addonInfo preInstall postInstall;
installPhase = ''
runHook preInstall
target=$out/${rtpPath}/${path}
mkdir -p $out/${rtpPath}
cp -r . $target
# build help tags
if [ -d "$target/doc" ]; then
${vim}/bin/vim -N -u NONE -i NONE -n -E -s -c "helptags $1/doc" +quit! || echo "docs to build failed"
fi
if [ -n "$addonInfo" ]; then
echo "$addonInfo" > $target/addon-info.json
fi
runHook postInstall
'';
}));
buildVimPluginFrom2Nix = attrs: buildVimPlugin ({
buildPhase = ":";
configurePhase =":";
} // attrs);
}

View file

@ -5,8 +5,8 @@ let
inherit (vimUtils.override {inherit vim;}) buildVimPluginFrom2Nix; inherit (vimUtils.override {inherit vim;}) buildVimPluginFrom2Nix;
generated = callPackage ./generated.nix { plugins = callPackage ./generated.nix {
inherit buildVimPluginFrom2Nix; inherit buildVimPluginFrom2Nix overrides;
}; };
# TL;DR # TL;DR
@ -22,10 +22,8 @@ let
inherit llvmPackages; inherit llvmPackages;
}; };
overriden = generated // (overrides generated); aliases = lib.optionalAttrs (config.allowAliases or true) (import ./aliases.nix lib plugins);
aliases = lib.optionalAttrs (config.allowAliases or true) (import ./aliases.nix lib overriden);
in in
overriden // aliases plugins // aliases

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,9 @@
{config, lib, stdenv { lib, stdenv
, python, cmake, vim, vimUtils, ruby , python, cmake, vim, ruby
, which, fetchgit, llvmPackages, rustPlatform , which, fetchgit, llvmPackages, rustPlatform
, xkb_switch, fzf, skim , xkb_switch, fzf, skim
, python3, boost, icu, ncurses , python3, boost, icu, ncurses
, ycmd, rake , ycmd, rake
, pythonPackages, python3Packages
, substituteAll , substituteAll
, languagetool , languagetool
, Cocoa, CoreFoundation, CoreServices , Cocoa, CoreFoundation, CoreServices
@ -17,34 +16,22 @@
, impl, iferr, gocode, gocode-gomod, go-tools , impl, iferr, gocode, gocode-gomod, go-tools
}: }:
let self: super: {
_skim = skim;
in
generated:
with generated;
{
vim2nix = buildVimPluginFrom2Nix { vim2nix = buildVimPluginFrom2Nix {
name = "vim2nix"; name = "vim2nix";
src = ./vim2nix; src = ./vim2nix;
dependencies = ["vim-addon-manager"]; dependencies = with super; [ vim-addon-manager ];
}; };
fzfWrapper = buildVimPluginFrom2Nix { fzfWrapper = buildVimPluginFrom2Nix {
name = fzf.name; name = fzf.name;
src = fzf.src; src = fzf.src;
dependencies = [];
}; };
skim = buildVimPluginFrom2Nix { skim = buildVimPluginFrom2Nix {
name = _skim.name; name = skim.name;
src = _skim.vim; src = skim.vim;
dependencies = [];
}; };
LanguageClient-neovim = let LanguageClient-neovim = let
@ -70,7 +57,6 @@ with generated;
name = "LanguageClient-neovim-2018-09-07"; name = "LanguageClient-neovim-2018-09-07";
src = LanguageClient-neovim-src; src = LanguageClient-neovim-src;
dependencies = [];
propogatedBuildInputs = [ LanguageClient-neovim-bin ]; propogatedBuildInputs = [ LanguageClient-neovim-bin ];
preFixup = '' preFixup = ''
@ -87,10 +73,9 @@ with generated;
rev = "69cce66defdf131958f152ea7a7b26c21ca9d009"; rev = "69cce66defdf131958f152ea7a7b26c21ca9d009";
sha256 = "1363b2fmv69axrl2hm74dmx51cqd8k7rk116890qllnapzw1zjgc"; sha256 = "1363b2fmv69axrl2hm74dmx51cqd8k7rk116890qllnapzw1zjgc";
}; };
dependencies = [];
}; };
clang_complete = clang_complete.overrideAttrs(old: { clang_complete = super.clang_complete.overrideAttrs(old: {
# In addition to the arguments you pass to your compiler, you also need to # In addition to the arguments you pass to your compiler, you also need to
# specify the path of the C++ std header (if you are using C++). # specify the path of the C++ std header (if you are using C++).
# These usually implicitly set by cc-wrapper around clang (pkgs/build-support/cc-wrapper). # These usually implicitly set by cc-wrapper around clang (pkgs/build-support/cc-wrapper).
@ -107,14 +92,14 @@ with generated;
''; '';
}); });
clighter8 = clighter8.overrideAttrs(old: { clighter8 = super.clighter8.overrideAttrs(old: {
preFixup = '' preFixup = ''
sed "/^let g:clighter8_libclang_path/s|')$|${llvmPackages.clang.cc.lib}/lib/libclang.so')|" \ sed "/^let g:clighter8_libclang_path/s|')$|${llvmPackages.clang.cc.lib}/lib/libclang.so')|" \
-i "$out"/share/vim-plugins/clighter8/plugin/clighter8.vim -i "$out"/share/vim-plugins/clighter8/plugin/clighter8.vim
''; '';
}); });
command-t = command-t.overrideAttrs(old: { command-t = super.command-t.overrideAttrs(old: {
buildInputs = [ ruby rake ]; buildInputs = [ ruby rake ];
buildPhase = '' buildPhase = ''
rake make rake make
@ -122,7 +107,7 @@ with generated;
''; '';
}); });
cpsm = cpsm.overrideAttrs(old: { cpsm = super.cpsm.overrideAttrs(old: {
buildInputs = [ buildInputs = [
python3 python3
stdenv stdenv
@ -138,7 +123,7 @@ with generated;
''; '';
}); });
ctrlp-cmatcher = ctrlp-cmatcher.overrideAttrs(old: { ctrlp-cmatcher = super.ctrlp-cmatcher.overrideAttrs(old: {
buildInputs = [ python ]; buildInputs = [ python ];
buildPhase = '' buildPhase = ''
patchShebangs . patchShebangs .
@ -146,7 +131,7 @@ with generated;
''; '';
}); });
deoplete-go = deoplete-go.overrideAttrs(old: { deoplete-go = super.deoplete-go.overrideAttrs(old: {
buildInputs = [ python3 ]; buildInputs = [ python3 ];
buildPhase = '' buildPhase = ''
pushd ./rplugin/python3/deoplete/ujson pushd ./rplugin/python3/deoplete/ujson
@ -156,114 +141,106 @@ with generated;
''; '';
}); });
ensime-vim = ensime-vim.overrideAttrs(old: { ensime-vim = super.ensime-vim.overrideAttrs(old: {
passthru.python3Dependencies = ps: with ps; [ sexpdata websocket_client ]; passthru.python3Dependencies = ps: with ps; [ sexpdata websocket_client ];
dependencies = ["vimproc" "vimshell" "self" "forms"]; dependencies = with super; [ vimproc-vim vimshell-vim super.self forms ];
}); });
forms = forms.overrideAttrs(old: { forms = super.forms.overrideAttrs(old: {
dependencies = ["self"]; dependencies = with super; [ super.self ];
}); });
gist-vim = gist-vim.overrideAttrs(old: { gist-vim = super.gist-vim.overrideAttrs(old: {
dependencies = ["webapi-vim"]; dependencies = with super; [ webapi-vim ];
}); });
gitv = gitv.overrideAttrs(old: { ncm2 = super.ncm2.overrideAttrs(old: {
dependencies = ["gitv"]; dependencies = with super; [ nvim-yarp ];
}); });
ncm2 = ncm2.overrideAttrs(old: { ncm2-jedi = super.ncm2-jedi.overrideAttrs(old: {
dependencies = ["nvim-yarp"]; dependencies = with super; [ nvim-yarp ncm2 ];
passthru.python3Dependencies = ps: with ps; [ jedi ];
}); });
ncm2-ultisnips = ncm2-ultisnips.overrideAttrs(old: { ncm2-ultisnips = super.ncm2-ultisnips.overrideAttrs(old: {
dependencies = ["ultisnips"]; dependencies = with super; [ ultisnips ];
}); });
taglist-vim = taglist-vim.overrideAttrs(old: { vimshell-vim = super.vimshell-vim.overrideAttrs(old: {
setSourceRoot = '' dependencies = with super; [ vimproc-vim ];
export sourceRoot=taglist
mkdir taglist
mv doc taglist
mv plugin taglist
'';
}); });
vimshell-vim = vimshell-vim.overrideAttrs(old: { vim-addon-manager = super.vim-addon-manager.overrideAttrs(old: {
dependencies = [ "vimproc-vim" ];
});
vim-addon-manager = vim-addon-manager.overrideAttrs(old: {
buildInputs = stdenv.lib.optional stdenv.isDarwin Cocoa; buildInputs = stdenv.lib.optional stdenv.isDarwin Cocoa;
}); });
vim-addon-actions = vim-addon-actions.overrideAttrs(old: { vim-addon-actions = super.vim-addon-actions.overrideAttrs(old: {
dependencies = [ "vim-addon-mw-utils" "tlib" ]; dependencies = with super; [ vim-addon-mw-utils tlib_vim ];
}); });
vim-addon-async = vim-addon-async.overrideAttrs(old: { vim-addon-async = super.vim-addon-async.overrideAttrs(old: {
dependencies = [ "vim-addon-signs" ]; dependencies = with super; [ vim-addon-signs ];
}); });
vim-addon-background-cmd = vim-addon-background-cmd.overrideAttrs(old: { vim-addon-background-cmd = super.vim-addon-background-cmd.overrideAttrs(old: {
dependencies = [ "vim-addon-mw-utils" ]; dependencies = with super; [ vim-addon-mw-utils ];
}); });
vim-addon-completion = vim-addon-completion.overrideAttrs(old: { vim-addon-completion = super.vim-addon-completion.overrideAttrs(old: {
dependencies = [ "tlib" ]; dependencies = with super; [ tlib_vim ];
}); });
vim-addon-goto-thing-at-cursor = vim-addon-goto-thing-at-cursor.overrideAttrs(old: { vim-addon-goto-thing-at-cursor = super.vim-addon-goto-thing-at-cursor.overrideAttrs(old: {
dependencies = [ "tlib" ]; dependencies = with super; [ tlib_vim ];
}); });
vim-addon-mru = vim-addon-mru.overrideAttrs(old: { vim-addon-mru = super.vim-addon-mru.overrideAttrs(old: {
dependencies = ["vim-addon-other" "vim-addon-mw-utils"]; dependencies = with super; [ vim-addon-other vim-addon-mw-utils ];
}); });
vim-addon-nix = vim-addon-nix.overrideAttrs(old: { vim-addon-nix = super.vim-addon-nix.overrideAttrs(old: {
dependencies = [ dependencies = with super; [
"vim-addon-completion" vim-addon-completion
"vim-addon-goto-thing-at-cursor" vim-addon-goto-thing-at-cursor
"vim-addon-errorformats" vim-addon-errorformats
"vim-addon-actions" vim-addon-actions
"vim-addon-mw-utils" "tlib" vim-addon-mw-utils tlib_vim
]; ];
}); });
vim-addon-sql = vim-addon-sql.overrideAttrs(old: { vim-addon-sql = super.vim-addon-sql.overrideAttrs(old: {
dependencies = ["vim-addon-completion" "vim-addon-background-cmd" "tlib"]; dependencies = with super; [ vim-addon-completion vim-addon-background-cmd tlib_vim ];
}); });
vim-addon-syntax-checker = vim-addon-syntax-checker.overrideAttrs(old: { vim-addon-syntax-checker = super.vim-addon-syntax-checker.overrideAttrs(old: {
dependencies = ["vim-addon-mw-utils" "tlib"]; dependencies = with super; [ vim-addon-mw-utils tlib_vim ];
}); });
vim-addon-toggle-buffer = vim-addon-toggle-buffer.overrideAttrs(old: { vim-addon-toggle-buffer = super.vim-addon-toggle-buffer.overrideAttrs(old: {
dependencies = [ "vim-addon-mw-utils" "tlib" ]; dependencies = with super; [ vim-addon-mw-utils tlib_vim ];
}); });
vim-addon-xdebug = vim-addon-xdebug.overrideAttrs(old: { vim-addon-xdebug = super.vim-addon-xdebug.overrideAttrs(old: {
dependencies = [ "WebAPI" "vim-addon-mw-utils" "vim-addon-signs" "vim-addon-async" ]; dependencies = with super; [ webapi-vim vim-addon-mw-utils vim-addon-signs vim-addon-async ];
}); });
vim-bazel = vim-bazel.overrideAttrs(old: { vim-bazel = super.vim-bazel.overrideAttrs(old: {
dependencies = ["maktaba"]; dependencies = with super; [ vim-maktaba ];
}); });
vim-codefmt = vim-codefmt.overrideAttrs(old: { vim-codefmt = super.vim-codefmt.overrideAttrs(old: {
dependencies = ["maktaba"]; dependencies = with super; [ vim-maktaba ];
}); });
vim-easytags = vim-easytags.overrideAttrs(old: { vim-easytags = super.vim-easytags.overrideAttrs(old: {
dependencies = ["vim-misc"]; dependencies = with super; [ vim-misc ];
}); });
# change the go_bin_path to point to a path in the nix store. See the code in # change the go_bin_path to point to a path in the nix store. See the code in
# fatih/vim-go here # fatih/vim-go here
# https://github.com/fatih/vim-go/blob/155836d47052ea9c9bac81ba3e937f6f22c8e384/autoload/go/path.vim#L154-L159 # https://github.com/fatih/vim-go/blob/155836d47052ea9c9bac81ba3e937f6f22c8e384/autoload/go/path.vim#L154-L159
vim-go = vim-go.overrideAttrs(old: let vim-go = super.vim-go.overrideAttrs(old: let
binPath = lib.makeBinPath [ binPath = lib.makeBinPath [
asmfmt asmfmt
delve delve
@ -291,7 +268,7 @@ with generated;
''; '';
}); });
vim-grammarous = vim-grammarous.overrideAttrs(old: { vim-grammarous = super.vim-grammarous.overrideAttrs(old: {
# use `:GrammarousCheck` to initialize checking # use `:GrammarousCheck` to initialize checking
# In neovim, you also want to use set # In neovim, you also want to use set
# let g:grammarous#show_first_error = 1 # let g:grammarous#show_first_error = 1
@ -304,31 +281,31 @@ with generated;
]; ];
}); });
vim-hier = vim-hier.overrideAttrs(old: { vim-hier = super.vim-hier.overrideAttrs(old: {
buildInputs = [ vim ]; buildInputs = [ vim ];
}); });
vim-isort = vim-isort.overrideAttrs(old: { vim-isort = super.vim-isort.overrideAttrs(old: {
postPatch = '' postPatch = ''
substituteInPlace ftplugin/python_vimisort.vim \ substituteInPlace ftplugin/python_vimisort.vim \
--replace 'import vim' 'import vim; import sys; sys.path.append("${pythonPackages.isort}/${python.sitePackages}")' --replace 'import vim' 'import vim; import sys; sys.path.append("${python.pkgs.isort}/${python.sitePackages}")'
''; '';
}); });
vim-snipmate = vim-snipmate.overrideAttrs(old: { vim-snipmate = super.vim-snipmate.overrideAttrs(old: {
dependencies = ["vim-addon-mw-utils" "tlib"]; dependencies = with super; [ vim-addon-mw-utils tlib_vim ];
}); });
vim-wakatime = vim-wakatime.overrideAttrs(old: { vim-wakatime = super.vim-wakatime.overrideAttrs(old: {
buildInputs = [ python ]; buildInputs = [ python ];
}); });
vim-xdebug = vim-xdebug.overrideAttrs(old: { vim-xdebug = super.vim-xdebug.overrideAttrs(old: {
postInstall = false; postInstall = false;
}); });
vim-xkbswitch = vim-xkbswitch.overrideAttrs(old: { vim-xkbswitch = super.vim-xkbswitch.overrideAttrs(old: {
patchPhase = '' patchPhase = ''
substituteInPlace plugin/xkbswitch.vim \ substituteInPlace plugin/xkbswitch.vim \
--replace /usr/local/lib/libxkbswitch.so ${xkb_switch}/lib/libxkbswitch.so --replace /usr/local/lib/libxkbswitch.so ${xkb_switch}/lib/libxkbswitch.so
@ -336,14 +313,14 @@ with generated;
buildInputs = [ xkb_switch ]; buildInputs = [ xkb_switch ];
}); });
vim-yapf = vim-yapf.overrideAttrs(old: { vim-yapf = super.vim-yapf.overrideAttrs(old: {
buildPhase = '' buildPhase = ''
substituteInPlace ftplugin/python_yapf.vim \ substituteInPlace ftplugin/python_yapf.vim \
--replace '"yapf"' '"${python3Packages.yapf}/bin/yapf"' --replace '"yapf"' '"${python3.pkgs.yapf}/bin/yapf"'
''; '';
}); });
vimproc-vim = vimproc-vim.overrideAttrs(old: { vimproc-vim = super.vimproc-vim.overrideAttrs(old: {
buildInputs = [ which ]; buildInputs = [ which ];
buildPhase = '' buildPhase = ''
@ -355,11 +332,11 @@ with generated;
''; '';
}); });
YankRing-vim = YankRing-vim.overrideAttrs(old: { YankRing-vim = super.YankRing-vim.overrideAttrs(old: {
sourceRoot = "."; sourceRoot = ".";
}); });
youcompleteme = youcompleteme.overrideAttrs(old: { youcompleteme = super.youcompleteme.overrideAttrs(old: {
buildPhase = '' buildPhase = ''
substituteInPlace plugin/youcompleteme.vim \ substituteInPlace plugin/youcompleteme.vim \
--replace "'ycm_path_to_python_interpreter', '''" \ --replace "'ycm_path_to_python_interpreter', '''" \
@ -378,9 +355,9 @@ with generated;
}; };
}); });
jedi-vim = jedi-vim.overrideAttrs(old: { jedi-vim = super.jedi-vim.overrideAttrs(old: {
# checking for python3 support in vim would be neat, too, but nobody else seems to care # checking for python3 support in vim would be neat, too, but nobody else seems to care
buildInputs = [ python3Packages.jedi ]; buildInputs = [ python3.pkgs.jedi ];
meta = { meta = {
description = "code-completion for python using python-jedi"; description = "code-completion for python using python-jedi";
license = stdenv.lib.licenses.mit; license = stdenv.lib.licenses.mit;

View file

@ -309,7 +309,8 @@ def generate_nix(plugins: List[Tuple[str, str, Plugin]]):
f.write( f.write(
f""" f"""
{plugin.normalized_name} = buildVimPluginFrom2Nix {{ {plugin.normalized_name} = buildVimPluginFrom2Nix {{
name = "{plugin.normalized_name}-{plugin.version}"; pname = "{plugin.normalized_name}";
version = "{plugin.version}";
src = fetchFromGitHub {{ src = fetchFromGitHub {{
owner = "{owner}"; owner = "{owner}";
repo = "{repo}"; repo = "{repo}";

View file

@ -197,6 +197,7 @@ navicore/vissort.vim
nbouscal/vim-stylish-haskell nbouscal/vim-stylish-haskell
ncm2/ncm2 ncm2/ncm2
ncm2/ncm2-bufword ncm2/ncm2-bufword
ncm2/ncm2-jedi
ncm2/ncm2-path ncm2/ncm2-path
ncm2/ncm2-tmux ncm2/ncm2-tmux
ncm2/ncm2-ultisnips ncm2/ncm2-ultisnips

View file

@ -150,23 +150,35 @@ vim_with_plugins can be installed like any other application within Nix.
let let
inherit (stdenv) lib; inherit (stdenv) lib;
toNames = x: # 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 []))
);
findDependenciesRecursively = knownPlugins: plugins: lib.concatMap (transitiveClosure knownPlugins) plugins;
attrnamesToPlugins = { knownPlugins, names }:
map (name: if builtins.isString name then knownPlugins.${name} else name) knownPlugins;
pluginToAttrname = plugin:
plugin.pname;
pluginsToAttrnames = plugins: map pluginToAttrname plugins;
vamDictToNames = x:
if builtins.isString x then [x] if builtins.isString x then [x]
else (lib.optional (x ? name) x.name) else (lib.optional (x ? name) x.name)
++ (x.names or []); ++ (x.names or []);
findDependenciesRecursively = {knownPlugins, names}:
let depsOf = name: (builtins.getAttr name knownPlugins).dependencies or []; rtpPath = "share/vim-plugins";
recurseNames = path: names: lib.concatMap (name: recurse ([name]++path)) names;
recurse = path:
let name = builtins.head path;
in if builtins.elem name (builtins.tail path)
then throw "recursive vim dependencies"
else [name] ++ recurseNames path (depsOf name);
in lib.uniqList { inputList = recurseNames [] names; };
vimrcFile = { vimrcFile = {
packages ? null, packages ? null,
@ -183,11 +195,11 @@ let
(let (let
knownPlugins = pathogen.knownPlugins or vimPlugins; knownPlugins = pathogen.knownPlugins or vimPlugins;
plugins = map (name: knownPlugins.${name}) (findDependenciesRecursively { inherit knownPlugins; names = pathogen.pluginNames; }); plugins = findDependenciesRecursively knownPlugins pathogen.pluginNames;
pluginsEnv = buildEnv { pluginsEnv = buildEnv {
name = "pathogen-plugin-env"; name = "pathogen-plugin-env";
paths = map (x: "${x}/${vimPlugins.rtpPath}") plugins; paths = map (x: "${x}/${rtpPath}") plugins;
}; };
in in
'' ''
@ -228,7 +240,7 @@ let
(let (let
knownPlugins = vam.knownPlugins or vimPlugins; knownPlugins = vam.knownPlugins or vimPlugins;
names = findDependenciesRecursively { inherit knownPlugins; names = lib.concatMap toNames vam.pluginDictionaries; }; plugins = findDependenciesRecursively knownPlugins (lib.concatMap vamDictToNames vam.pluginDictionaries);
# Vim almost reads JSON, so eventually JSON support should be added to Nix # Vim almost reads JSON, so eventually JSON support should be added to Nix
# TODO: proper quoting # TODO: proper quoting
@ -242,9 +254,9 @@ let
in assert builtins.hasAttr "vim-addon-manager" knownPlugins; in assert builtins.hasAttr "vim-addon-manager" knownPlugins;
'' ''
let g:nix_plugin_locations = {} let g:nix_plugin_locations = {}
${lib.concatMapStrings (name: '' ${lib.concatMapStrings (plugin: ''
let g:nix_plugin_locations['${name}'] = "${knownPlugins.${name}.rtp}" let g:nix_plugin_locations['${plugin.pname}'] = "${plugin.rtp}"
'') names} '') plugins}
let g:nix_plugin_locations['vim-addon-manager'] = "${knownPlugins."vim-addon-manager".rtp}" let g:nix_plugin_locations['vim-addon-manager'] = "${knownPlugins."vim-addon-manager".rtp}"
let g:vim_addon_manager = {} let g:vim_addon_manager = {}
@ -281,8 +293,18 @@ let
(let (let
link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}"); link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}");
packageLinks = (packageName: {start ? [], opt ? []}: packageLinks = (packageName: {start ? [], opt ? []}:
let
# `nativeImpl` expects packages to be derivations, not strings (as
# 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;
in
["mkdir -p $out/pack/${packageName}/start"] ["mkdir -p $out/pack/${packageName}/start"]
++ (builtins.map (link packageName "start") start) # To avoid confusion, even dependencies of optional plugins are added
# to `start` (except if they are explicitly listed as optional plugins).
++ (builtins.map (link packageName "start") (lib.unique (startWithDeps ++ depsOfOptionalPlugins)))
++ ["mkdir -p $out/pack/${packageName}/opt"] ++ ["mkdir -p $out/pack/${packageName}/opt"]
++ (builtins.map (link packageName "opt") opt) ++ (builtins.map (link packageName "opt") opt)
); );
@ -381,61 +403,9 @@ rec {
''; '';
}; };
rtpPath = "share/vim-plugins";
vimHelpTags = ''
vimHelpTags(){
if [ -d "$1/doc" ]; then
${vim}/bin/vim -N -u NONE -i NONE -n -E -s -c "helptags $1/doc" +quit! || echo "docs to build failed"
fi
}
'';
addRtp = path: attrs: derivation:
derivation // { rtp = "${derivation}/${path}"; } // {
overrideAttrs = f: buildVimPlugin (attrs // f attrs);
};
buildVimPlugin = a@{
name,
namePrefix ? "vimplugin-",
src,
unpackPhase ? "",
configurePhase ? "",
buildPhase ? "",
preInstall ? "",
postInstall ? "",
path ? (builtins.parseDrvName name).name,
addonInfo ? null,
...
}:
addRtp "${rtpPath}/${path}" a (stdenv.mkDerivation (a // {
name = namePrefix + name;
inherit unpackPhase configurePhase buildPhase addonInfo preInstall postInstall;
installPhase = ''
runHook preInstall
target=$out/${rtpPath}/${path}
mkdir -p $out/${rtpPath}
cp -r . $target
${vimHelpTags}
vimHelpTags $target
if [ -n "$addonInfo" ]; then
echo "$addonInfo" > $target/addon-info.json
fi
runHook postInstall
'';
}));
vim_with_vim2nix = vim_configurable.customize { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; }; vim_with_vim2nix = vim_configurable.customize { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; };
buildVimPluginFrom2Nix = a: buildVimPlugin ({ inherit (import ./build-vim-plugin.nix { inherit stdenv rtpPath vim; }) buildVimPlugin buildVimPluginFrom2Nix;
buildPhase = ":";
configurePhase =":";
} // a);
requiredPlugins = { requiredPlugins = {
packages ? {}, packages ? {},
@ -450,13 +420,13 @@ rec {
if vam != null && vam ? knownPlugins then vam.knownPlugins else if vam != null && vam ? knownPlugins then vam.knownPlugins else
if pathogen != null && pathogen ? knownPlugins then pathogen.knownPlugins else if pathogen != null && pathogen ? knownPlugins then pathogen.knownPlugins else
vimPlugins; vimPlugins;
pathogenNames = map (name: knownPlugins.${name}) (findDependenciesRecursively { inherit knownPlugins; names = pathogen.pluginNames; }); pathogenNames = findDependenciesRecursively knownPlugins pathogen.pluginNames;
vamNames = findDependenciesRecursively { inherit knownPlugins; names = lib.concatMap toNames vam.pluginDictionaries; }; vamNames = findDependenciesRecursively knownPlugins (lib.concatMap vamDictToNames vam.pluginDictionaries);
names = (lib.optionals (pathogen != null) pathogenNames) ++ names = (lib.optionals (pathogen != null) pathogenNames) ++
(lib.optionals (vam != null) vamNames); (lib.optionals (vam != null) vamNames);
nonNativePlugins = map (name: knownPlugins.${name}) names ++ (lib.optionals (plug != null) plug.plugins); nonNativePlugins = map (name: knownPlugins.${name}) names ++ (lib.optionals (plug != null) plug.plugins);
nativePluginsConfigs = lib.attrsets.attrValues packages; nativePluginsConfigs = lib.attrsets.attrValues packages;
nativePlugins = lib.concatMap ({start?[], opt?[]}: start++opt) nativePluginsConfigs; nativePlugins = lib.concatMap ({start?[], opt?[], knownPlugins?vimPlugins}: start++opt) nativePluginsConfigs;
in in
nativePlugins ++ nonNativePlugins; nativePlugins ++ nonNativePlugins;