Hello hello
I have the Nix IDE extension on VSCode.
I’m getting the following error whenever I save, any idea how I could investigate this?
Failed to run nixpkgs-fmt: spawn nixpkgs-fmt ENOENT
Hello hello
I have the Nix IDE extension on VSCode.
I’m getting the following error whenever I save, any idea how I could investigate this?
Failed to run nixpkgs-fmt: spawn nixpkgs-fmt ENOENT
It means you don’t have the nixpkgs-fmt package installed.
Vscode will by default use it to format your code whenever you save. Either disable that feature or install the package.
Install the package with brew you mean?
Ideally with nix from the nixpkgs channel like @TLATER linked, but as long as you have a nixpkgs-fmt binary on your $PATH it should work fine, no matter how you got this package, but I’m not sure if it’s available in homebrew
I use neither vscode nor mac os, but I hear this package works well with vscode if you want to use nix shells to provide your development packages instead: Nix Environment Selector - Visual Studio Marketplace
You could also use home-manager: https://nix-community.github.io/home-manager/index.html#sec-install-nix-darwin-module.
Or indeed, just get your hands on a copy of the binary and dump it in a directory in $PATH.
Lots of ways to do it ![]()
There are lots of ways to do it, and “Ideally with nix from the nixpkgs channel” was given, but how? VSCode doesn’t, as far as I’m aware, run from within a Nix environment. Should that be a prerequisite? If I had some Nix-initializing code for my shell, it wouldn’t trigger when I run VSCode.
That’s precisely what the first plugin I linked to does, it changes your vscode environment to have all the variables from a nix-shell set: Nix Environment Selector - Visual Studio Marketplace
… or, yeah, you could start vscode in an environment that does have nixpkgs-fmt. It will trigger if it’s your ~/.profile (assuming a Unix desktop with normal user shell login, so maybe not MacOS?), and that in turn could be configured with home-manager. Or your distro package manager. Or brew.
It’s hard to give more specific advice without knowing specifics about your OS and how you start vscode, and what level of “installed” you want.
I’m seeing this issue on macOS despite having nixfmt-rfc-style in my home-manager config:
❯ which nixfmt
/Users/myuser/.nix-profile/bin/nixfmt
Shouldn’t VSCode be picking this up from my PATH?
Yes, I would expect that, depending on the exact configuration. Though whenever I hear “MacOS”, “PATH” and “GUI application”, I have to ask, how do you start VSCode?
If you’re using this specific extension (Nix IDE - Visual Studio Marketplace) then you’d need 0.4.0 or newer I believe to get nixfmt as the default formatter.
If you’re on an older version, you’d probably need something like this in settings.json:
"nix.serverSettings": {
"nil": {
"formatting": {
"command": [
"nixfmt"
]
},
}
},
(FWIW I use nil, I don’t know if something similar is needed for nixd.)