2022-12-01 03:24:59 +03:00
# nil: NIx Language server
2022-08-01 04:31:10 +03:00
2023-03-10 08:49:58 +03:00
[![CI ](https://github.com/oxalica/nil/actions/workflows/ci.yaml/badge.svg )](https://github.com/oxalica/nil/actions/workflows/ci.yaml)
2022-09-19 04:45:49 +03:00
2023-02-13 18:31:24 +03:00
An incremental analysis assistant for writing in Nix.
2022-08-02 07:03:47 +03:00
2023-03-08 07:20:59 +03:00
See [release notes ](https://github.com/oxalica/nil/releases ) for changelog between releases.
2022-09-22 19:09:41 +03:00
2022-09-26 10:53:04 +03:00
See [`docs/features.md` ](docs/features.md ) for an incomplete list of notable features currently
2022-09-22 19:09:41 +03:00
implemented or planned.
2022-11-25 18:43:54 +03:00
See [`docs/configuration.md` ](docs/configuration.md ) for all tunable configuration options.
2022-08-01 04:31:10 +03:00
## Installation
2023-03-08 07:20:59 +03:00
This program is available in [NixOS/nixpkgs ](https://github.com/NixOS/nixpkgs ) under attribute `nil` ,
and is regularly updated.
2022-09-22 19:09:41 +03:00
- If you use `nix-env` , run `nix-env -iA nixpkgs.nil`
- If you use `nix profile` , run `nix profile install nixpkgs#nil`
2023-03-08 07:20:59 +03:00
- If you want to compile it from source:
2023-11-08 09:05:37 +03:00
1. Install stable Rust toolchain >= 1.70
2023-03-08 07:20:59 +03:00
1. Install nix >= 2.4 and make sure the binary `nix` is in your `PATH` .
2022-09-27 17:17:40 +03:00
1. Build and install via `cargo install --git https://github.com/oxalica/nil nil`
2022-09-22 19:09:41 +03:00
2023-03-08 07:20:59 +03:00
## Install with [Flake](https://nixos.wiki/wiki/Flakes)
2022-09-22 19:09:41 +03:00
2023-03-08 07:20:59 +03:00
This repo is also packaged via Nix flakes. The language server package is
available in the default flake output `github:oxalica/nil#` , under `bin/nil` .
2022-08-04 10:53:05 +03:00
2023-03-08 07:20:59 +03:00
To install, run `nix profile install github:oxalica/nil` . Alternatively,
you can use this repository as a flake input, and add its output to your own flake-managed
system-wide and/or home configurations.
2022-08-05 14:01:45 +03:00
2023-03-08 07:20:59 +03:00
*Disclaimer: The `flake.lock` we ship is tested in CI. If you use `follows` to
override flake inputs, we do not guarantee that it will build.*
2022-12-01 03:24:59 +03:00
2023-03-08 07:20:59 +03:00
Flake output structure (not necessarily up-to-date):
2022-08-04 10:53:05 +03:00
```
├───devShells
│ └───(...)
└───packages
├───x86_64-linux
│ ├───default: package 'nil-unstable-2022-08-04'
│ └───nil: package 'nil-unstable-2022-08-04'
└───(...)
```
2022-09-05 16:51:02 +03:00
## Editor integration
2022-08-01 04:31:10 +03:00
2023-03-08 07:20:59 +03:00
### Neovim native LSP and [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig)
2022-09-22 19:09:41 +03:00
2023-03-08 07:20:59 +03:00
We are officially supported by nvim-lspconfig, see [upstream docs ](https://github.com/neovim/nvim-lspconfig/blob/0fafc3ef648bd612757630097c96b725a36a0476/doc/server_configurations.txt#nil_ls ),
also [the example config for testing ](dev/nvim-lsp.nix ).
2022-09-05 16:51:02 +03:00
2023-05-20 01:21:10 +03:00
:warning: There is a known performance issue for semantic highlighting with
neovim native LSP. See more details in https://github.com/oxalica/nil/issues/83
2023-03-08 07:20:59 +03:00
### Vim/Neovim with [coc.nvim](https://github.com/neoclide/coc.nvim)
2022-09-05 16:51:02 +03:00
2023-03-08 07:20:59 +03:00
Merge this setting into your `coc-settings.json` (open with `:CocConfig` ).
2022-09-05 16:51:02 +03:00
2022-11-25 18:43:54 +03:00
```jsonc
2022-09-05 16:51:02 +03:00
{
"languageserver": {
"nix": {
"command": "nil",
"filetypes": ["nix"],
2022-11-25 18:41:09 +03:00
"rootPatterns": ["flake.nix"],
// Uncomment these to tweak settings.
// "settings": {
// "nil": {
// "formatting": { "command": ["nixpkgs-fmt"] }
// }
// }
2022-09-05 16:51:02 +03:00
}
2022-08-01 04:31:10 +03:00
}
2022-09-05 16:51:02 +03:00
}
2022-08-01 04:31:10 +03:00
```
2023-03-08 07:20:59 +03:00
See [the example config for testing ](dev/vim-coc.nix ).
2022-09-22 19:09:41 +03:00
2023-03-08 07:20:59 +03:00
### Vim with [vim-lsp](https://github.com/prabirshrestha/vim-lsp)
2022-09-28 13:17:33 +03:00
2023-03-08 07:20:59 +03:00
Add the following code to your `~/.vimrc` to register the LSP server.
2022-09-28 13:17:33 +03:00
Thanks @mitchmindtree
```vim
if executable('nil')
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'nil',
\ 'cmd': {server_info->['nil']},
\ 'whitelist': ['nix'],
\ })
endif
```
2023-03-08 07:20:59 +03:00
### Emacs with [lsp-mode](https://github.com/emacs-lsp/lsp-mode)
2022-12-25 00:09:04 +03:00
Add the following elisp code to your configuration. (using `use-package` )
```elisp
(use-package lsp-mode
:ensure t)
(use-package lsp-nix
:ensure lsp-mode
:after (lsp-mode)
:demand t
:custom
(lsp-nix-nil-formatter ["nixpkgs-fmt"]))
(use-package nix-mode
:hook (nix-mode . lsp-deferred)
:ensure t)
```
2023-03-08 07:20:59 +03:00
There are various other configurations to tweak. Refer to the
[specific manual page ](https://emacs-lsp.github.io/lsp-mode/page/lsp-nix-nil/ ) for more details.
2022-09-05 16:51:02 +03:00
2023-03-08 07:20:59 +03:00
### Emacs with [eglot](https://github.com/joaotavora/eglot)
2022-08-05 14:01:45 +03:00
Add the following elisp code to your configuration. (using `use-package` )
```elisp
(use-package nix-mode)
(use-package eglot
:config
;; Ensure `nil` is in your PATH.
(add-to-list 'eglot-server-programs '(nix-mode . ("nil")))
:hook
(nix-mode . eglot-ensure))
```
2023-03-08 07:20:59 +03:00
### VSCode/VSCodium with [Nix IDE](https://github.com/nix-community/vscode-nix-ide)
2022-09-24 12:52:40 +03:00
Modify the extension's settings in your `settings.json` .
2022-08-27 23:02:40 +03:00
```jsonc
{
2022-09-24 12:52:40 +03:00
"nix.enableLanguageServer": true, // Enable LSP.
"nix.serverPath": "nil" // The path to the LSP server executable.
2022-11-25 18:41:09 +03:00
// Uncomment these to tweak settings.
// "nix.serverSettings": {
// "nil": {
// "formatting": { "command": ["nixpkgs-fmt"] }
// }
// }
2022-08-27 23:02:40 +03:00
}
```
2023-03-08 07:20:59 +03:00
### Kate with [LSP Client Plugin](https://docs.kde.org/stable5/en/kate/kate/kate-application-plugin-lspclient.html)
2022-12-25 00:05:06 +03:00
Add this to your "User Server Settings" in LSP Client configuration:
```json
{
"servers": {
"nix": {
"command": ["nil"],
"url": "https://github.com/oxalica/nil",
"highlightingModeRegex": "^Nix$"
}
}
}
```
2022-08-01 04:31:10 +03:00
## License
"nil" is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.