NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.89k stars 13.95k forks source link

nvim-treesitter not linking grammars #341442

Closed anna328p closed 1 month ago

anna328p commented 1 month ago

Describe the bug

I noticed that nvim wasn't loading any of my treesitter plugins. I decided to check the plugin directory.

$ nix build 'nixpkgs#vimPlugins.nvim-treesitter.withAllGrammars' --no-link --print-out-paths
/nix/store/8iwi6pzi9690yl1l0dv3r497hml7zylf-vimplugin-nvim-treesitter-2024-08-04

$ nix path-info --recursive /nix/store/8iwi6pzi9690yl1l0dv3r497hml7zylf-vimplugin-nvim-treesitter-2024-08-04
/nix/store/cjnmdi9chk0fhjy8p8dq8inxqr4p3vk7-libunistring-1.2
/nix/store/04hj9k1gyv26b9gdmcmw3l3bbi124xxi-libidn2-2.3.7
/nix/store/3ilxy06yvz70vg6ld86kyjr6qb248vd6-gcc-13.3.0-libgcc
/nix/store/mrsnnz2nmnb4mrma1bfv6inmy2k3k3k8-xgcc-13.3.0-libgcc
/nix/store/wlffq5p6mxxgfap10sav3ij936jzqm59-glibc-2.39-52
/nix/store/zx9zgvy2nsxcmpn0fzx277m5lk352cdf-gcc-13.3.0-lib
/nix/store/cxz2iaaaipqbf2slznyaazx81d27imlh-gmp-with-cxx-6.3.0
/nix/store/p610ybx1pp15lnxxdggm3nmaq31whnvi-attr-2.5.2
/nix/store/gda8zjgw0s8zzg5ijza7p12zf5c4b0b0-acl-2.3.2
/nix/store/vb8mdklw65p9wikp97ybmnyay0xzipx3-coreutils-9.5
/nix/store/vpvy79k1qq02p1vyqjk6nb89gwhxqvyb-bash-5.2p32
/nix/store/8iwi6pzi9690yl1l0dv3r497hml7zylf-vimplugin-nvim-treesitter-2024-08-04

hm. something is very wrong here. it isn't pulling in any grammars. let's investigate:

https://github.com/NixOS/nixpkgs/blob/7a33145986fa450a1e202728ad485755c28558e9/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix#L43-L45

ok, so it's looking for a file at parser/${name}.so. what does the grammar derivation look like?

$ nix build 'nixpkgs#vimPlugins.nvim-treesitter.withAllGrammars' --no-link --print-out-paths
/nix/store/8iwi6pzi9690yl1l0dv3r497hml7zylf-vimplugin-nvim-treesitter-2024-08-04

$ eza -lT /nix/store/9g0g0gbgn4n7w4mlrlzp0r7yjwd1wn3f-nix-grammar-0.0.0+rev=68d3b79
dr-xr-xr-x    - root 31 Dec  1969 /nix/store/9g0g0gbgn4n7w4mlrlzp0r7yjwd1wn3f-nix-grammar-0.0.0+rev=68d3b79
.r-xr-xr-x 106k root 31 Dec  1969 ├── parser
dr-xr-xr-x    - root 31 Dec  1969 └── queries
.r--r--r-- 2.7k root 31 Dec  1969    ├── highlights.scm
.r--r--r-- 1.4k root 31 Dec  1969    ├── injections.scm
.r--r--r-- 1.2k root 31 Dec  1969    └── locals.scm

$ file /nix/store/9g0g0gbgn4n7w4mlrlzp0r7yjwd1wn3f-nix-grammar-0.0.0+rev=68d3b79/parser
/nix/store/9g0g0gbgn4n7w4mlrlzp0r7yjwd1wn3f-nix-grammar-0.0.0+rev=68d3b79/parser: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

So the parser is ending up at $out/parser instead of $out/parser/${language}.so. What does the grammar derivation's source look like?

https://github.com/NixOS/nixpkgs/blob/7a33145986fa450a1e202728ad485755c28558e9/pkgs/development/tools/parsing/tree-sitter/grammar.nix#L7

Checking git blame, this code has been in place for years.

Checking git blame for nvim-treesitter, I find https://github.com/NixOS/nixpkgs/commit/54f33c58c45e4677699162dbd864adfd363377e1. It was merged three weeks ago.

I see that https://github.com/NixOS/nixpkgs/pull/341079 is open. I couldn't find any information on this problem with GitHub search...

Could that PR be merged quicker please? My editor setup is broken now :(

Notify maintainers

@stephen-huan

Metadata


Add a :+1: reaction to issues you find important.

stephen-huan commented 1 month ago

So the parser is ending up at $out/parser instead of $out/parser/${language}.so.

I think this is not actually the direct cause of the issue you're seeing since the grammars go through grammarToPlugin

https://github.com/NixOS/nixpkgs/blob/a6f77b0590a382b701d2e441c79583017a3e6ab6/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix#L40-L42

https://github.com/NixOS/nixpkgs/blob/2b32fd65a31d54e9858734ad488df2a6434b4e8a/pkgs/applications/editors/neovim/utils.nix#L207-L230

(see the below, which precisely corrects the observed discrepancy)

https://github.com/NixOS/nixpkgs/blob/2b32fd65a31d54e9858734ad488df2a6434b4e8a/pkgs/applications/editors/neovim/utils.nix#L227-L230

You're not seeing the grammars when you nix build because the grammars are in passthru.dependencies. I explain how to properly build it in https://github.com/NixOS/nixpkgs/pull/319233#issuecomment-2308398048. The PR is broken, don't get me wrong, but I think not this directly :p.

For why your configuration is broken, see https://github.com/NixOS/nixpkgs/pull/201548. I think it's because of your dependency on v.nvim-treesitter-endwise and v.nvim-treesitter-context which pulls in a nvim-treesitter without any grammars but I'm not sure.

Could that PR be merged quicker please? My editor setup is broken now :(

You can try giving https://github.com/NixOS/nixpkgs/pull/341079 an approval, I'm in the same boat as you (I don't have merge permissions).

Apologies for breaking your setup!