diff options
Diffstat (limited to 'pkgs/applications/editors')
-rw-r--r-- | pkgs/applications/editors/neovim/neovim-override.vim | 6 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/tests.nix | 16 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/utils.nix | 97 | ||||
-rw-r--r-- | pkgs/applications/editors/vim/plugins/vim-utils.nix | 74 |
4 files changed, 68 insertions, 125 deletions
diff --git a/pkgs/applications/editors/neovim/neovim-override.vim b/pkgs/applications/editors/neovim/neovim-override.vim index 34a1a8f1f432..04ee66760185 100644 --- a/pkgs/applications/editors/neovim/neovim-override.vim +++ b/pkgs/applications/editors/neovim/neovim-override.vim @@ -1,7 +1 @@ -" configuration generated by NIX -set nocompatible - -set packpath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir -set runtimepath^=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vim-pack-dir - :help ale diff --git a/pkgs/applications/editors/neovim/tests.nix b/pkgs/applications/editors/neovim/tests.nix index 3163041dabfe..3f38abee5005 100644 --- a/pkgs/applications/editors/neovim/tests.nix +++ b/pkgs/applications/editors/neovim/tests.nix @@ -86,9 +86,11 @@ rec { nvim_with_plug = neovim.override { extraName = "-with-plug"; - configure.plug.plugins = with pkgs.vimPlugins; [ - (base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; })) - ]; + configure.packages.plugins = with pkgs.vimPlugins; { + start = [ + (base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; })) + ]; + }; configure.customRC = '' color base16-tomorrow-night set background=dark @@ -123,7 +125,7 @@ rec { }); force-nowrap = runTest nvimDontWrap '' - ! grep "-u" ${nvimDontWrap}/bin/nvim + ! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim ''; nvim_via_override-test = runTest nvim_via_override '' @@ -154,12 +156,6 @@ rec { configure.packages.foo.start = with vimPlugins; [ deoplete-nvim ]; }; - # only neovim makes use of `requiredPlugins`, test this here - test_nvim_with_vim_nix_using_pathogen = neovim.override { - extraName = "-pathogen"; - configure.pathogen.pluginNames = [ "vim-nix" ]; - }; - nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig { extraLuaPackages = ps: [ps.mpack]; customRC = '' diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 16b19f63d2d3..c3e41966534e 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -11,21 +11,18 @@ , wrapNeovimUnstable }: let - # returns everything needed for the caller to wrap its own neovim: - # - the generated content of the future init.vim - # - the arguments to wrap neovim with - # The caller is responsible for writing the init.vim and adding it to the wrapped - # arguments (["-u" writeText "init.vim" GENERATEDRC)]). - # This makes it possible to write the config anywhere: on a per-project basis - # .nvimrc or in $XDG_CONFIG_HOME/nvim/init.vim to avoid sideeffects. - # Indeed, note that wrapping with `-u init.vim` has sideeffects like .nvimrc wont be loaded - # anymore, $MYVIMRC wont be set etc + /* returns everything needed for the caller to wrap its own neovim: + - the generated content of the future init.vim + - the arguments to wrap neovim with + The caller is responsible for writing the init.vim and adding it to the wrapped + arguments (["-u" writeText "init.vim" GENERATEDRC)]). + This makes it possible to write the config anywhere: on a per-project basis + .nvimrc or in $XDG_CONFIG_HOME/nvim/init.vim to avoid sideeffects. + Indeed, note that wrapping with `-u init.vim` has sideeffects like .nvimrc wont be loaded + anymore, $MYVIMRC wont be set etc + */ makeNeovimConfig = - { - withPython2 ? false - /* the function you would have passed to python.withPackages */ - , extraPython2Packages ? (_: [ ]) - , withPython3 ? true + { withPython3 ? true /* the function you would have passed to python3.withPackages */ , extraPython3Packages ? (_: [ ]) , withNodeJs ? false @@ -36,10 +33,8 @@ let # expects a list of plugin configuration # expects { plugin=far-vim; config = "let g:far#source='rg'"; optional = false; } , plugins ? [] - # forwarded to configure.customRC + # custom viml config appended after plugin-specific config , customRC ? "" - # same values as in vimUtils.vimrcContent - , configure ? { } # for forward compability, when adding new environments, haskell etc. , ... @@ -54,25 +49,20 @@ let }; # transform all plugins into an attrset - pluginsNormalized = map (x: if x ? plugin then { optional = false; } // x else { plugin = x; optional = false;}) plugins; - + # { optional = bool; plugin = package; dest = filename; } + pluginsNormalized = map (x: if x ? plugin then { dest = "init.vim"; optional = false; } // x else { plugin = x; optional = false;}) plugins; - configurePatched = configure // { - customRC = pluginRc + customRC + (configure.customRC or ""); - }; - # 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; + pluginRC = lib.concatMapStrings (p: p.config or "") pluginsNormalized; - requiredPlugins = vimUtils.requiredPlugins configurePatched; + pluginsPartitioned = lib.partition (x: x.optional == true) pluginsNormalized; + requiredPlugins = vimUtils.requiredPluginsForPackage myVimPackage; getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ])); + myVimPackage = { + start = map (x: x.plugin) pluginsPartitioned.wrong; + opt = map (x: x.plugin) pluginsPartitioned.right; + }; pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins; python3Env = python3Packages.python.withPackages (ps: @@ -102,12 +92,16 @@ let let binPath = lib.makeBinPath (lib.optionals withRuby [ rubyEnv ] ++ lib.optionals withNodeJs [ nodejs ]); - flags = lib.concatLists (lib.mapAttrsToList ( - prog: withProg: [ - "--cmd" (genProviderSettings prog withProg) - ] - ) - hostprog_check_table); + hostProviderViml = lib.mapAttrsToList genProviderSettings hostprog_check_table; + + # as expected by packdir + packDirArgs.myNeovimPackages = myVimPackage; + + # vim accepts a limited number of commands so we join them all + flags = [ + "--cmd" (lib.intersperse "|" hostProviderViml) + "--cmd" "set packpath^=${vimUtils.packDir packDirArgs}" + ]; in [ "--inherit-argv0" "--add-flags" (lib.escapeShellArgs flags) @@ -120,11 +114,10 @@ let "--prefix" "LUA_CPATH" ";" (neovim-unwrapped.lua.pkgs.lib.genLuaCPathAbsStr luaEnv) ]; - - manifestRc = vimUtils.vimrcContent (configurePatched // { customRC = ""; }) ; - neovimRcContent = vimUtils.vimrcContent configurePatched; + manifestRc = vimUtils.vimrcContent ({ customRC = ""; }) ; + # we call vimrcContent without 'packages' to avoid the init.vim generation + neovimRcContent = vimUtils.vimrcContent ({ beforePlugins = ""; customRC = pluginRC + customRC; packages = null; }); in - assert withPython2 -> throw "Python2 support has been removed from neovim, please remove withPython2 and extraPython2Packages."; builtins.removeAttrs args ["plugins"] // { wrapperArgs = makeWrapperArgs; @@ -144,10 +137,9 @@ let "let g:loaded_${prog}_provider=0" ; - # to keep backwards compatibility + # to keep backwards compatibility for people using neovim.override legacyWrapper = neovim: { extraMakeWrapperArgs ? "" - , withPython ? false /* the function you would have passed to python.withPackages */ , extraPythonPackages ? (_: []) /* the function you would have passed to python.withPackages */ @@ -162,22 +154,25 @@ let , extraName ? "" }: let - /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */ - compatFun = funOrList: (if builtins.isList funOrList then - (_: lib.warn "passing a list as extraPythonPackages to the neovim wrapper is deprecated, pass a function as to python.withPackages instead" funOrList) - else funOrList); + + # we convert from the old configure.format to + plugins = if builtins.hasAttr "plug" configure then + throw "The neovim legacy wrapper doesn't support configure.plug anymore, please setup your plugins via 'configure.packages' instead" + else + lib.flatten (lib.mapAttrsToList genPlugin (configure.packages or {})); + genPlugin = packageName: {start ? [], opt?[]}: + start ++ opt; res = makeNeovimConfig { inherit withPython3; - extraPython3Packages = compatFun extraPython3Packages; + inherit extraPython3Packages; inherit extraLuaPackages; inherit withNodeJs withRuby viAlias vimAlias; - inherit configure; + customRC = configure.customRC or ""; + inherit plugins; inherit extraName; }; in - assert withPython -> throw "Python2 support has been removed from neovim, please remove withPython and extraPythonPackages."; - wrapNeovimUnstable neovim (res // { wrapperArgs = lib.escapeShellArgs res.wrapperArgs + " " + extraMakeWrapperArgs; wrapRc = (configure != {}); diff --git a/pkgs/applications/editors/vim/plugins/vim-utils.nix b/pkgs/applications/editors/vim/plugins/vim-utils.nix index 60d4856cae6f..d11d638f4a02 100644 --- a/pkgs/applications/editors/vim/plugins/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/vim-utils.nix @@ -3,7 +3,6 @@ , runCommand, makeWrapper , nix-prefetch-hg, nix-prefetch-git , fetchFromGitHub, runtimeShell -, hasLuaModule , python3 , callPackage, makeSetupHook }: @@ -52,8 +51,6 @@ this to your .vimrc should make most plugins work: set rtp+=~/.nix-profile/share/vim-plugins/youcompleteme " or for p in ["youcompleteme"] | exec 'set rtp+=~/.nix-profile/share/vim-plugins/'.p | endfor -which is what the [VAM]/pathogen solutions above basically do. - Learn about about plugin Vim plugin mm managers at http://vim-wiki.mawercer.de/wiki/topic/vim%20plugin%20managment.html. @@ -168,16 +165,13 @@ let rtpPath = "."; - # Generates a packpath folder as expected by vim + /* Generates a packpath folder as expected by vim + Example: + packDir (myVimPackage.{ start = [ vimPlugins.vim-fugitive ]; opt = [] }) + => "/nix/store/xxxxx-pack-dir" + */ packDir = packages: let - # dir is "start" or "opt" - linkLuaPlugin = plugin: packageName: dir: '' - mkdir -p $out/pack/${packageName}/${dir}/${plugin.pname}/lua - ln -sf ${plugin}/share/lua/5.1/* $out/pack/${packageName}/${dir}/${plugin.pname}/lua - ln -sf ${plugin}/${plugin.pname}-${plugin.version}-rocks/${plugin.pname}/${plugin.version}/* $out/pack/${packageName}/${dir}/${plugin.pname}/ - ''; - linkVimlPlugin = plugin: packageName: dir: '' mkdir -p $out/pack/${packageName}/${dir} if test -e "$out/pack/${packageName}/${dir}/${lib.getName plugin}"; then @@ -242,8 +236,8 @@ let */ vimrcContent = { packages ? null, - vam ? null, - pathogen ? null, + vam ? null, # deprecated + pathogen ? null, # deprecated plug ? null, beforePlugins ? '' " configuration generated by NIX @@ -253,19 +247,6 @@ let }: let - /* pathogen mostly can set &rtp at startup time. Deprecated. - */ - pathogenImpl = let - knownPlugins = pathogen.knownPlugins or vimPlugins; - - plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames); - - pathogenPackages.pathogen = { - start = plugins; - }; - in - nativeImpl pathogenPackages; - /* vim-plug is an extremely popular vim plugin manager. */ plugImpl = @@ -278,23 +259,7 @@ let call plug#end() ''; - /* - vim-addon-manager = VAM - - * maps names to plugin location - - * manipulates &rtp at startup time - or when Vim has been running for a while - - * can activate plugins laziy (eg when loading a specific filetype) - - * knows about vim plugin dependencies (addon-info.json files) - - * still is minimalistic (only loads one file), the "check out" code it also - has only gets loaded when a plugin is requested which is not found on disk - yet - - */ + # vim-addon-manager = VAM (deprecated) vamImpl = let knownPlugins = vam.knownPlugins or vimPlugins; @@ -314,7 +279,7 @@ let ] ++ lib.optional (vam != null) (lib.warn "'vam' attribute is deprecated. Use 'packages' instead in your vim configuration" vamImpl) ++ lib.optional (packages != null && packages != []) (nativeImpl packages) - ++ lib.optional (pathogen != null) (lib.warn "'pathogen' attribute is deprecated. Use 'packages' instead in your vim configuration" pathogenImpl) + ++ lib.optional (pathogen != null) (throw "pathogen is now unsupported, replace `pathogen = {}` with `packages.home = { start = []; }`") ++ lib.optional (plug != null) plugImpl ++ [ customRC ]; @@ -444,27 +409,20 @@ rec { # used to figure out which python dependencies etc. neovim needs requiredPlugins = { packages ? {}, - givenKnownPlugins ? null, - vam ? null, - pathogen ? null, plug ? null, ... }: let - # This is probably overcomplicated, but I don't understand this well enough to know what's necessary. - knownPlugins = if givenKnownPlugins != null then givenKnownPlugins else - if vam != null && vam ? knownPlugins then vam.knownPlugins else - if pathogen != null && pathogen ? knownPlugins then pathogen.knownPlugins else - vimPlugins; - pathogenPlugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames); - vamPlugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) (lib.concatMap vamDictToNames vam.pluginDictionaries)); - nonNativePlugins = (lib.optionals (pathogen != null) pathogenPlugins) - ++ (lib.optionals (vam != null) vamPlugins) - ++ (lib.optionals (plug != null) plug.plugins); nativePluginsConfigs = lib.attrsets.attrValues packages; - nativePlugins = lib.concatMap ({start?[], opt?[], knownPlugins?vimPlugins}: start++opt) nativePluginsConfigs; + nonNativePlugins = (lib.optionals (plug != null) plug.plugins); + nativePlugins = lib.concatMap (requiredPluginsForPackage) nativePluginsConfigs; in nativePlugins ++ nonNativePlugins; + + # figures out which python dependencies etc. is needed for one vim package + requiredPluginsForPackage = { start ? [], opt ? []}: + start ++ opt; + toVimPlugin = drv: drv.overrideAttrs(oldAttrs: { # dont move the "doc" folder since vim expects it |