Skip to content
项目

关于

VSCode 编辑器的 Nix 语言支持[维护者:@jnoortheen]

开发工具

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Nix ✨💡🌟

Adds Nix language support for Visual Studio Code.

Quickstart 🚀

  1. Install the extension, and open a Nix file.
  2. Syntax highlighting should work out of the box. Nix code blocks inside markdown files are also supported.
  3. Auto-formatting should work if nixfmt is available in $PATH. A custom formatter can be set by configuring nix.formatterPath.
  4. Syntax errors are linted using nix-instantiate.
  5. Full language support can be enabled by configuring a language server. See LSP Plugin Support for more information.
  6. Snippets are provided for conditional expressions, let/with expressions, and recursive sets.
  7. Path completion is supported using the Path Intellisense extension.

Settings ⚙️

LSP Plugin Support

Full language support can be enabled by using a language server. Generally, any Nix LSP implementation should work. Some examples are given below for nil and nixd.

{
  "nix.enableLanguageServer": true,
  "nix.serverPath": "nil", // or "nixd", or ["executable", "argument1", ...]
  // LSP config can be passed via the ``nix.serverSettings.{lsp}`` as shown below.
  "nix.serverSettings": {
    // check https://github.com/oxalica/nil/blob/main/docs/configuration.md for all options available
    "nil": {
      // "diagnostics": {
      //  "ignored": ["unused_binding", "unused_with"],
      // },
      "formatting": {
        "command": ["nixfmt"],
      },
    },
    // check https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md for all nixd config
    "nixd": {
      "formatting": {
        "command": ["nixfmt"],
      },
      "options": {
        // By default, this entry will be read from `import <nixpkgs> { }`.
        // You can write arbitrary 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",
        },
      },
    }
  }
}
Home Manager integrated as a NixOS module

When Home Manager is integrated into a NixOS configuration, its options are stored under that configuration instead of homeConfigurations. Configure the home-manager option set like this:

{
  "nix.serverSettings": {
    "nixd": {
      "options": {
        "home-manager": {
          "expr": "(builtins.getFlake (builtins.toString ./.)).nixosConfigurations.<name>.options.home-manager.users.type.getSubOptions []",
        },
      },
    },
  },
}

Replace <name> with the key of the matching nixosConfigurations entry.

Custom Formatter

It can be changed by setting nix.formatterPath to any command which can accept file contents on stdin and return formatted text on stdout.

[!IMPORTANT] If you are using the above LSP plugin setting, then this configuration is not used.

{
    "nix.formatterPath": "nixfmt" // or "alejandra"
    // or pass full list of args like below
    // "nix.formatterPath": ["treefmt", "--stdin", "{file}"]
}

Contributing 💪

We welcome contributions to this extension. Kindly start with any of open issues or feature requests.

See CONTRIBUTING.md for more information.

Credits

Special thanks to:

探索相关项目

加载中…