coq_nvim icon indicating copy to clipboard operation
coq_nvim copied to clipboard

Unable to be used on NixOs

Open B4rc1 opened this issue 1 year ago • 6 comments
trafficstars

When calling :COQdeps a window opens with the following content:

/nix/store/b9mkn6wrfrkkyaiix1p4rbipamvmyi1f-python3-3.11.6-env/bin/python3.11: No module named coq

[Process exited 1]

My neovim config looks like this: (im using lazy.nvim)

  {
    'ms-jpq/coq_nvim',
    branch = "coq",
    config = function ()
      vim.g.coq_settings = {
        xdg = true
      }
    end,
  }

I set xdg= true because of #20.

My Healthcheck: :checkhealth provider


==============================================================================
provider: health#provider#check

Clipboard (optional) ~
- OK Clipboard tool found: win32yank

Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/nix/store/x550cpl6f99r1cnd11jf9naah2jb3wwj-neovim-0.9.4/bin/nvim-python3"
- Executable: /nix/store/x550cpl6f99r1cnd11jf9naah2jb3wwj-neovim-0.9.4/bin/nvim-python3
- Python version: 3.11.6
- pynvim version: 0.4.3 (outdated; from /nix/store/b9mkn6wrfrkkyaiix1p4rbipamvmyi1f-python3-3.11.6-env/lib/python3.11/site-packages/neovim)
- WARNING Latest pynvim is NOT installed: 0.5.0

Python virtualenv ~
- OK no $VIRTUAL_ENV

Ruby provider (optional) ~
- Ruby: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
- Host: /nix/store/x550cpl6f99r1cnd11jf9naah2jb3wwj-neovim-0.9.4/bin/nvim-ruby
- WARNING Gem "neovim" is out-of-date. Installed: 0.9.0, latest: 0.9.1
  - ADVICE:
    - Run in shell: gem update neovim

Node.js provider (optional) ~
- Disabled (g:loaded_node_provider=0).

Perl provider (optional) ~
- Disabled (g:loaded_perl_provider=0).

I investigated this a bit and found that my vim.g.python3_host_prog is /nix/store/x550cpl6f99r1cnd11jf9naah2jb3wwj-neovim-0.9.4/bin/nvim-python3 different from the error im recieving. The executable looks like this:

$ cat /nix/store/x550cpl6f99r1cnd11jf9naah2jb3wwj-neovim-0.9.4/bin/nvim-python3
#! /nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash -e
unset PYTHONPATH
exec "/nix/store/b9mkn6wrfrkkyaiix1p4rbipamvmyi1f-python3-3.11.6-env/bin/python3.11"  "$@" 

It unsets the pythonpath before launching python. So I tried changing the python executable to the one that gets launched anyways: :lua vim.g.python3_host_prog = "/nix/store/b9mkn6wrfrkkyaiix1p4rbipamvmyi1f-python3-3.11.6-env/bin/python3.11" but I still get the same error.

How is this plugin structured? Does it inject the plugins path into PYTHONPATH and then tries to load the python module coq? How is this done? Through environment variables? Through commandline options?

Help would be greatly appreciated.

B4rc1 avatar Jan 19 '24 13:01 B4rc1

nix-community/nixvim/plugins/completion/coq.nix#L15

I use nixvim and It work for me. But I can't run :COQDeps either .

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/nix/store/170h6l5irprm169c914l6vhcwrik1jk9-vimplugin-coq_nvim-2023-12-29/coq/__main__.py", line 85, in <module>
    assert not _IN_VENV
AssertionError

[Process exited 1]

This doesn't seem to have any impact.

This seems to be related to nixpkgs.

gemone avatar Jan 22 '24 16:01 gemone

A temporary fix would be cd to the coq_nvim directory and executing this command with python

python -m coq deps --xdg ~/.local/share/nvim

body20002 avatar Feb 23 '24 17:02 body20002

This recently started for me after updating, it's a regression in either NixOS or coq.

meisme-dev avatar Mar 22 '24 12:03 meisme-dev

This is a regression by this commit: https://github.com/ms-jpq/coq_nvim/commit/78bd6e9ec4421b2e9d6d4f97eab172a5d50d28f6

What is happening here?

  1. This line calculates the working directory of the script and this line sets the working directory of the Python script
  2. In NixOS, Neovim generates its own Python wrapper. This is a Bash script that invokes the interpreter. Note the --unset PYTHONPATH line. It causes the Bash script to have "unset PYTHONPATH" at the start of the script. So the "PYTHONPATH" variable is unset before the script is loaded.
  3. Here Coq is passing the PYTHONPATH variable to set the current working directory into the path, so that the "coq" module is found. However, this has no effect on NixOS since this PYTHONPATH variable is unset anyway. But since the cwd was set here, it still works. As mentioned in the Python docs, the current directory is added to the list of paths anyway.
  4. But now the PYTHONSAFEPATH variable comes into play. Because of this, the current directory is not added to PATH and the module is not found.

So the fix is to either remove PYTHONSAFEPATH, or fetch Neovim from the unstable channel, where the PYTHONSAFEPATH is also unset

heraldofsolace avatar Mar 26 '24 10:03 heraldofsolace

So the fix is to either remove PYTHONSAFEPATH, or fetch Neovim from the unstable channel

I have the same problem but i'm using the unstable channel for neovim

programs.neovim = {
      enable = true;
      defaultEditor = true;
      vimAlias = true;
      viAlias = true;
      package = pkgs.unstable.neovim-unwrapped;
};

perrylets avatar Apr 19 '24 01:04 perrylets

I have the same problem but i'm using the unstable channel for neovim

It's because neovim-unwrapped doesn't have that configuration. home-manager creates a wraed version of neovim from neovim-unwrapped using pkgs.wrapNeovimUnstable. You'll need to pull the wrapNeovimUnstable from unstable (using maybe an overlay).

heraldofsolace avatar May 12 '24 12:05 heraldofsolace