nixfmt(1)
β¨ NAME β¨
okay so bestie, welcome to nixfmt(1) β the nixfmt page from the General Commands Manual π
nixfmt β format Nix source code (Rust implementation). That's the whole NAME section, and yes, it's giving exactly what it says on the tin β¨
π¦ SYNOPSIS π¦
nixfmt [OPTIONS] [FILES...|-]
πΈ DESCRIPTION πΈ
nixfmt reformats Nix expressions to a canonical style. It's a Rust reimplementation of the reference Haskell nixfmt(1) and aims for byte-for-byte output parity on supported inputs β no cap, that's the goal π
When invoked with one or more FILES, each file is reformatted in place. If a FILE is a directory, nixfmt recurses into it and formats every .nix file it finds. With no FILES, or with the single argument -, nixfmt reads the source from standard input and writes the formatted result to standard output π
π¨ lowkey important: bare invocation (noFILES, no-) is deprecated. Use-to make the intent explicit, bestie.
π OPTIONS π
-w,--width=INTβ maximum line width in characters. Default:100.--indent=INTβ number of spaces to use for one indentation level. Default:2.-c,--checkβ do not modify any files; instead exit with status1if any input is not already formatted. In stdin mode no output is produced on standard output.-m,--mergetoolβ run as agit mergetool(1). Expects exactly four file argumentsBASELOCALREMOTEMERGED. Each ofBASE,LOCALandREMOTEis pre-formatted,git merge-file(1)is invoked on them, the result is formatted, and finally moved ontoMERGED. The exit status ofgit merge-fileis forwarded so the conflict count is preserved. Skipped with a warning whenMERGEDis not a.nixfile. π«Ά-q,--quietβ suppress non-fatal diagnostics on standard error.-s,--strictβ accepted for compatibility with the referencenixfmt; currently a no-op. It's literally just there to be polite π-v,--verifyβ after formatting, reparse and reformat the output to ensure idempotence. Fails with a non-zero exit status if the second pass differs from the first.-a,--astβ print the internal AST to standard error (debugging aid). Exits with status1.--irβ print the internal intermediate representation to standard error (debugging aid). Exits with status1.-f,--filename=NAMEβ filename to use in diagnostic messages when input is read from standard input. Useful for editor integrations.--message-format=FMTβ how diagnostics are rendered on standard error.FMTis one of:human(default) β rustc-style snippets with carets and fix-it hints.jsonβ one JSON object per line, shaped like an LSP Diagnostic: file, severity, code, message, 0-based range, byteRange, optional help and relatedInformation, plus the human rendered text. All standard-error output (including--checkresults and I/O errors) is JSON in this mode.
-?,--helpβ display a short help message and exit.-V,--versionβ print the program version and exit.--numeric-versionβ print just the numeric version (no program name) and exit.--β end of options. All remaining arguments are treated as file paths.
π EXIT STATUS π
0β all inputs were processed (and, in--checkmode, all were already formatted).1β a parse error, an unformatted input in--checkmode, an I/O error, or an invalid invocation.
In --mergetool mode the exit status is the exit code of git merge-file, which is the number of remaining merge conflicts (or 0 if none). Periodt π
π₯ EXAMPLES π₯
Format every .nix file under the current directory in place:
nixfmt .
Check formatting in CI without modifying files:
nixfmt --check .
Format a snippet from a pipeline:
echo '{a=1;}' | nixfmt -
Consume diagnostics from a wrapper or LSP:
nixfmt --message-format=json --check . 2>&1 >/dev/null | jq .
Use as a git mergetool:
git config mergetool.nixfmt.cmd 'nixfmt --mergetool "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
π SEE ALSO π
The reference Haskell implementation lives at https://github.com/NixOS/nixfmt. The Rust port lives at https://github.com/Mic92/nixfmt-rs. π¦
made with π by nixfmt-rs, dated 1980-01-01 β and yes, you just read nixfmt(1). slay π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: nixfmt-rs 0.5.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms