Skip to content

Formatting nix command exited with 256 with nix fmt mac #456

@loadx

Description

@loadx

Hi there I saw there was an existing ticket here: #426
However the proposed solution does not seem to resolve this issue.

I've ensures that nixd and nixfmt are installed though i am using nixfmt-rfc-style as opposed to nixfmt directly

I've used the exact same vscode configuration as defined here:
https://github.com/nix-community/vscode-nix-ide/blob/main/docs/snippets/advanced-nixd-settings.jsonc

Package versions:

❯ nixfmt --version
nixfmt nixpkgs-unstable-2024-12-04

❯ nixd --version
nixd, version: 2.5.1

To recreate the error you'll need to make a syntax error and then try and save the file, this is when the problem shows. I would cause this by removing the closing semi-colon from an attribute set.

The error appearing in vscode is:

I[00:06:22.947] 5301: <-- textDocument/formatting(67)
I[00:06:22.978] 5301: --> reply:textDocument/formatting(67) formatting nixfmt command exited with 256, error: 3
[Error - 00:06:22] Request textDocument/formatting failed.
  Message: formatting nixfmt command exited with 256
  Code: -32001 

When running this locally using nixfmt directly against the file in question:

❯ nixfmt zsh.nix
zsh.nix:22:5:
   |
22 |     };
   |     ^
unexpected '}'
expecting expression

Reviewing the exit code here I don't see the 256 error.

echo $?
1

Any help is much appreciated. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions