Nix-lsp: Language server for nix


#1

https://gitlab.com/jD91mZM2 has build a parser for nix and a language server for nix called nix-lsp.

It is still in early in development, but you can already test code formatting and renaming symbols.
The parser itself is able to read and dump nixpkgs already.

Since it depends on rust-nightly we can not put it in nixpkgs right-away.
However I created a NUR package: nur.repos.mic92.nix-lsp

$ nix-shell -p nur.repos.mic92.nix-lsp

Here is the configuration I use with LanguageClient-neovim:

let g:LanguageClient_serverCommands = {
      \ 'nix': ['nix-lsp'],
      \ }
let g:LanguageClient_loadSettings = 1
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
nnoremap <silent> gh :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> gr :call LanguageClient_textDocument_references()<CR>
nnoremap <silent> gs :call LanguageClient_textDocument_documentSymbol()<CR>
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>
nnoremap <silent> gf :call LanguageClient_textDocument_formatting()<CR>

#2

Interesting development, but only if it actually works and never crashes. Anyone besides Mic92 that has used it?

My experience with such projects is that they never live up to their promises, so perhaps that user built something that actually delivers, but I am going to guess for now that it doesn’t. I’d say it’s announced too early. It should have a video with a demo of it working at the very least. Release early, release often is a thing, but I think there is also such a thing as being too early. I look forward to the day that nix-mode is implemented with language server support printing a small warning in my status buffer "You don’t have services.language_server.enable = yes; # which would create a superior user experience.

NUR also seems interesting, but the value of a package in nixpkgs is that there is build automation. I mostly hope that more maintainers will get commit access (almost 1000 PRs now(!)). As long as not a lot of people are allowed to touch “core packages” (like the kernel or glibc), I don’t really see an issue with increasing commit access. Also, for most packages the nix packages can be automatically generated, so what really needs to be done is not so much writing packages, but keeping packages updated with automation and that automation needs to be updated and reviewed (which can be done by a small group of people).


#3

My experience with such projects is that they never live up to their
promises, so perhaps that user built something that actually
delivers, but I am going to guess for now that it doesn’t. I’d say
it’s announced too early. It should have a video with a demo of it
working at the very least. Release early, release often is a thing,
but I think there is also such a thing as being too early.

There’s a good change you are a part of the “early majority”
demographic[1] that doesn’t like unstable releases. There’s a
well-studied group of people called “early adopters/innovators” that
don’t mind early releases, as it’s a way to test new ideas and to
contribute code. I have a feeling most nix users are the “early
adopter/innovator” demographic so you should expect to see a lot of
stuff like this around here :wink:

[1] https://en.wikipedia.org/wiki/Technology_adoption_life_cycle