Can't Get nvim-treesitter neovim plugin to work properly

I’m trying to install the nvim-treesitter plugin with home manger on nixos unstable with the nightly version of neovim like this:

    programs.neovim = {
      enable = true;
      package = pkgs.neovim-nightly;
      plugins = with pkgs.vimPlugins; [
       (nvim-treesitter.withPlugins (plugins: with plugins; [
          tree-sitter-nix
        ]))
];

However when I run nixos-rebuild switch --flake ‘.#’ I get this error:

error: builder for '/nix/store/70wxdnwkc3pzr917yj79cj2gwapxch9a-neovim-master.drv' failed with exit code 1;
       last 9 log lines:
       > Generating remote plugin manifest
       > Error detected while processing /nix/store/ps86v15lwi7r5lx4l7d0pc6gvy0zrck5-vimplugin-nvim-treesitter-2022-08-21/plugin/nvim-treesitter.lua:
       > E5113: Error while calling lua chunk: .../start/nvim-treesitter/lua/nvim-treesitter/highlight.lua:14: attempt to index local 'hlmap' (a nil value)
       > stack traceback:
       >    .../start/nvim-treesitter/lua/nvim-treesitter/highlight.lua:14: in main chunk
       >  [C]: in function 'require'
       >     ...in-nvim-treesitter-2022-08-21/plugin/nvim-treesitter.lua:12: in main chunk
       > remote/host: generated rplugin manifest: /nix/store/4sz4176bwapq1dpng4q4qf98rnm0p6av-neovim-master/rplugin.vim
       > Generating rplugin.vim failed!
       For full logs, run 'nix log /nix/store/70wxdnwkc3pzr917yj79cj2gwapxch9a-neovim-master.drv'.
error: 1 dependencies of derivation '/nix/store/zipsbs21phhl3x5gipdypjky8xm85var-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/d5qc6kmf7gxw4pfqjs1vzm6j60nd7fd3-home-manager-generation.drv' failed to build
error: 1 dependencies of derivation '/nix/store/fxxb58yyxzlqs5jfy9vindxxvjcykl00-user-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/rlvpxm6g3b8hkq3d6ynlp0g3b5agwci5-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/9zd9hia3jkaa15q7b64gywqzz2x0l7rq-nixos-system-Entertainer-22.11.20220828.a63021a.drv' failed to build

Is this a problem with the package itself?

I temporarily fixed the problem by removing the neovim-nightly flake and using from nixpkgs only for now

I solved it by overriding the nvim-treesitter plugin version to the latest:

(nvim-treesitter.withPlugins (plugins: pkgs.tree-sitter.allGrammars))
                    .overrideAttrs (old: { 
                        version = "2022-08-31";
                        src = pkgs.fetchFromGitHub { 
                            owner = "nvim-treesitter";
                            repo = "nvim-treesitter";
                            rev = "501db1459a7a46cb0766b3c56e9a6904bbcbcc97";
                            sha256 = "sha256-MGtvAtZ4VgZczalMlbftdTtPr6Ofxdkudpo6PmaVhtQ=";
                        };
                    })

Make sure to put the overrideAttrs after withPlugins.

It appears that the nvim-treesitter version in nixpkgs is too old to include this nvim-treesitter commit:

https://github.com/nvim-treesitter/nvim-treesitter/commit/1baf751fb0b03015c4c9883a87923cc4a7a4812e

and therefore it breaks on nightly Neovim. The correct solution here is to update the nvim-treesitter plugin in Nixpkgs.

When I put this code into my plugins block I get this error:

error: attempt to call something which is not a function but a set

       at /nix/store/5f83a60c6lcxfzdh7yg3ifmk150dkqb2-source/pkgs/stdenv/generic/make-derivation.nix:36:25:

           35|                 # arise from flipping an overlay's parameters in some cases.
           36|                 let x = f0 super;
             |                         ^
           37|                 in

Doesn’t function syntax use {} brackets, and attribute sets use () parentheses?

In case it helps this (using drv for nvim-treesitter defined here) is what I do.

where should the code go? I use nvchad and mason. thank you