From 7836469dbe40783c640e2c0fafd2e55248ffea31 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 21 May 2021 12:48:43 +0200 Subject: neovimUtils: makeNeovimConfig accepts plugins/customRc mimics home-manager interface and makes it easier to associate configs with plugins. Added a test as well. --- pkgs/test/vim/default.nix | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'pkgs/test') diff --git a/pkgs/test/vim/default.nix b/pkgs/test/vim/default.nix index 4ca004a60c3..9128e1bcb11 100644 --- a/pkgs/test/vim/default.nix +++ b/pkgs/test/vim/default.nix @@ -1,14 +1,45 @@ -{ 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 $ Obsession + ''; + } + ]; + + 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 { 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 { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; }; -- cgit 1.4.1 From 4a860879ea76c2be86a696cb885cc51bfe8f61fa Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Tue, 25 May 2021 22:37:57 +0200 Subject: wrapNeovimUnstable: accept a wrapRc boolean additional argument not generated by makeNeovimConfig If true (the default), appends "-u " 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) --- pkgs/applications/editors/neovim/wrapper.nix | 24 +++++++++++++++++------- pkgs/test/vim/default.nix | 8 +++----- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'pkgs/test') diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index 1feb21387ea..4defc2d4327 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -12,8 +12,8 @@ neovim: let wrapper = { extraName ? "" - # should contain all args but the binary - , wrapperArgs ? "" + # should contain all args but the binary. Can be either a string or list + , wrapperArgs ? [] , manifestRc ? null , withPython2 ? false , withPython3 ? true, python3Env ? null @@ -21,10 +21,18 @@ let , rubyEnv ? null , vimAlias ? false , viAlias ? false + + # additional argument not generated by makeNeovimConfig + # it will append "-u " 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 @@ -32,8 +40,10 @@ 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."; @@ -67,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 @@ -97,7 +107,7 @@ let '') + '' rm $out/bin/nvim - makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgs} + makeWrapper ${lib.escapeShellArgs finalMakeWrapperArgs} ${wrapperArgsStr} ''; paths = [ neovim ]; diff --git a/pkgs/test/vim/default.nix b/pkgs/test/vim/default.nix index 9128e1bcb11..c75836aa9a8 100644 --- a/pkgs/test/vim/default.nix +++ b/pkgs/test/vim/default.nix @@ -26,20 +26,18 @@ let wrapNeovim = suffix: config: wrapNeovimUnstable neovim-unwrapped (config // { extraName = suffix; - wrapperArgs = lib.escapeShellArgs (config.wrapperArgs ++ - ["--add-flags" "-u ${writeText "init.vim" config.neovimRcContent}"] - ); + wrapRc = true; }); in { 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 { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; }; -- cgit 1.4.1