treefmt-nix and nix fmt guide. Unified formatting and linting with treefmt. Use when configuring or running nix fmt, treefmt, or adding formatters/linters to a Nix project.
From nix-tasukenpx claudepluginhub ncaq/konoka --plugin nix-tasukeThis skill uses the workspace's default tool permissions.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Guides agent creation for Claude Code plugins with file templates, frontmatter specs (name, description, model), triggering examples, system prompts, and best practices.
treefmtはプロジェクト内の複数言語ファイルを一コマンドで並列フォーマットするツールです。 treefmt-nixはNixモジュールシステムでtreefmtを設定・管理するラッパーです。
nix fmtコマンドはflakeのformatter出力を呼び出します。
treefmt-nixを組み込むとnix fmtの実体がtreefmtになり、
設定されたすべてのプログラムが実行されます。
FlakeはGitで追跡されているファイルのみを対象とするため、
新規ファイルがある場合は事前にgit ls-files --others --exclude-standard -z | git add --intent-to-add --pathspec-from-file=- --pathspec-file-nulを実行してください。
未追跡ファイルがなく空の入力でもエラーにはなりません。
nix fmtやtreefmtという名前から「フォーマッタだけ」と誤解されがちですが、
treefmt-nixのprogramsにはリンターやチェッカーが多数含まれています。
フォーマッタの例:
nixfmtprettierrustfmtshfmtリンターの例:
actionlintdeadnixhlintshellcheckstatixその他:
typos(スペルチェック)zizmor(GitHub Actionsセキュリティ)treefmtのフォーマッタ仕様は「ファイルパスのリストを受け取り、変更があればファイルに書き戻す」というものです。 リンターはファイルを変更しませんが、エラー時に非ゼロ終了するためtreefmtがエラーとして検出します。
flake-partsを使う場合の例です。
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
flake-parts,
treefmt-nix,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
treefmt-nix.flakeModule
];
systems = [
"aarch64-linux"
"x86_64-linux"
];
perSystem = { pkgs, ... }: {
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
prettier.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
};
};
};
};
}
nix fmtで全プログラムが実行されます。
treefmtの設定モジュールを使ってカスタム引数を渡すこともできます。
しかしなるべくflake.nixに書くのではなく、 そのツール自体が標準的に使う設定ファイルなどに設定を書き込んでください。
そうするとそのツールをnix fmt経由以外で使うときも同じ設定が適用されるため一貫性が保たれます。
引数しか設定方法がないツールの場合などは仕方がないのでflake.nixに書いても構いません。
| プログラム | 種類 | 説明 |
|---|---|---|
deadnix | リンター | 未使用コードの検出 |
nixfmt | フォーマッタ | 公式のNixフォーマッタ |
statix | リンター | アンチパターンの検出と自動修正 |
| プログラム | 種類 | 説明 |
|---|---|---|
shellcheck | リンター | シェルスクリプトの静的解析 |
shfmt | フォーマッタ | シェルスクリプトのフォーマット |
| プログラム | 種類 | 説明 |
|---|---|---|
prettier | フォーマッタ | JS/TS/CSS/HTML/JSON/Markdown/YAML等 |
| プログラム | 種類 | 説明 |
|---|---|---|
cabal-gild | フォーマッタ | Cabalファイルの整理 |
fourmolu | フォーマッタ | Haskellフォーマッタ |
hlint | リンター | Haskellのリファクタリング提案 |
| プログラム | 種類 | 説明 |
|---|---|---|
actionlint | リンター | GitHub Actions YAMLの検証 |
clang-format | フォーマッタ | C/C++のフォーマット |
gofmt | フォーマッタ | Goのフォーマット |
ruff-check | リンター | Pythonのリント |
ruff-format | フォーマッタ | Pythonのフォーマット |
rustfmt | フォーマッタ | Rustのフォーマット |
taplo | フォーマッタ | TOMLのフォーマット |
typos | チェッカー | ソースコード中のスペルチェック |
yamlfmt | フォーマッタ | YAMLのフォーマット |
zizmor | リンター | GitHub Actionsのセキュリティチェック |
上記は一部で、100以上のプログラムが定義されています。 全リストはtreefmt-nixのprogramsディレクトリを参照してください。
programsに定義されていないツールはsettings.formatterに直接定義できます。
treefmt.config = {
settings.formatter = {
editorconfig-checker = {
command = pkgs.editorconfig-checker;
includes = [ "*" ];
};
};
};
settings.formatter.<name>のフィールド:
| フィールド | 型 | 説明 |
|---|---|---|
command | string/path/derivation | 実行コマンド(必須) |
options | list of string | コマンド引数 |
includes | list of string | 対象ファイルのglobパターン(必須) |
excludes | list of string | 除外ファイルのglobパターン |
priority | int | 実行順序(値が小さいほど先、デフォルト0) |
globパターンはgobwas/globライブラリで処理され、
ツリールートからの相対パスに対してマッチします。
*はパス区切り/を含む任意の文字列にマッチするため、*.rsだけでリポジトリ全体の.rsファイルに再帰的にマッチします。
src/*.rsのようなディレクトリを含むパターンも機能し、src/以下の全.rsファイルに再帰的にマッチします。
**も使えますが*と実質同じ動作です。
settings.global.excludesを使うと全フォーマッタ共通でファイルを除外できます。
global excludesは各フォーマッタのincludes/excludesより先に処理されます。
treefmtのフォーマッタ仕様を満たす必要があります。
CLIが<command> [options] [...<files>]の形式で、変更があればファイルに書き戻し、エラー時は非ゼロ終了です。
仕様を満たさないツールはシェルスクリプトでラップしてください。