Recently I wrote a brand new nix language server, which links with official NixOS/nix library.
Home page: GitHub - nix-community/nixd: Nix language server, based on nix libraries [maintainer=@inclyc]
About
Nixd is a Nix language server that directly uses (i.e., is linked with) the official Nix library (GitHub - NixOS/nix: Nix, the purely functional package manager).
Some notable features provided by linking with the Nix library include:
- Nixpkgs option support, for all option system (NixOS/home-manager/flake-parts).
- Diagnostics and evaluation that produce identical results as the real Nix command.
- Shared eval caches (flake, file) with your system’s Nix.
- Native support for cross-file analysis.
- Precise Nix language support. We do not maintain “yet another parser & evaluator”.
- Support for built-ins, including Nix plugins.
Features
We provide native options auto-completion system, by lazily evaluated merged option set. (Goto declarations also work)
Note that not only home-manager options, generally all nixpkgs option system are supported. We have tested nixos options, home-manager options, and even flake-parts.
And, we know the lambda arguments passed to your nix file, e.g. by callPackage
Also, we complete variables inside with
expressions (and also complete stdenv
, lib
, with hover support). Note that the diagnostic missing “name” is reported.
Installation & User Guide
We support all kinds of evaluation & cross-file analysis by allow our user explicitly specify a nix installable. Which will be used for cross-file analysis pivot. For more information, please see:
Developers’ Manual
So how do these things work? I’ve written a brief explanation here. TLDR: we use callbacks and inject custom AST nodes to nix evaluator.
Limitations
- Currently critical features like “rename” & “semantic tokens” are not yet supported yet. Because we cannot retrieve range information from nix ASTs. Many language features like AST-based editing do expect ASTs preserving enough information.
- Source Tree Abstraction. We do need provide a VFS to nix evaluator, and provide file contents from the memory. Because buffers you are editing does nothing to do with real filesystems, however, we need to tell nix do not access filesystems directly. This prevents us collecting language information from pure-evaluated nix flakes.
Status
I just released the first version (which means all trivial features are implemented and tested). And the code base is in rapid development. The status page could be found here. I just submitted a PR: nixpkgs#236675
Feedback
Any questions & feature request please comment here
Update v1.1.0:
Main topic: Nixd 1.1.0 released
Completely New Features
Goto Definition - Values (e.g. lambdas, attrs)
Goto Definition - Derivations
Document Symbol
Document Link
Rename
Static Analysis
Provide static bindings (such as rec
) without any evaluation.
Improvements
Automatic Evaluation
You don’t need to manually set “eval depth”. Nixd will evaluate where you touched lazily.
Diagnostic
Show nix stack trace (completely consistent with official implementation)
Option System
The nixpkgs option auto-completion subsystem will show you example if specified.