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.
Note
Thanks to https://github.com/wmertens/sublime-nix for the original grammar!
Nix code snippets inside markdown
files also work.
Full editing support when using a language server. Generally, any Nix LSP implementation should work.
The following have been tested so far:
{
"nix.enableLanguageServer": true,
"nix.serverPath": "nil",
// or
"nix.serverPath": "nixd"
}
Pass settings to the language server via the serverSettings
option.
{
"nix.serverSettings": {
"nil": {
"diagnostics": {
"ignored": ["unused_binding", "unused_with"]
},
"formatting": {
"command": ["nixpkgs-fmt"]
}
}
}
}
{
"nix.serverSettings": {
"nixd": {
"formatting": {
"command": [ "nixpkgs-fmt" ]
},
"options": {
// By default, this entriy will be read from `import <nixpkgs> { }`.
// You can write arbitary Nix expressions here, to produce valid "options" declaration result.
// Tip: for flake-based configuration, utilize `builtins.getFlake`
"nixos": {
"expr": "(builtins.getFlake \"/absolute/path/to/flake\").nixosConfigurations.<name>.options"
},
"home-manager": {
"expr": "(builtins.getFlake \"/absolute/path/to/flake\").homeConfigurations.<name>.options"
},
// Tip: use ${workspaceFolder} variable to define path
"nix-darwin": {
"expr": "(builtins.getFlake \"${workspaceFolder}/path/to/flake\").darwinConfigurations.<name>.options"
}
}
}
}
}
Enable formatting support by setting nix.formatterPath
to any command which can accept file contents on stdin and return formatted text on stdout.
{
"nix.formatterPath": "nixpkgs-fmt"
}
{
"nix.formatterPath": "nixfmt"
}
{
"nix.formatterPath": ["treefmt", "--stdin", "{file}"]
}
{
"nix.formatterPath": ["nix", "fmt", "--", "-"] // using flakes with `formatter = pkgs.alejandra;`
}
Errors reported using nix-instantiate
.
Snippets are provided for conditional expressions, let
expressions, with
expressions, and rec
ursive sets.
- Embedded language support for Bash.
- Path completion.
- Document the purpose of functions and classes.
- Please mention new features in the
README.md
features section. Use screenshots when applicable. - The Conventional Commits style should be used for commit messages as it is used to generate the changelog.
There is direnv and nix-shell support so a dev environment can be created with the nix-shell
command or a one-time direnv allow
at the root of the repo.
Press F5
in VSCode to run an Extension Development Host instance with the extension installed.
TypeScript is used to develop the extension.
yarn install # install dependencies
yarn build # build the extension
Complete .env
with environment variables based on .env.template
,
# this is needed to publish extensions to [openvsx](https://open-vsx.org/) from local machine.
yarn env-cmd
# this will generate changelog and will create a GitHub release. This will also trigger jobs to publish the extension.
yarn release
# to manually publish the extension
yarn publish
Special thanks to:
- @wmertens for writing the grammar.
- The vscode-fish extension, which was modified to work for Nix in this extension.