Describe the bug
A clear and concise description of what the bug is.
The neovim with vimPlugins."coc-python" in either configure.packages.myVimPackages.start or plug.plugins doesn't bring python into scope, resulting in
pylintTo Reproduce
Steps to reproduce the behavior:
home-manager with neovim.plugins = [coc-nvim coc-python] shell.nix with with import <nixpkgs> {};
let
neovimPythonPackages = p: with p; [
jedi
flake8
black
pylint
];
neovim = pkgs.neovim.override {
extraPython3Packages = neovimPythonPackages;
withPython3 = true;
withNodeJs = true;
configure = {
customRC = builtins.readFile ~/.config/nixpkgs/nvim-init-template.vim;
plug.plugins = with pkgs.vimPlugins; [
coc-nvim
coc-python
];
};
};
in
mkShell {
buildInputs = [neovim];
}
nix-shell in the directory with shell.nix (or home-manager switch)nvim example.py:! which python:! which nodeExpected behavior
A clear and concise description of what you expected to happen.
:!, but regardless)Observed behaviour
If applicable, add screenshots to help explain your problem.
pylint. An error reporting "No Python interpreter"Additional context
Add any other context about the problem here.
Notify maintainers
@vcunat (found in vim-plugins/overrides.nix)
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
- system: `"x86_64-linux"`
- host os: `Linux 5.4.62, NixOS, 20.09pre242769.61525137fd1 (Nightingale)`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.3.7`
- channels(serge): `"home-manager, nixpkgs-21.03pre243200.c413f10dafa"`
- channels(root): `"nixos-20.09pre242769.61525137fd1"`
- nixpkgs: `/home/serge/.nix-defexpr/channels/nixpkgs`
Maintainer information:
# a list of nixpkgs attributes affected by the problem
attribute: [pkgs.vimPlugins.coc-python, pkgs.neovim]
# a list of nixos modules affected by the problem
module:
Upd: found that python executable is exposed to nvim, as it is supposed to, through g:python3_host_prog and not PATH:
:echo g:python3_host_prog
/nix/store/gsb3ahrqpd99i4frbrsdb2br3chi88gl-neovim-0.4.4/bin/nvim-python3
Apparently the solution would be to allow to populate the coc-settings.json with python.linting.pylintPath, etc.
I temporarily resorted to the following hack and it kind of works:
# home.nix
xdg.configFile."nvim/coc-settings.json".text = ''
{
"python.linting.pylintPath": "nix-shell -p 'python3.withPackages(ps: [ps.pylint])' --run 'python -m pylint'"
}
'';
The UX I'd expect is that adding coc-python to neovim plugins would automatically include pylint, black, isort, etc in the closure and that neovim would be exposed to their executables. I could work on that some time later, but I wouldn't know how to approach the problem. I find nixpkgs somewhat overwhelming
I'm just a NixOS newbie, so I might be doing something very wrong here, but for black and flake8 the following works for me:
# configuration.nix
home-manager = {
# ..
programs = {
neovim = {
extraPackages = with pkgs; [
(python3.withPackages (ps: with ps; [
black
flake8
]))
];
This seems to install black and flake8 and expose them in the PATH to the Neovim process, so you would not need your xdg.configFile hack.
I still have not managed to get jedi working, though: Python complains about module jedi not being found, even when I add it to the extraPython3Packages option.
@carletes, modules from extraPython3Packages ends up available to nvim-python3. Try to make sure it's the one you invoke (e.g., as nvim-python3 -m jedi).
@carletes for myself, I hotfixed jedi by explicitly providing path to its site-packages: https://github.com/newkozlukov/dotfiles/blob/7058ff268c6d802621135831b5271ecc781a7c2c/home/program/neovim/coc.nix#L5 (here pylinters comes from https://github.com/newkozlukov/dotfiles/blob/7058ff268c6d802621135831b5271ecc781a7c2c/overlays/pylinters.nix#L33 but probably most of this terrible messy hack is unnecessary; I just don't have time to clean it up)
I didn't check @t184256's solution now, but when I just opened this issue, extraPython3Packages didn't work (at least for me, at least with jedi)
Also, didn't know about nvim-python3, will look into where's it constructed and how - later
Thanks
Try to make sure it's the one you invoke (e.g., as nvim-python3 -m jedi).
@t184256: Thanks for the hint! Yes, I did a /nix/store/<blahblah>/nvim-python3 -m jedi in another terminal and it worked (as in nvim-python3 as able to locate the jedi module).
All I had to do then was to set python.pythonPath to pnvim-python3 in my coc-settings.json and then everything works.
For black and flake8 I made them accessible to nvim's PATH by adding them toextraPackages`, and that seems to do the trick.
To sum up: The following configuration (I use home-manager driven from /etc/nixos/configuration.nix) works for me:
# configuration.nix
{
home-manager = {
programs = {
neovim = {
enable =true;
withPython3 = true;
plugins = with pkgs.vimPlugins; [
coc-nvim
coc-python
];
extraPackages = with pkgs; [
(python3.withPackages (ps: with ps; [
black
flake8
]))
];
extraPython3Packages = (ps: with ps; [
jedi
]);
};
};
};
xdg.configFile."nvim/coc-settings.json".text = builtins.readFile ./my-coc-settings.json;
}
And here are the relevant bits of my-coc-settings.json:
{
"python.formatting.provider": "black",
"python.jediEnabled": true,
"python.linting.flake8Enabled": true,
"python.pythonPath": "nvim-python3"
}