From 8e8a09bfc9546edca6623f713bd1be2cb544da21 Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Mon, 24 Dec 2018 13:13:59 +0100 Subject: [PATCH] vimUtils: add dependency logic to nativeImpl nativeImpl previously simply ignored dependency information. --- doc/languages-frameworks/vim.section.md | 7 ++++++- pkgs/misc/vim-plugins/vim-utils.nix | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/languages-frameworks/vim.section.md b/doc/languages-frameworks/vim.section.md index 2cec1543a24..6ed60028ae2 100644 --- a/doc/languages-frameworks/vim.section.md +++ b/doc/languages-frameworks/vim.section.md @@ -48,7 +48,7 @@ neovim.override { ## 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 { @@ -56,6 +56,8 @@ vim_configurable.customize { # loaded on launch start = [ youcompleteme fugitive ]; # 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 ]; # To automatically load a plugin when opening a filetype, add vimrc lines like: # 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: ``` @@ -74,6 +77,8 @@ neovim.override { packages.myVimPackage = with pkgs.vimPlugins; { # see examples below how to use custom packages 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 = [ ]; }; }; diff --git a/pkgs/misc/vim-plugins/vim-utils.nix b/pkgs/misc/vim-plugins/vim-utils.nix index 59d1a980e88..a8146dbf5d4 100644 --- a/pkgs/misc/vim-plugins/vim-utils.nix +++ b/pkgs/misc/vim-plugins/vim-utils.nix @@ -293,8 +293,18 @@ let (let link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}"); 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"] - ++ (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"] ++ (builtins.map (link packageName "opt") opt) );