# 使用 Homebrew, Nix 安装 nixfmt

查看 nixfmt 的安装路径、可执行文件、元数据以及面向 AI 代理工作流的安全说明。

## 安装

```sh
sudo av install brew:nixfmt
```

其他安装命令:

### macOS

- Homebrew (100%):

```sh
brew install nixfmt
```

  证据: local Homebrew formula metadata

### Linux

- Nix (92%):

```sh
nix profile install nixpkgs#nixfmt
```

  证据: nixpkgs package indexes: pkgs/by-name/ni/nixfmt/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1

## 软件包事实

- **软件包键:** brew:nixfmt
- **软件包管理器:** Homebrew
- **版本:** 1.4.0
- **来源摘要:** Command-line tool to format Nix language code
- **主页:** <https://github.com/NixOS/nixfmt>
- **仓库:** <https://github.com/NixOS/nixfmt>
- **最后更新:** 2026-07-22T06:03:29Z
- **已生成:** 2026-08-03T19:37:03+00:00

## 可执行文件

- nixfmt (别名)

## 安装行为

- Bottle: 不可用

## 版本和新鲜度

- 页面生成时间: 2026-08-03
- 管理器版本: 1.4.0
## 项目历史与用法

nixfmt is the official formatter for Nix language code. It started as a formatter project, was donated into the NixOS organization, and became the reference implementation for the standard Nix format defined by RFC 166.

### 项目历史

The nixfmt changelog lists version 0.1.0 on May 11, 2019 as the first release and says it could parse all of nixpkgs and format it consistently, though not yet prettily in all places. The repository README later acknowledged that nixfmt was originally developed by Serokell and donated to become an official Nix project after RFC 166.

RFC 166 was merged on March 5, 2024. The RFC text on the pull request set out to define the initial standard Nix format, establish the Nix formatter team, create the official implementation, reformat Nixpkgs, and require default formatting in the Nix CLI to use the official formatter. nixfmt 1.0.0 was released on July 9, 2025 as the first stable release of the official formatter, with the changelog noting that formatting changed substantially from earlier nixfmt output.

### 采用历史

nixfmt's adoption is institutional inside the Nix ecosystem rather than measured only by direct installs. The README calls it the official formatter, says the standard is defined in `standard.md`, and documents editor integration, NixOS/Home Manager installation, `nixfmt-tree`, `treefmt-nix`, direct `treefmt`, and `git-hooks.nix` workflows.

On 2026-07-01, Homebrew listed nixfmt 1.3.1 with 1,388 installs over 365 days. That undercounts its real ecosystem role because many Nix users get it from Nixpkgs and invoke it through flakes, `nix fmt`, treefmt wrappers, editor integrations, or pre-commit hooks.

### 使用方式

The bare CLI is simple: `nixfmt < input.nix` formats stdin to stdout, and `nixfmt file.nix` formats a file in place. The README notes that `nixfmt` itself processes one file at a time and points project-level users toward wrappers such as `nixfmt-tree`, `treefmt-nix`, `treefmt`, and `git-hooks.nix`.

For flake-based workflows, the Nix manual documents `nix fmt` as rewriting Nix files to a canonical format using the formatter specified in the flake, including examples that set the formatter to `nixfmt`. That is the package-nerd adoption path: wire nixfmt into the flake, editor, or pre-commit hook and stop arguing about style.

### 为什么软件包爱好者会关心

nixfmt matters because Nix formatting moved from preference and competing tools toward a source-backed standard with a maintained official implementation. For package databases, it is a clean example of a developer tool whose status changed through governance: Serokell project, RFC-defined standard, NixOS-org repository, then official stable formatter.

### 时间线

- {'date': '2019-05-11', 'event': 'nixfmt 0.1.0 first release.'}
- {'date': '2024-03-05', 'event': 'RFC 166 merged.'}
- {'date': '2025-07-09', 'event': 'nixfmt 1.0.0 released as the first stable official formatter.'}
- {'date': '2026-07-01', 'event': 'Homebrew formula listed stable nixfmt 1.3.1.'}

### Related projects

- Nix
- Nixpkgs
- nixfmt-tree
- treefmt
- treefmt-nix
- git-hooks.nix

### 来源

- <https://formulae.brew.sh/formula/nixfmt>
- <https://github.com/NixOS/nixfmt>
- <https://github.com/NixOS/nixfmt/blob/master/CHANGELOG.md>
- <https://github.com/NixOS/nixfmt/blob/master/standard.md>
- <https://github.com/NixOS/rfcs/pull/166>
- <https://nix.dev/manual/nix/2.23/command-ref/new-cli/nix3-fmt>


## 安全说明

narrow executable package without higher-risk signals.

- **Geiger 风险:** 绿色 / 低
- narrow executable package without higher-risk signals

## 其他软件包管理器记录

- Nix - nixfmt: normalized package name match | nixpkgs package indexes: pkgs/by-name/ni/nixfmt/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1


## Combined YAML source

View the package source record on GitHub. [combined/nixfmt.yml](https://github.com/mxcl/pkgdb/blob/main/combined/nixfmt.yml)


## 来源

- pkg.so package database
- Geiger risk classifier
- curated package history
- pkgdb category and tag curation
- external package-manager database matches
- cross-ecosystem install command graph
