Hi! I am configuring Neovim from scratch on NixOS and having trouble getting Treesitter to work. I am aware of NixVim, but I am trying to get lazy.nvim to work because I use machines where I am not able to use Nix. Here are my configurations:
# home-manager.nix
{pkgs, ...}: {
programs.neovim = {
enable = true;
plugins = with pkgs.vimPlugins; [
lazy-nvim
];
};
}
-- init.lua
vim.g.mapleader = " "
vim.opt.termguicolors = true
vim.opt.guicursor = ""
vim.cmd("set expandtab")
vim.cmd("set tabstop=2")
vim.cmd("set softtabstop=2")
vim.cmd("set shiftwidth=2")
vim.cmd("set number")
vim.cmd("set relativenumber")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
spec = {
{ import = "plugins" },
},
})
require("nvim-treesitter.configs").setup({
ensure_installed = { "all" },
highlight = {
enable = true,
},
})
vim.cmd.colorscheme("catppuccin")
-- treesitter.lua
return {
{
"nvim-treesitter/nvim-treesitter",
branch = "master",
lazy = false,
build = ":TSUpdate",
},
}
And this is the error I’m getting:
Error detected while processing /home/<username>/Dots/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/<username>/Dots/.config/nvim/init.lua:30: module 'nvim-treesitter.configs' not found:
no field package.preload['nvim-treesitter.configs']
cache_loader: module 'nvim-treesitter.configs' not found
cache_loader_lib: module 'nvim-treesitter.configs' not found
no file '/nix/store/dzqf1rfxpi24npgnb8k5831s17li4748-luajit-2.1.1741730670-env/share/lua/5.1/nvim-treesitter/configs.lua'
no file '/nix/store/dzqf1rfxpi24npgnb8k5831s17li4748-luajit-2.1.1741730670-env/share/lua/5.1/nvim-treesitter/configs/init.lua'
no file '/home/<username>/.local/share/nvim/lazy-rocks/telescope.nvim/share/lua/5.1/nvim-treesitter/configs.lua'
no file '/home/<username>/.local/share/nvim/lazy-rocks/telescope.nvim/share/lua/5.1/nvim-treesitter/configs/init.lua'
no file '/nix/store/dzqf1rfxpi24npgnb8k5831s17li4748-luajit-2.1.1741730670-env/lib/lua/5.1/nvim-treesitter/configs.so'
no file '/home/<username>/.local/share/nvim/lazy-rocks/telescope.nvim/lib/lua/5.1/nvim-treesitter/configs.so'
no file '/home/<username>/.local/share/nvim/lazy-rocks/telescope.nvim/lib64/lua/5.1/nvim-treesitter/configs.so'
no file '/nix/store/dzqf1rfxpi24npgnb8k5831s17li4748-luajit-2.1.1741730670-env/lib/lua/5.1/nvim-treesitter.so'
no file '/home/<username>/.local/share/nvim/lazy-rocks/telescope.nvim/lib/lua/5.1/nvim-treesitter.so'
no file '/home/<username>/.local/share/nvim/lazy-rocks/telescope.nvim/lib64/lua/5.1/nvim-treesitter.so'
stack traceback:
[C]: in function 'require'
/home/<username>/Dots/.config/nvim/init.lua:30: in main chunk
I have seen a comment on Reddit where a guy installed Treesitter in his Home Manager configuration and then did some symlink shenanigans, but I couldn’t get that to work, even after taking code straight from his repository.
Any help with getting this to work using lazy.nvim will be greatly appreciated. Please let me know if I should provide any other information.