vscode-nix-ide icon indicating copy to clipboard operation
vscode-nix-ide copied to clipboard

formatting nixpkgs-fmt command exited with 65280,

Open maribrowne opened this issue 1 year ago • 3 comments

When I try to format with Nix IDE, I get this message:

formatting nixpkgs-fmt command exited with 65280, error: 3 [Error - 11:56:39 AM] Request textDocument/formatting failed.
Message: formatting nixpkgs-fmt command exited with 65280
Code: -32001

I've tried other commands such as nixfmt and nixfmt-classic

Screenshot_20240810_111217 Screenshot_20240810_111242 Screenshot_20240810_120445

My settings.json

"nix.enableLanguageServer": true,
    "nix.serverPath": "nixd",
    "nix.serverSettings": {
        "nixd": {
            "formatting": {
                "command": [ "nixpkgs-fmt" ]
             },
        },
    },
    "nix.formatterPath": "nixpkgs-fmt",

and the packages in my /etc/nixosconfiguration.nix file

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
     vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
     wget
     vscode
     telegram-desktop
     git
     nixd
  ];

maribrowne avatar Aug 10 '24 11:08 maribrowne

I had tried as well with nixfmt in my system packages and this did not work :( pls halp! NixOS newbie, so may be missing the obvious

maribrowne avatar Aug 10 '24 11:08 maribrowne

A quick fix would be to add nixpkgs-fmt to the environment to use the older formatter.

In my case, I encountered the same error because nixd releases <= v2.3.1, which was in the unstable channel, effectively forces usage of nixpkgs-fmt if you have flakes in the nixd configuration. nixpkgs-fmt was recently archived so there are also some migration pains to nixfmt at the moment.

Until a new release is merged, those that want to use another formatter can either use nixd from source/flake with the nix fmt flake option:

outputs = inputs: {
  formatter.x86_64-linux = inputs.nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
  ...
};

or the vscode-nix-ide configuration without flakes defined:

"nix.serverSettings": {
  "nixd": {
    "formatting": {
      "command": ["nixfmt"]
    }
  }
},

Both options still require the formatter package in the environment, from my testing.

myned avatar Aug 18 '24 20:08 myned

Thanks for the suggestions. For me, putting pkgs.nixfmt-rfc-style instead of pkgs.nixpkgs-fmt in my packages, and having in my VSCode config:

"nixd": {
			"formatting": {
				"command": "nixfmt"
			}
}

has the formatter working again.

Ten0 avatar Sep 02 '24 20:09 Ten0

Kindly check the same from terminal. If the issue persists, kindly reopen with the version number of nixpkgs-fmt to get more help.

jnoortheen avatar Jan 02 '25 06:01 jnoortheen