Installing a neovim IDE layer the Nix-way

Hey you guys,
I’m new to Nix(OS) and must say I love its premise, though I’m still a bit lost when it comes how I have to configure things. :slight_smile:
I’d like to use a couple of IDE layers for neovim as my code editor, such as
LunarVim or NvChad. They both offer an installation script on their respective website, but I doubt that this is consired a very ‘Nix’ way.
I was wondering if any of you could explain to me, how you’d install such programs / configs in a declaretive way, so that I can treat them like I would any other Nix package.
Thanks in advance! :slight_smile:

1 Like

Hey @4761 :wave:, I do not know about LunarVim or NvChad specifically, but I use AstroNvim which I setup with home-manager:

And AstroNvim supports loading its config from a location other than ~/.config/nvim, ~/.config/astronvim works out-of-the-box:

The onChanges work around an issue with the impatient.nvim: Using `mtime.secs` for hash is incompatible with Nix managed configurations · Issue #42 · lewis6991/impatient.nvim · GitHub. You can ignore if your config does not use it (AstroNvim does).

I manage updates with niv, but nix flake could do too:

niv add AstroNvim/AstroNvim --name astronvim --branch v2.11.8
niv update astronvim --branch <tag>

I do not use any fancy feature from home-manager at the moment (e.g. its neovim modules which would be incompatible beyond installing the package), I only use it to link my dotfiles.

Hope that helps :slight_smile:

2 Likes

thanks a lot for the detailed response! While I do not understand each step just yet, I bet this would also work for LunarVim or NvChad, as they also support a seperate config file.
If I understood it correctly, you basically manually install AstroNvim once and then just add the config file to your repo and reference it in your home manager config, is that correct?

Thanks again, I’ll be playing around with NixOS now, trying to get this to work :slight_smile:

The tricky part here is that these installer scripts don’t just install the Neovim configuration, they also install sidecar programs (or some of the plugins do so) in order to provide LSPs and formatters. To me, that isn’t very “Nix-native”, and letting a program make changes to your system may not even work at all in NixOS. These programs are great for getting setup quickly, but hard to maintain when something goes wrong.

I don’t have an easy solution here. Obviously, you can attempt to install one of these pre-made configurations anyway, and you can declare your configuration using home-manager; either with the neovim module or just with raw config files referenced by your Nix config.

Personally, I don’t use a pre-made IDE. I choose similar plugins and settings myself, and then I use nix2vim to write most of my config in native Nix and bundle it with the Neovim package myself as a single dependency. This includes bundling all the LSPs and formatters, which I pull from nixpkgs instead of using a script. The downside is that this method is extremely poorly documented, and I end up juggling Nix code, Lua code, plugins in nixpkgs, and other plugins in GitHub repos.

I just wanted to mention it because there are more and less “declarative” ways of managing Neovim, depending on what you need.

1 Like

I recommend nix2vim but I might be biased ;))))

1 Like

Another one that may be worth considering is

I haven’t got much experience with it yet though.

1 Like

thank you! I saw it on github, but since I’m lacking knowledge about Nix I was a bit overwhelmed at first glance.

I’ll take a look at it again, once I’m a bit more comfortable with the language :slight_smile: