Adds Nix language support for Visual Studio Code.
Available on both the Visual Studio Marketplace and the Open VSX Registry.
You can also open the Command Palette (Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on macOS) and enter ext install jnoortheen.nix-ide
to install the extension, or download it from the latest release.
- Install the extension
- Open a Nix file
- Syntax highlighting should work out of the box.
- Formatting the code should work if
nixpkgs-fmt
is installed and available on the PATH. - Full language support is available if you have a language server installed and enabled. See LSP Plugin Support for more information.
- Syntax Highlighting support. Also Nix code blocks inside
markdown
files also highlighted. - The basic language integration is supported out of the box using
nixpkgs-fmt
andnix instantiate
. Syntax Errors are linted usingnix-instantiate
while Auto-Formatting is handled bynixpkgs-fmt
by default. Custom formatter can be set by settingnix.formatterPath
. - The full language support is enabled by configuring an LSP server.
- Snippets are provided for conditional expressions,
let
expressions,with
expressions, andrec
ursive sets. - Path completion support using https://github.com/ChristianKohler/PathIntellisense extension
It can be changed by setting nix.formatterPath
to any command which can accept file contents on stdin and return formatted text on stdout.
{
"nix.formatterPath": "nixpkgs-fmt" // or "nixfmt" or ["treefmt", "--stdin", "{file}"]
// or using flakes with `formatter = pkgs.alejandra;`
// "nix.formatterPath": ["nix", "fmt", "--", "--"]
}
Full language support can be enabled by using a language server. Generally, any Nix LSP implementation should work.
{
"nix.enableLanguageServer": true,
"nix.serverPath": "nil", // or "nixd"
// Pass settings to the language server via the `serverSettings` option.
"nix.serverSettings": { ... }
}
Some examples of advanced settings are provided below for nil and nixd.
We welcome contributions to this extension. Kindly start with any of open issues or feature requests.
See CONTRIBUTING.md for more information.
Special thanks to:
- @wmertens for writing the grammar.
- The vscode-fish extension, which was modified to work for Nix in this extension.