Closed AlexMakesSoftware closed 4 months ago
Are you using an FHS environment?
programs.vscode = {
enable = true;
package = pkgs.vscode.fhs;
};
No, I don't think so. I've just installed vscode the traditional way on linux, using my software package manager, and then installed the plugin using the vscode GUI. This has nothing to do with Nix or NixOS at this stage.
Have u set
"nix.enableLanguageServer": true
in your settings.json?
No, but it says it should 'just work' out of the box.
No, but it says it should 'just work' out of the box.
nixd should work out of box, but not this extension.
Alright... I added this in my settings.json:
{
"security.workspace.trust.untrustedFiles": "open",
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd"
}
and got the error:
Command nixd not found in $PATH Source: Nix IDE.
Oh I should add that I also added this bit just to see if that helped:
{
"security.workspace.trust.untrustedFiles": "open",
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
"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"
}
}
}
}
}
It did not.
and got the error:
Command nixd not found in $PATH Source: Nix IDE.
This error message is quite informative that you may not have nixd
installed in your system. For example, have you add it under environment.systemPackages
?
Odd. When I type 'nix --version' in my terminal outside of vscode, it says it's installed. Inside the vscode terminal though, it doesn't. Something seems to be misconfigured - taking a look.
Ah, my vscode was installed as a flatpack, so I uninstalled it and reinstalled it properly using a .deb package. Now my terminal is fixed and I can see nix is working fine there. Whilst I don't get the error on opening the 'nix' file, I still get the error when I try to reformat the code 'failed to run nixpkgs-fmt' and the extension doesn't actually seem to do anything - I get no syntax error highlighting or anything.
have you add it under
environment.systemPackages
?
When you say this, are you assuming I'm running NixOS? I'm not running NixOS.
Also, in the instructions for nixd, it says:
"https://github.com/nix-community/vscode-nix-ide extension provide a general interface for nixd, and it should work out of box. Please file a bug if you encountered some trouble using the extension."
I can't see any other installation instructions. What am I missing here?
@AlexMakesSoftware did you check the LSP config here https://github.com/nix-community/vscode-nix-ide?tab=readme-ov-file#language-servers ?
Yes. My settings.json:
{
"nix.enableLanguageServer": true,
"nix.serverPath": "nixd",
"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"
}
}
}
}
}
The error I get is "command nixd not found in $PATH' - which is because it's not installed of course. So I go to the nixd documentation and it says, (under how to integrate with different editors):
VSCode https://github.com/nix-community/vscode-nix-ide extension provide a general interface for nixd, and it should work out of box. Please file a bug if you encountered some trouble using the extension.
So, bug filed. Do with that what you will.
Just on the same page from your link, there is a detailed installing guide.
In my humble opinion, the solution to your question seems to be well-documented and maybe for some reason you haven't read it.
"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" } }
This configutation is also wrong. Please replace <name>
with your REAL flake output name, likely it should be your hostname.
Maybe not very appropriate,
I'd like to recommend you try to read the manual/guide lines before submitting issues.
Thanks for pointing out the
Yes, I wrongly assumed that that step of getting the executable was optional, since it talks about fetching it only with Nix. Now I've got my vscode installed through apt - (like most people using vscode would), not Nix. If I went the Nix route - my vscode wouldn't see it, you see? Now, if it's a must-do and you must use nix, maybe make that clearer?
No worries though, if you think I'm just not interpreting the manual properly, that's your call I guess. To be honest I gave up and went to VSCodium instead using the flake mentioned in the other bit of the documentation - that worked. Close this issue if you like, but it might help others following to add just a bit more explanation. Just my humble opinion.
After installing vscode-nix-ide in vscode version 1.91.1 today, I found it produced an error 'spawn nix-instantiate ENOENT' when I opened a very basic 'hello world'-style shell.nix script. Auto-completion doesn't seem to work and formatting the file gives me another error 'failed to run nixpgs-fmt: spawn nixpks-fmt ENOENT'.
At first I thought this might be because I hadn't explicitly installed and set up a language server for Nix but upon reading your installation instructions for nixd, they say "vscode-nix-ide extension provide a general interface for nixd, and it should work out of box. Please file a bug if you encountered some trouble using the extension." - so I am. Apologies if I've misunderstood something here.