Please update this doc (tweaks, tricks, or how to setup for another editor)!
Editor Setup Guide
This is the description about how to setup your editor to use nixd.
Installation - get a working executable
Package nixd can be found in nixpkgs.
NixOS Configuration
{ pkgs, ... }: {
environment.systemPackages = with pkgs; [
nixd
];
}
nix-env(legacy commands)
On NixOS:
On Non NixOS:
nix profile
nix profile add github:nixos/nixpkgs#nixd
And our flake.nix provides a package named nixd with "unstable" experience.
Note that please do NOT override nixpkgs revision for nixd inputs. The source code have tested on specific version on NixOS/nix, which may not work at your version.
Teach your editor find the executable, and setup configurations.
VSCode
https://github.com/nix-community/vscode-nix-ide extension provide a general interface for nixd, and it should work out of box. Please file a bug if you encountered some trouble using the extension.
(Neo)vim
Coc.nvim
According to :help coc-config.txt, coc-settings.json:
{
"languageserver": {
"nix": {
"command": "nixd",
"filetypes": ["nix"]
}
}
}
Neovim
Neovim native LSP and nvim-lspconfig. We are officially supported by nvim-lspconfig, see upstream docs
Emacs
Eglot
The following configuration can be used with the built-in Emacs LSP client: Eglot.
-lisp
(add-hook 'prog-mode-hook
(lambda ()
(add-hook 'before-save-hook 'eglot-format nil t)))
(with-eval-after-load 'eglot
(dolist (mode '((nix-mode . ("nixd"))))
(add-to-list 'eglot-server-programs mode)))
lsp-mode
A simple Emacs Lisp configuration that adds nixd to LSP Mode in the mean time is as follows:
-lisp
(with-eval-after-load 'lsp-mode
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection "nixd")
:major-modes '(nix-mode)
:priority 0
:server-id 'nixd)))
Helix
nixd will be supported by default in the next release after 24.07.
languages.toml
[[language]]
name = "nix"
language-servers = ["nixd","nil"]
[language-server.nixd]
command = "nixd"
KDE Kate
Kate with LSP Client Plugin:
/$HOME/$USER/.config/kate/lspclient/settings.json
{
"servers": {
"nix": {
"command": ["nixd"],
"url": "https://github.com/nix-community/nixd",
"highlightingModeRegex": "^Nix$"
}
}
}
Change the configuration.
Read the configuration docs here.