PSA: if you are on unstable, try out nvim-treesitter.withAllGrammars

Note: This is for people on {nixos,nixpkgs}-unstable only

If you were using vimPlugins.nvim-treesitter.withPlugins (_: tree-sitter.allGrammars), you can now switch to vimPlugins.nvim-treesitter.withAllGrammars to use the versions of tree sitter grammars specified in nvim-treesitter’s lock file.

If you were experiencing breakages with withPlugins and switched to :TSInstall, you can give the new version a try.

Refer to the new docs (scroll down to the treesitter section) for more information

People using nvim-treesitter.withPlugins (ps: [...]) should automatically get the updates without changing anything

11 Likes

I would like to know the reason why vimPlugins.nvim-treesitter: remove parser directory

I prefer to use neovim-unwrapped and configure neovim with minimal configuration. This doesn’t work after the commit

xdg.configFile = {
    "nvim/init.lua".text = ''
      -- Add Treesitter Path
      vim.opt.runtimepath = vim.opt.runtimepath + "${pkgs.vimPlugins.nvim-treesitter.withAllGrammars}"
      -- Invoke Real Start
      require("start")
    '';
  };

That was probably broken by vimPlugins.nvim-treesitter: add plugins to dependencies to avoid extending vimPlugins by figsoda · Pull Request #201548 · NixOS/nixpkgs · GitHub then, all the grammars are added to dependencies instead

A way to fix this would be to also add all of pkgs.vimPlugins.nvim-treesitter.withAllGrammars.dependencies to runtimepath

Edit: If you are worried that runtimepath would be too long, you can do a symlinkJoin of these

2 Likes

Thanks a lot. This works

let
  treesitter-parsers = pkgs.symlinkJoin {
    name = "treesitter-parsers";
    paths =[
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.c] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.lua] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.nix] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.bash] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.json] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.typescript] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.cpp] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.rust] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.python] )).dependencies
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [p.markdown] )).dependencies
    ];
  };
in
{
  xdg.configFile = {
    "nvim/init.lua".text = ''
      -- Add Treesitter Plugin Path
      vim.opt.runtimepath:append("${pkgs.vimPlugins.nvim-treesitter}")
      -- Add Treesitter Parsers Path
      vim.opt.runtimepath:append("${treesitter-parsers}")
      -- Invoke Real Start
      require("start")
    '';
  };

  home.packages = with pkgs;
    [
      neovim-unwrapped
      fd
      ripgrep
    ]
}

btw, you should be able to simplify that to

[...]
paths = (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.c p.lua p.nix p.bash ... ])).dependencies
[...]
2 Likes

I’m on unstable and using home-manger to configure my neovim install.

{ config, pkgs, ...}:
let
    nvim-plugintree = (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [
        p.c
        p.lua
        p.nix
        p.bash
        p.cpp
        p.json
        p.python
        p.markdown
    ]));

    treesitter-parsers = pkgs.symlinkJoin {
      name = "treesitter-parsers";
      paths = nvim-plugintree.dependencies;
    };
in
{
  programs.neovim = {
    enable = true;
    vimAlias = true;
    plugins = with pkgs.vimPlugins; [
      nvim-plugintree
    ];

    extraConfig = ''
      lua require('init')
    '';
  };

  xdg.configFile = {
    "nvim/lua/init.lua".text = ''
      -- Add Treesitter Plugin Path
      vim.opt.runtimepath:append("${nvim-plugintree}")
      -- Add Treesitter Parsers Path
      vim.opt.runtimepath:append("${treesitter-parsers}")

      require('start')
    '';
    "nvim/lua/start.lua".source = ./start.lua;
  };

  home.packages = with pkgs; [
    tree-sitter
  ];
}

I think this is all the relevent parts of my config. I use nix flakes to build the system.

Opening neovim and it still errors with read-only file system. Weirdly though the highlighting is working.

This didn’t work for me properly before your change so it may be unrelated, any insights would be welcome though!

Do you have anywhere in your config that runs TSUpdate or TSInstall?

No, not in the config files. And running it manually in neovim ofc has the same error

This might be late, but I had the same issue, and it was fixed when I flipped this:

require("nvim-treesitter.configs").setup({
    ....
    -- Automatically install missing parsers when entering buffer
    auto_install = false, <-- This was set to true before
    ....
})

This issue is cause by nvim either wanting to install something additionally as mentioned by @figsoda.

This is a late contribution, but I hope I point someone in the right direction. The pointers above helped me a lot.

If not this, look for other places where you automagically install things. That should especially be applicable when migrating an existing config to nix (as suddenly you move to read-only)

Hi, I am new to nixos and this works but I have a doubt.
How do I find such packages? I tried the following

  • nix search nixpkgs nvim-treesitter
  • nix-env -qaP nvim-treesitter
  • Queried on the nix packages search online

None of them showed this package. I want a similar package for emacs but don’t know how to find.

1 Like