neovimUtils: makeNeovimConfig accepts plugins/customRc
mimics home-manager interface and makes it easier to associate configs with plugins. Added a test as well.
This commit is contained in:
parent
abb1e5cd4c
commit
7836469dbe
|
@ -29,6 +29,11 @@ let
|
||||||
, withNodeJs ? false
|
, withNodeJs ? false
|
||||||
, withRuby ? true
|
, 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
|
# same values as in vimUtils.vimrcContent
|
||||||
, configure ? { }
|
, 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 (_: [ ]));
|
getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));
|
||||||
|
|
||||||
pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins;
|
pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins;
|
||||||
|
@ -89,12 +120,13 @@ let
|
||||||
"--suffix" "PATH" ":" binPath
|
"--suffix" "PATH" ":" binPath
|
||||||
];
|
];
|
||||||
|
|
||||||
manifestRc = vimUtils.vimrcContent (configure // { customRC = ""; });
|
|
||||||
neovimRcContent = vimUtils.vimrcContent configure;
|
manifestRc = vimUtils.vimrcContent (configurePatched // { customRC = ""; }) ;
|
||||||
|
neovimRcContent = vimUtils.vimrcContent configurePatched;
|
||||||
in
|
in
|
||||||
assert withPython2 -> throw "Python2 support has been removed from neovim, please remove withPython2 and extraPython2Packages.";
|
assert withPython2 -> throw "Python2 support has been removed from neovim, please remove withPython2 and extraPython2Packages.";
|
||||||
|
|
||||||
args // {
|
builtins.removeAttrs args ["plugins"] // {
|
||||||
wrapperArgs = makeWrapperArgs;
|
wrapperArgs = makeWrapperArgs;
|
||||||
inherit neovimRcContent;
|
inherit neovimRcContent;
|
||||||
inherit manifestRc;
|
inherit manifestRc;
|
||||||
|
|
|
@ -232,8 +232,7 @@ let
|
||||||
let
|
let
|
||||||
/* pathogen mostly can set &rtp at startup time. Its used very commonly.
|
/* pathogen mostly can set &rtp at startup time. Its used very commonly.
|
||||||
*/
|
*/
|
||||||
pathogenImpl = lib.optionalString (pathogen != null)
|
pathogenImpl = let
|
||||||
(let
|
|
||||||
knownPlugins = pathogen.knownPlugins or vimPlugins;
|
knownPlugins = pathogen.knownPlugins or vimPlugins;
|
||||||
|
|
||||||
plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames);
|
plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames);
|
||||||
|
@ -248,11 +247,11 @@ let
|
||||||
execute pathogen#infect('${pluginsEnv}/{}')
|
execute pathogen#infect('${pluginsEnv}/{}')
|
||||||
|
|
||||||
filetype indent plugin on | syn on
|
filetype indent plugin on | syn on
|
||||||
'');
|
'';
|
||||||
|
|
||||||
/* vim-plug is an extremely popular vim plugin manager.
|
/* vim-plug is an extremely popular vim plugin manager.
|
||||||
*/
|
*/
|
||||||
plugImpl = lib.optionalString (plug != null)
|
plugImpl =
|
||||||
(''
|
(''
|
||||||
source ${vimPlugins.vim-plug.rtp}/plug.vim
|
source ${vimPlugins.vim-plug.rtp}/plug.vim
|
||||||
call plug#begin('/dev/null')
|
call plug#begin('/dev/null')
|
||||||
|
@ -340,10 +339,12 @@ let
|
||||||
|
|
||||||
entries = [
|
entries = [
|
||||||
beforePlugins
|
beforePlugins
|
||||||
vamImpl pathogenImpl plugImpl
|
vamImpl
|
||||||
(nativeImpl packages)
|
(nativeImpl packages)
|
||||||
customRC
|
customRC
|
||||||
];
|
]
|
||||||
|
++ lib.optional (pathogen != null) pathogenImpl
|
||||||
|
++ lib.optional (plug != null) plugImpl;
|
||||||
|
|
||||||
in
|
in
|
||||||
lib.concatStringsSep "\n" (lib.filter (x: x != null && x != "") entries);
|
lib.concatStringsSep "\n" (lib.filter (x: x != null && x != "") entries);
|
||||||
|
|
|
@ -1,14 +1,45 @@
|
||||||
{ vimUtils, vim_configurable, neovim, vimPlugins
|
{ vimUtils, vim_configurable, writeText, neovim, vimPlugins
|
||||||
, lib, fetchFromGitHub,
|
, lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable
|
||||||
|
, neovim-unwrapped
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (vimUtils) buildVimPluginFrom2Nix;
|
inherit (vimUtils) buildVimPluginFrom2Nix;
|
||||||
|
|
||||||
packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
|
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;
|
||||||
|
wrapperArgs = lib.escapeShellArgs (config.wrapperArgs ++
|
||||||
|
["--add-flags" "-u ${writeText "init.vim" config.neovimRcContent}"]
|
||||||
|
);
|
||||||
|
});
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
|
vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
|
||||||
|
|
||||||
|
### neovim tests
|
||||||
|
##############3
|
||||||
|
nvim_with_plugins = wrapNeovim "-with-plugins" nvimConfNix;
|
||||||
|
|
||||||
|
### vim tests
|
||||||
|
##############3
|
||||||
vim_with_vim2nix = vim_configurable.customize {
|
vim_with_vim2nix = vim_configurable.customize {
|
||||||
name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ];
|
name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue