Neovim Treesitter Grammars with Nix and lazy.nvim

I recently managed to install my neovim plugins with nix but lazy load them with lazy.nvim (blog post coming soon).
One milestone was to install all treesitter grammars via nix and make them available to neovim.
The treesitter nix package has a handy plugin called pkgs.vimPlugins.nvim-treesitter.withAllGrammars to install all compiled grammars at once.
Somehow this was hard to setup if you are not bootstrapping your neovim plugins with the nix neovim module (and instead use lazy.nvim).

Here is a little snippet on how to link all compiled treesitter grammars to your runtimepath. The treesitter plugin will automatically pick them up since he searches for <grammer>.so in your runtimepath (rtp). No more config needed (of course you still need to install the treesitter plugin).

luaConfigSnippet = let grammarsPath = pkgs.symlinkJoin {
  name = "nvim-treesitter-grammars";
  paths = pkgs.vimPlugins.nvim-treesitter.withAllGrammars.dependencies;
}; in 
# lua 
''
    -- also make sure to append treesitter since it bundles some languages
    vim.opt.runtimepath:append("${pkgs.vimPlugins.nvim-treesitter}")
    -- append all *.so files
    vim.opt.runtimepath:append("${grammarsPath}")
''

Just integrate this snippet into your existing neovim lua config.

Click HERE to see how I integrated it into my setup.