Neovim LSPs and NixOS - The Lazy Way

2 Jul 20242 min read

You moved over to NixOS and found yourself in trouble when running Neovim? Mason is screaming at you asking for the LSPs and you have no idea what's going on? Fear not, you're in the right place.

There are different ways to fix this issue, but I prefer to keep it lazy. I want Neovim to work out of the box, just like on other distros.

Nix-ld Knows The Way

NixOS is different from other Linux distributions when it comes to its file system. When Mason goes looking for packages, it won't find them due to how the system is structured. Here's where nix-ld comes in. In short, nix-ld tells Mason where to look for the LSPs.

As of July 2024, enabling nix-ld on NixOS 24.05 is very simple:

  1. Add the following line to your configuration.nix file:
programs.nix-ld.enable = true;
  1. Save the changes and run:
sudo nixos-rebuild switch
  1. Reboot your system.

From now on, Mason will be able to find the LSPs. I won't go into details to keep the post short, but in case you're curious and want an in-depth guide on nix-ld you can find it here.

Thoughts

Using nix-ld allows you to keep your Neovim configuration separate from NixOS, making it highly portable and easy to maintain.

Pixel art of the ocean