From 10436a707a45f540e10d6b0cb5a2c075dff1fc66 Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Wed, 11 Jul 2018 17:05:51 +0200 Subject: neovim wrapper: do not unset PYTHONPATH This solves the following bug: opening neovim in nix-shell -p pythonPackages.numpy does not enable to run successfully :!python -c "import numpy" because the PYTHONPATH is wiped by the neovim wrapper. This wiping is necessary for the python providers, though, otherwise a python2 nix-shell will make the python3 provider read python2 files. We wrap the providers only, instead of neovim as whole. --- pkgs/applications/editors/neovim/wrapper.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index fa0603255599..a57831ba03c0 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -63,7 +63,6 @@ let --cmd \"${if withPython then "let g:python_host_prog='$out/bin/nvim-python'" else "let g:loaded_python_provider = 1"}\" \ --cmd \"${if withPython3 then "let g:python3_host_prog='$out/bin/nvim-python3'" else "let g:loaded_python3_provider = 1"}\" \ --cmd \"${if withRuby then "let g:ruby_host_prog='$out/bin/nvim-ruby'" else "let g:loaded_ruby_provider=1"}\" " \ - --unset PYTHONPATH \ ${optionalString withRuby '' --suffix PATH : ${rubyEnv}/bin --set GEM_HOME ${rubyEnv}/${rubyEnv.ruby.gemPath}'' } '' @@ -75,9 +74,9 @@ let --replace 'Name=Neovim' 'Name=WrappedNeovim' '' + optionalString withPython '' - ln -s ${pythonEnv}/bin/python $out/bin/nvim-python + makeWrapper ${pythonEnv}/bin/python $out/bin/nvim-python --unset PYTHONPATH '' + optionalString withPython3 '' - ln -s ${python3Env}/bin/python3 $out/bin/nvim-python3 + makeWrapper ${python3Env}/bin/python3 $out/bin/nvim-python3 --unset PYTHONPATH '' + optionalString withRuby '' ln -s ${rubyEnv}/bin/neovim-ruby-host $out/bin/nvim-ruby '' -- cgit 1.4.1 From c1752666dfb1f47bf18225524c695621978d1419 Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Wed, 11 Jul 2018 22:57:26 +0200 Subject: neovim wrapper: use python.withPackages instead of python.buildEnv They are both as powerful, but buildEnv is treacherous: if you pass a package which depends on another python (for example the one of unstable when you are on stable) it will be *silently* dropped, leading to hair pulling. Use case: override neovim from unstable, but still keep stable's pythonPackages. --- pkgs/applications/editors/neovim/wrapper.nix | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index a57831ba03c0..90b7f1ae7bea 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -10,8 +10,8 @@ neovim: let wrapper = { - withPython ? true, extraPythonPackages ? [] - , withPython3 ? true, extraPython3Packages ? [] + withPython ? true, extraPythonPackages ? (_: []) /* the function you would have passed to python.withPackages */ + , withPython3 ? true, extraPython3Packages ? (_: []) /* the function you would have passed to python.withPackages */ , withRuby ? true , withPyGUI ? false , vimAlias ? false @@ -28,25 +28,25 @@ let ''; }; + /* for compatibility with passing extraPythonPackages as a list; added 2018-07-11 */ + compatFun = funOrList: (if builtins.isList funOrList then + (_: builtins.trace "passing a list as extraPythonPackages to the neovim wrapper is deprecated, pass a function as to python.withPackages instead" funOrList) + else funOrList); + extraPythonPackagesFun = compatFun extraPythonPackages; + extraPython3PackagesFun = compatFun extraPython3Packages; + pluginPythonPackages = if configure == null then [] else builtins.concatLists (map ({ pythonDependencies ? [], ...}: pythonDependencies) (vimUtils.requiredPlugins configure)); - pythonEnv = pythonPackages.python.buildEnv.override { - extraLibs = ( - if withPyGUI - then [ pythonPackages.neovim_gui ] - else [ pythonPackages.neovim ] - ) ++ extraPythonPackages ++ pluginPythonPackages; - ignoreCollisions = true; - }; + pythonEnv = pythonPackages.python.withPackages(ps: + (if withPyGUI then [ ps.neovim_gui ] else [ ps.neovim ]) + ++ (extraPythonPackagesFun ps) ++ pluginPythonPackages); pluginPython3Packages = if configure == null then [] else builtins.concatLists (map ({ python3Dependencies ? [], ...}: python3Dependencies) (vimUtils.requiredPlugins configure)); - python3Env = python3Packages.python.buildEnv.override { - extraLibs = [ python3Packages.neovim ] ++ extraPython3Packages ++ pluginPython3Packages; - ignoreCollisions = true; - }; + python3Env = python3Packages.python.withPackages (ps: + [ ps.neovim ] ++ (extraPython3PackagesFun ps) ++ pluginPython3Packages); in stdenv.mkDerivation { -- cgit 1.4.1 From dddaa94ac26ecb223ca6d0a6a2121c7818d4b840 Mon Sep 17 00:00:00 2001 From: Symphorien Gibol Date: Thu, 12 Jul 2018 22:47:02 +0200 Subject: neovim wrapper: also make .pythonDepedencies a function A function of the same signature as the argument of python.withPackages --- pkgs/applications/editors/neovim/wrapper.nix | 22 ++++++++++++---------- pkgs/misc/vim-plugins/default.nix | 2 +- pkgs/misc/vim-plugins/vim-utils.nix | 8 +++++++- .../vim2nix/additional-nix-code/ensime-vim | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index 90b7f1ae7bea..17cf49521f1d 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -16,7 +16,7 @@ let , withPyGUI ? false , vimAlias ? false , viAlias ? false - , configure ? null + , configure ? {} }: let @@ -35,18 +35,20 @@ let extraPythonPackagesFun = compatFun extraPythonPackages; extraPython3PackagesFun = compatFun extraPython3Packages; - pluginPythonPackages = if configure == null then [] else builtins.concatLists - (map ({ pythonDependencies ? [], ...}: pythonDependencies) - (vimUtils.requiredPlugins configure)); + requiredPlugins = vimUtils.requiredPlugins configure; + getDeps = attrname: map (plugin: plugin.${attrname} or (_:[])); + + pluginPythonPackages = getDeps "pythonDependencies" requiredPlugins; pythonEnv = pythonPackages.python.withPackages(ps: (if withPyGUI then [ ps.neovim_gui ] else [ ps.neovim ]) - ++ (extraPythonPackagesFun ps) ++ pluginPythonPackages); + ++ (extraPythonPackagesFun ps) + ++ (concatMap (f: f ps) pluginPythonPackages)); - pluginPython3Packages = if configure == null then [] else builtins.concatLists - (map ({ python3Dependencies ? [], ...}: python3Dependencies) - (vimUtils.requiredPlugins configure)); + pluginPython3Packages = getDeps "python3Dependencies" requiredPlugins; python3Env = python3Packages.python.withPackages (ps: - [ ps.neovim ] ++ (extraPython3PackagesFun ps) ++ pluginPython3Packages); + [ ps.neovim ] + ++ (extraPython3PackagesFun ps) + ++ (concatMap (f: f ps) pluginPython3Packages)); in stdenv.mkDerivation { @@ -87,7 +89,7 @@ let ln -s $out/bin/nvim $out/bin/vim '' + optionalString viAlias '' ln -s $out/bin/nvim $out/bin/vi - '' + optionalString (configure != null) '' + '' + optionalString (configure != {}) '' wrapProgram $out/bin/nvim --add-flags "-u ${vimUtils.vimrcFile configure}" '' ; diff --git a/pkgs/misc/vim-plugins/default.nix b/pkgs/misc/vim-plugins/default.nix index b52e63241990..4f9bae97ea7b 100644 --- a/pkgs/misc/vim-plugins/default.nix +++ b/pkgs/misc/vim-plugins/default.nix @@ -1015,7 +1015,7 @@ let sha256 = "03sr53680kcwxaa5xbqzdfbsgday3bkzja33wym49w9gjmlaa320"; }; dependencies = ["vimproc" "vimshell" "self" "forms"]; - pythonDependencies = with pythonPackages; [ sexpdata websocket_client ]; + passthru.python3Dependencies = ps: with ps; [ sexpdata websocket_client ]; }; supertab = buildVimPluginFrom2Nix { # created by nix#NixDerivation diff --git a/pkgs/misc/vim-plugins/vim-utils.nix b/pkgs/misc/vim-plugins/vim-utils.nix index 514c1daed629..bae1645563f0 100644 --- a/pkgs/misc/vim-plugins/vim-utils.nix +++ b/pkgs/misc/vim-plugins/vim-utils.nix @@ -280,6 +280,7 @@ let installPhase = lib.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList packageLinks packages)); + preferLocalBuild = true; } ); in @@ -423,6 +424,7 @@ rec { } // a); requiredPlugins = { + packages ? {}, givenKnownPlugins ? null, vam ? null, pathogen ? null, ... @@ -437,8 +439,12 @@ rec { vamNames = findDependenciesRecursively { inherit knownPlugins; names = lib.concatMap toNames vam.pluginDictionaries; }; names = (lib.optionals (pathogen != null) pathogenNames) ++ (lib.optionals (vam != null) vamNames); + nonNativePlugins = map (name: knownPlugins.${name}) names; + nativePluginsConfigs = lib.attrsets.attrValues packages; + nativePlugins = lib.concatMap ({start?[], opt?[]}: start++opt) nativePluginsConfigs; in - map (name: knownPlugins.${name}) names; + nativePlugins ++ nonNativePlugins; + # test cases: test_vim_with_vim_addon_nix_using_vam = vim_configurable.customize { diff --git a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/ensime-vim b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/ensime-vim index 7d6267e95151..e065e0db4f47 100644 --- a/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/ensime-vim +++ b/pkgs/misc/vim-plugins/vim2nix/additional-nix-code/ensime-vim @@ -1 +1 @@ - pythonDependencies = with pythonPackages; [ sexpdata websocket_client ]; + passthru.python3Dependencies = ps: with ps; [ sexpdata websocket_client ]; -- cgit 1.4.1