vimUtils: represent vim plugins as derivations

Vim plugins were previously represented as strings by default,
necessitating a `knownPlugins` set. Backwards compatibility is kept
(strings are still accepted), so vam plugins should continue to work.
This commit is contained in:
Timo Kaufmann 2018-12-24 13:02:31 +01:00
parent ce7899bea5
commit b352318cd1
4 changed files with 483 additions and 99 deletions

File diff suppressed because it is too large Load Diff

View File

@ -25,14 +25,30 @@ in
generated: generated:
with generated; rec {
{ # list of plugins that are needed as dependencies somewhere
# This is necessary (as opposed to `with generated;`) because
# there would otherwise be conflicts with `rec`. `rec` is necessary
# however to make sure overriden plugins can be used as dependencies.
# This should use a proper package set with fixed-points instead.
inherit (generated)
self
webapi-vim
nvim-yarp
ultisnips
vim-addon-mw-utils
tlib_vim
vim-addon-signs
vim-addon-other
vim-addon-errorformats
vim-maktaba
vim-misc;
vim2nix = buildVimPluginFrom2Nix { vim2nix = buildVimPluginFrom2Nix {
name = "vim2nix"; name = "vim2nix";
src = ./vim2nix; src = ./vim2nix;
dependencies = ["vim-addon-manager"]; dependencies = [ vim-addon-manager ];
}; };
fzfWrapper = buildVimPluginFrom2Nix { fzfWrapper = buildVimPluginFrom2Nix {
@ -90,7 +106,7 @@ with generated;
dependencies = []; dependencies = [];
}; };
clang_complete = clang_complete.overrideAttrs(old: { clang_complete = generated.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 +123,14 @@ with generated;
''; '';
}); });
clighter8 = clighter8.overrideAttrs(old: { clighter8 = generated.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 = generated.command-t.overrideAttrs(old: {
buildInputs = [ ruby rake ]; buildInputs = [ ruby rake ];
buildPhase = '' buildPhase = ''
rake make rake make
@ -122,7 +138,7 @@ with generated;
''; '';
}); });
cpsm = cpsm.overrideAttrs(old: { cpsm = generated.cpsm.overrideAttrs(old: {
buildInputs = [ buildInputs = [
python3 python3
stdenv stdenv
@ -138,7 +154,7 @@ with generated;
''; '';
}); });
ctrlp-cmatcher = ctrlp-cmatcher.overrideAttrs(old: { ctrlp-cmatcher = generated.ctrlp-cmatcher.overrideAttrs(old: {
buildInputs = [ python ]; buildInputs = [ python ];
buildPhase = '' buildPhase = ''
patchShebangs . patchShebangs .
@ -146,7 +162,7 @@ with generated;
''; '';
}); });
deoplete-go = deoplete-go.overrideAttrs(old: { deoplete-go = generated.deoplete-go.overrideAttrs(old: {
buildInputs = [ python3 ]; buildInputs = [ python3 ];
buildPhase = '' buildPhase = ''
pushd ./rplugin/python3/deoplete/ujson pushd ./rplugin/python3/deoplete/ujson
@ -156,37 +172,33 @@ with generated;
''; '';
}); });
ensime-vim = ensime-vim.overrideAttrs(old: { ensime-vim = generated.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 = [ vimproc-vim vimshell-vim self forms ];
}); });
forms = forms.overrideAttrs(old: { forms = generated.forms.overrideAttrs(old: {
dependencies = ["self"]; dependencies = [ self ];
}); });
gist-vim = gist-vim.overrideAttrs(old: { gist-vim = generated.gist-vim.overrideAttrs(old: {
dependencies = ["webapi-vim"]; dependencies = [ webapi-vim ];
}); });
gitv = gitv.overrideAttrs(old: { ncm2 = generated.ncm2.overrideAttrs(old: {
dependencies = ["gitv"]; dependencies = [ nvim-yarp ];
}); });
ncm2 = ncm2.overrideAttrs(old: { ncm2-jedi = generated.ncm2-jedi.overrideAttrs(old: {
dependencies = ["nvim-yarp"]; dependencies = [ nvim-yarp ncm2 ];
});
ncm2-jedi = ncm2-jedi.overrideAttrs(old: {
dependencies = ["nvim-yarp" "ncm2"];
passthru.python3Dependencies = ps: with ps; [ jedi ]; passthru.python3Dependencies = ps: with ps; [ jedi ];
}); });
ncm2-ultisnips = ncm2-ultisnips.overrideAttrs(old: { ncm2-ultisnips = generated.ncm2-ultisnips.overrideAttrs(old: {
dependencies = ["ultisnips"]; dependencies = [ ultisnips ];
}); });
taglist-vim = taglist-vim.overrideAttrs(old: { taglist-vim = generated.taglist-vim.overrideAttrs(old: {
setSourceRoot = '' setSourceRoot = ''
export sourceRoot=taglist export sourceRoot=taglist
mkdir taglist mkdir taglist
@ -195,80 +207,80 @@ with generated;
''; '';
}); });
vimshell-vim = vimshell-vim.overrideAttrs(old: { vimshell-vim = generated.vimshell-vim.overrideAttrs(old: {
dependencies = [ "vimproc-vim" ]; dependencies = [ vimproc-vim ];
}); });
vim-addon-manager = vim-addon-manager.overrideAttrs(old: { vim-addon-manager = generated.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 = generated.vim-addon-actions.overrideAttrs(old: {
dependencies = [ "vim-addon-mw-utils" "tlib" ]; dependencies = [ vim-addon-mw-utils tlib_vim ];
}); });
vim-addon-async = vim-addon-async.overrideAttrs(old: { vim-addon-async = generated.vim-addon-async.overrideAttrs(old: {
dependencies = [ "vim-addon-signs" ]; dependencies = [ vim-addon-signs ];
}); });
vim-addon-background-cmd = vim-addon-background-cmd.overrideAttrs(old: { vim-addon-background-cmd = generated.vim-addon-background-cmd.overrideAttrs(old: {
dependencies = [ "vim-addon-mw-utils" ]; dependencies = [ vim-addon-mw-utils ];
}); });
vim-addon-completion = vim-addon-completion.overrideAttrs(old: { vim-addon-completion = generated.vim-addon-completion.overrideAttrs(old: {
dependencies = [ "tlib" ]; dependencies = [ tlib_vim ];
}); });
vim-addon-goto-thing-at-cursor = vim-addon-goto-thing-at-cursor.overrideAttrs(old: { vim-addon-goto-thing-at-cursor = generated.vim-addon-goto-thing-at-cursor.overrideAttrs(old: {
dependencies = [ "tlib" ]; dependencies = [ tlib_vim ];
}); });
vim-addon-mru = vim-addon-mru.overrideAttrs(old: { vim-addon-mru = generated.vim-addon-mru.overrideAttrs(old: {
dependencies = ["vim-addon-other" "vim-addon-mw-utils"]; dependencies = [ vim-addon-other vim-addon-mw-utils ];
}); });
vim-addon-nix = vim-addon-nix.overrideAttrs(old: { vim-addon-nix = generated.vim-addon-nix.overrideAttrs(old: {
dependencies = [ dependencies = [
"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 = generated.vim-addon-sql.overrideAttrs(old: {
dependencies = ["vim-addon-completion" "vim-addon-background-cmd" "tlib"]; dependencies = [ vim-addon-completion vim-addon-background-cmd tlib_vim ];
}); });
vim-addon-syntax-checker = vim-addon-syntax-checker.overrideAttrs(old: { vim-addon-syntax-checker = generated.vim-addon-syntax-checker.overrideAttrs(old: {
dependencies = ["vim-addon-mw-utils" "tlib"]; dependencies = [ vim-addon-mw-utils tlib_vim ];
}); });
vim-addon-toggle-buffer = vim-addon-toggle-buffer.overrideAttrs(old: { vim-addon-toggle-buffer = generated.vim-addon-toggle-buffer.overrideAttrs(old: {
dependencies = [ "vim-addon-mw-utils" "tlib" ]; dependencies = [ vim-addon-mw-utils tlib_vim ];
}); });
vim-addon-xdebug = vim-addon-xdebug.overrideAttrs(old: { vim-addon-xdebug = generated.vim-addon-xdebug.overrideAttrs(old: {
dependencies = [ "WebAPI" "vim-addon-mw-utils" "vim-addon-signs" "vim-addon-async" ]; dependencies = [ webapi-vim vim-addon-mw-utils vim-addon-signs vim-addon-async ];
}); });
vim-bazel = vim-bazel.overrideAttrs(old: { vim-bazel = generated.vim-bazel.overrideAttrs(old: {
dependencies = ["maktaba"]; dependencies = [ vim-maktaba ];
}); });
vim-codefmt = vim-codefmt.overrideAttrs(old: { vim-codefmt = generated.vim-codefmt.overrideAttrs(old: {
dependencies = ["maktaba"]; dependencies = [ vim-maktaba ];
}); });
vim-easytags = vim-easytags.overrideAttrs(old: { vim-easytags = generated.vim-easytags.overrideAttrs(old: {
dependencies = ["vim-misc"]; dependencies = [ 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 = generated.vim-go.overrideAttrs(old: let
binPath = lib.makeBinPath [ binPath = lib.makeBinPath [
asmfmt asmfmt
delve delve
@ -296,7 +308,7 @@ with generated;
''; '';
}); });
vim-grammarous = vim-grammarous.overrideAttrs(old: { vim-grammarous = generated.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
@ -309,31 +321,31 @@ with generated;
]; ];
}); });
vim-hier = vim-hier.overrideAttrs(old: { vim-hier = generated.vim-hier.overrideAttrs(old: {
buildInputs = [ vim ]; buildInputs = [ vim ];
}); });
vim-isort = vim-isort.overrideAttrs(old: { vim-isort = generated.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("${pythonPackages.isort}/${python.sitePackages}")'
''; '';
}); });
vim-snipmate = vim-snipmate.overrideAttrs(old: { vim-snipmate = generated.vim-snipmate.overrideAttrs(old: {
dependencies = ["vim-addon-mw-utils" "tlib"]; dependencies = [ vim-addon-mw-utils tlib_vim ];
}); });
vim-wakatime = vim-wakatime.overrideAttrs(old: { vim-wakatime = generated.vim-wakatime.overrideAttrs(old: {
buildInputs = [ python ]; buildInputs = [ python ];
}); });
vim-xdebug = vim-xdebug.overrideAttrs(old: { vim-xdebug = generated.vim-xdebug.overrideAttrs(old: {
postInstall = false; postInstall = false;
}); });
vim-xkbswitch = vim-xkbswitch.overrideAttrs(old: { vim-xkbswitch = generated.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
@ -341,14 +353,14 @@ with generated;
buildInputs = [ xkb_switch ]; buildInputs = [ xkb_switch ];
}); });
vim-yapf = vim-yapf.overrideAttrs(old: { vim-yapf = generated.vim-yapf.overrideAttrs(old: {
buildPhase = '' buildPhase = ''
substituteInPlace ftplugin/python_yapf.vim \ substituteInPlace ftplugin/python_yapf.vim \
--replace '"yapf"' '"${python3Packages.yapf}/bin/yapf"' --replace '"yapf"' '"${python3Packages.yapf}/bin/yapf"'
''; '';
}); });
vimproc-vim = vimproc-vim.overrideAttrs(old: { vimproc-vim = generated.vimproc-vim.overrideAttrs(old: {
buildInputs = [ which ]; buildInputs = [ which ];
buildPhase = '' buildPhase = ''
@ -360,11 +372,11 @@ with generated;
''; '';
}); });
YankRing-vim = YankRing-vim.overrideAttrs(old: { YankRing-vim = generated.YankRing-vim.overrideAttrs(old: {
sourceRoot = "."; sourceRoot = ".";
}); });
youcompleteme = youcompleteme.overrideAttrs(old: { youcompleteme = generated.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', '''" \
@ -383,7 +395,7 @@ with generated;
}; };
}); });
jedi-vim = jedi-vim.overrideAttrs(old: { jedi-vim = generated.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 = [ python3Packages.jedi ];
meta = { meta = {

View File

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

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 = {}
@ -381,8 +393,6 @@ rec {
''; '';
}; };
rtpPath = "share/vim-plugins";
vimHelpTags = '' vimHelpTags = ''
vimHelpTags(){ vimHelpTags(){
if [ -d "$1/doc" ]; then if [ -d "$1/doc" ]; then
@ -450,13 +460,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;