Home Explore Blog Models CI



nix

src/nix/formatter-run.md
1a5b52fa14bfae95fa534d577e51d691cb6cc18f3a8adce400000003000002e0
R""(

# Description

`nix fmt` (an alias for `nix formatter run`) calls the formatter specified in the flake.

Flags can be forwarded to the formatter by using `--` followed by the flags.

Any arguments will be forwarded to the formatter. Typically these are the files to format.

The environment variable `PRJ_ROOT` (according to [prj-spec](https://github.com/numtide/prj-spec))
will be set to the absolute path to the directory containing the closest parent `flake.nix`
relative to the current directory.


# Example

To use the [official Nix formatter](https://github.com/NixOS/nixfmt):

```nix
# flake.nix
{
  outputs = { nixpkgs, self }: {
    formatter.x86_64-linux = nixpkgs.legacyPackages.${system}.nixfmt-tree;
  };
}
```

)""

Chunks
cadc6879 (1st chunk of `src/nix/formatter-run.md`)
Title: `nix fmt` Command Description
Summary
The `nix fmt` command (an alias for `nix formatter run`) executes the formatter defined within a Nix flake. Users can pass flags and arguments directly to the formatter by using `--` followed by the desired options. Additionally, the `PRJ_ROOT` environment variable is set to the absolute path of the closest parent directory containing a `flake.nix` file. An example demonstrates how to configure `nixfmt-tree` as the formatter for `x86_64-linux` systems within a `flake.nix` file.