Merge pull request #120445 from teto/vim-plugins-dict

neovimUtils: pass plugin config with plugin
launchpad/nixpkgs/master
Matthieu Coudron 3 years ago committed by GitHub
commit bffd12a4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      pkgs/applications/editors/neovim/utils.nix
  2. 27
      pkgs/applications/editors/neovim/wrapper.nix
  3. 15
      pkgs/misc/vim-plugins/vim-utils.nix
  4. 33
      pkgs/test/vim/default.nix

@ -29,6 +29,11 @@ let
, withNodeJs ? false
, withRuby ? true
# expects a list of plugin configuration
# expects { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; }
, plugins ? []
# forwarded to configure.customRC
, customRC ? ""
# same values as in vimUtils.vimrcContent
, configure ? { }
@ -44,7 +49,33 @@ let
'';
};
requiredPlugins = vimUtils.requiredPlugins configure;
# transform all plugins into an attrset
pluginsNormalized = map (x: if x ? plugin then { optional = false; } // x else { plugin = x; optional = false;}) plugins;
configurePatched = configure // {
packages.nix = {
start = lib.filter (f: f != null)
(map (x: if x.optional == false then x.plugin else null)
pluginsNormalized);
opt = lib.filter (f: f != null)
(map (x: if x.optional == true then x.plugin else null)
pluginsNormalized);
};
customRC = pluginRc + customRC;
};
# A function to get the configuration string (if any) from an element of 'plugins'
pluginConfig = p:
if (p.config or "") != "" then ''
" ${p.plugin.pname or p.plugin.name} {{{
${p.config}
" }}}
'' else "";
pluginRc = lib.concatMapStrings pluginConfig pluginsNormalized;
requiredPlugins = vimUtils.requiredPlugins configurePatched;
getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));
pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins;
@ -89,12 +120,13 @@ let
"--suffix" "PATH" ":" binPath
];
manifestRc = vimUtils.vimrcContent (configure // { customRC = ""; });
neovimRcContent = vimUtils.vimrcContent configure;
manifestRc = vimUtils.vimrcContent (configurePatched // { customRC = ""; }) ;
neovimRcContent = vimUtils.vimrcContent configurePatched;
in
assert withPython2 -> throw "Python2 support has been removed from neovim, please remove withPython2 and extraPython2Packages.";
args // {
builtins.removeAttrs args ["plugins"] // {
wrapperArgs = makeWrapperArgs;
inherit neovimRcContent;
inherit manifestRc;

@ -11,8 +11,9 @@ neovim:
let
wrapper = {
# should contain all args but the binary
wrapperArgs ? ""
extraName ? ""
# should contain all args but the binary. Can be either a string or list
, wrapperArgs ? []
, manifestRc ? null
, withPython2 ? false
, withPython3 ? true, python3Env ? null
@ -20,10 +21,18 @@ let
, rubyEnv ? null
, vimAlias ? false
, viAlias ? false
# additional argument not generated by makeNeovimConfig
# it will append "-u <customRc>" to the wrapped arguments
# set to false if you want to control where to save the generated config
# (e.g., in ~/.config/init.vim or project/.nvimrc)
, wrapRc ? true
, ...
}:
}@args:
let
wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
# If configure != {}, we can't generate the rplugin.vim file with e.g
# NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
# the wrapper. That's why only when configure != {} (tested both here and
@ -31,13 +40,15 @@ let
# wrapper with most arguments we need, excluding those that cause problems to
# generate rplugin.vim, but still required for the final wrapper.
finalMakeWrapperArgs =
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ] ++
[ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ];
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" args.neovimRcContent}" ]
;
in
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
symlinkJoin {
name = "neovim-${lib.getVersion neovim}";
name = "neovim-${lib.getVersion neovim}${extraName}";
# Remove the symlinks created by symlinkJoin which we need to perform
# extra actions upon
postBuild = lib.optionalString stdenv.isLinux ''
@ -66,7 +77,7 @@ let
in ''
echo "Generating remote plugin manifest"
export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgs}
makeWrapper ${lib.escapeShellArgs manifestWrapperArgs} ${wrapperArgsStr}
# Some plugins assume that the home directory is accessible for
# initializing caches, temporary files, etc. Even if the plugin isn't
@ -96,7 +107,7 @@ let
'')
+ ''
rm $out/bin/nvim
makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgs}
makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr}
'';
paths = [ neovim ];

@ -232,8 +232,7 @@ let
let
/* pathogen mostly can set &rtp at startup time. Its used very commonly.
*/
pathogenImpl = lib.optionalString (pathogen != null)
(let
pathogenImpl = let
knownPlugins = pathogen.knownPlugins or vimPlugins;
plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames);
@ -244,15 +243,15 @@ let
};
in
''
let &rtp.=(empty(&rtp)?"":',')."${vimPlugins.pathogen.rtp}"
let &rtp.=(empty(&rtp)?"":',')."${vimPlugins.vim-pathogen.rtp}"
execute pathogen#infect('${pluginsEnv}/{}')
filetype indent plugin on | syn on
'');
'';
/* vim-plug is an extremely popular vim plugin manager.
*/
plugImpl = lib.optionalString (plug != null)
plugImpl =
(''
source ${vimPlugins.vim-plug.rtp}/plug.vim
call plug#begin('/dev/null')
@ -340,10 +339,12 @@ let
entries = [
beforePlugins
vamImpl pathogenImpl plugImpl
vamImpl
(nativeImpl packages)
customRC
];
]
++ lib.optional (pathogen != null) pathogenImpl
++ lib.optional (plug != null) plugImpl;
in
lib.concatStringsSep "\n" (lib.filter (x: x != null && x != "") entries);

@ -1,14 +1,43 @@
{ vimUtils, vim_configurable, neovim, vimPlugins
, lib, fetchFromGitHub,
{ vimUtils, vim_configurable, writeText, neovim, vimPlugins
, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable
, neovim-unwrapped
}:
let
inherit (vimUtils) buildVimPluginFrom2Nix;
packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
plugins = with vimPlugins; [
{
plugin = vim-obsession;
config = ''
map <Leader>$ <Cmd>Obsession<CR>
'';
}
];
nvimConfNix = neovimUtils.makeNeovimConfig {
inherit plugins;
customRC = ''
" just a comment
'';
};
wrapNeovim = suffix: config:
wrapNeovimUnstable neovim-unwrapped (config // {
extraName = suffix;
wrapRc = true;
});
in
{
vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
### neovim tests
##################
nvim_with_plugins = wrapNeovim "-with-plugins" nvimConfNix;
### vim tests
##################
vim_with_vim2nix = vim_configurable.customize {
name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ];
};

Loading…
Cancel
Save