Documentation / support for configuring for use with Nixd? #8474
-
Nixd has a number of advantages over the alternative LSPs, like However, when I add this to my languages.toml: [[language]]
name = "nix"
language-servers = [ "nixd" ] It fails silently, and Edit: Note that it does seem to work, at least partially, when I do the following instead of the above conf: [language-server]
nil = { command = "nixd" } I will test further. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 13 replies
-
Support for For instance, jumping to file paths appears to be broken, whereas it works with |
Beta Was this translation helpful? Give feedback.
-
You need to define an entry for [language-server.nixd]
command = ...
args ... |
Beta Was this translation helpful? Give feedback.
-
With the following [[language]]
name = "nix"
language-servers = [ "nixd" ]
[language-server.nixd]
command = "nixd" I am getting this log output when attempting to With the CLI printing in red:
|
Beta Was this translation helpful? Give feedback.
-
With the new release it is now supported? |
Beta Was this translation helpful? Give feedback.
-
works with ❯ nixd --version
nixd, version: 2.1.2 didn't work with |
Beta Was this translation helpful? Give feedback.
-
In case it helps anyone, here's a rendered example of my (working) config for a flake-based NixOS system, which has been working reliably for me for the past couple years: [language-server.nixd]
command = "nixd"
[language-server.nixd.formatting]
command = ["alejandra"]
[language-server.nixd.nixpkgs]
expr = "import (builtins.getFlake \"/etc/nixos\").inputs.nixpkgs { }"
[language-server.nixd.options.nixos]
expr = "(builtins.getFlake \"/etc/nixos\").nixosConfigurations.<HOSTNAME>.options" Substitute for whatever you want. In my case, I use programs.helix.languages = {
language-server.rust-analyzer.config = {
checkOnSave.allTargets = true;
};
language-server.nixd = {
command = "nixd";
formatting = {
command = ["alejandra"];
};
nixpkgs.expr = "import (builtins.getFlake \"/etc/nixos\").inputs.nixpkgs { }";
options.nixos.expr = "(builtins.getFlake \"/etc/nixos\").nixosConfigurations.bld0.options";
}; |
Beta Was this translation helpful? Give feedback.
-
It seems that the accepted answer is incorrect and only works because, as @Brisingr05 stated, nixd is configured to provide NixOS options completions out of the box. {
inputs,
config,
osConfig,
pkgs,
lib,
...
}:
{
programs.helix = {
extraPackages = with pkgs; [ nixd ]; # Remove this if you prefer to add nixd in your env
languages = {
language = [
{
name = "nix";
auto-format = true;
}
];
language-server = {
nixd = {
command = "nixd";
args = [ "--semantic-tokens=true" ];
config.nixd =
let
myFlake = ''(builtins.getFlake "${inputs.self}")'';
nixosOpts = "${myFlake}.nixosConfigurations.${osConfig.networking.hostName}.options";
in
{
nixpkgs.expr = "import ${myFlake}.inputs.nixpkgs { }";
formatting.command = [ "${lib.getExe pkgs.nixfmt-rfc-style}" ];
options = {
nixos.expr = nixosOpts;
home-manager.expr = "${nixosOpts}.home-manager.users.type.getSubOptions []";
};
};
};
};
};
};
} |
Beta Was this translation helpful? Give feedback.
In case it helps anyone, here's a rendered example of my (working) config for a flake-based NixOS system, which has been working reliably for me for the past couple years:
Substitute for whatever you want. In my case, I use
home-manager
, so I configure it from a home-manager context like so: