From b9f533be4f7d64be41b5c1b23874e23dfe3528b0 Mon Sep 17 00:00:00 2001 From: oqyude Date: Sun, 15 Nov 2026 06:32:26 +0300 Subject: [PATCH] =?UTF-8?q?chore(repo):=20treefmt-=D0=BA=D0=BE=D0=BD=D1=84?= =?UTF-8?q?=D0=B8=D0=B3=20=D0=B8=20devshell=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit treefmt.toml: nixfmt для .nix, shfmt для .sh. Все 137 отслеживаемых .nix файлов уже nixfmt-чистые — форматтер теперь страхует от дрейфа, а не переформатирует репозиторий. Ничего не форматируется автоматически. Форматтер доступен как `nix develop .#fmt` (treefmt + nixfmt + shfmt). Output `formatter` у флейка быть не может — см. пояснение в flake.nix. --- devshells/default.nix | 27 +++++++++++++++++++++++++++ treefmt.toml | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 treefmt.toml diff --git a/devshells/default.nix b/devshells/default.nix index f4a165d..0521946 100644 --- a/devshells/default.nix +++ b/devshells/default.nix @@ -44,6 +44,33 @@ in ''; }; + # `nix develop .#fmt` -> инструменты форматирования репозитория: + # treefmt + nixfmt + shfmt. Конфиг — treefmt.toml в корне репозитория. + # + # nix develop .#fmt --command treefmt # применить стиль + # nix develop .#fmt --command treefmt -- --fail-on-change . + # + # Почему devshell, а не output `formatter` флейка (который дал бы + # `nix fmt`): на закреплённом nixpkgs `nix flake check` падает с + # "'outPath' is not a valid system type" на любом derivation-выводе, + # включая `formatter = pkgs.hello`. Подробности — в flake.nix и README. + fmt = pkgs.mkShell { + name = "nixos-fmt-devshell"; + + buildInputs = with pkgs; [ + treefmt + nixfmt + shfmt + ]; + + shellHook = '' + echo "[fmt-devshell] treefmt: $(command -v treefmt)" >&2 + echo "[fmt-devshell] nixfmt: $(command -v nixfmt)" >&2 + echo "[fmt-devshell] shfmt: $(command -v shfmt)" >&2 + echo "[fmt-devshell] конфиг: treefmt.toml в корне репозитория" >&2 + ''; + }; + # `nix develop .#vtimeline` -> shell for testing the VeeamTimelineView # project (Playwright + ESLint + Prettier over a vanilla-JS frontend). vtimeline = pkgs.mkShell { diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 0000000..4ca9e6b --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,29 @@ +# treefmt configuration — one entry point for every formatter in the repo. +# +# `nix fmt` runs this (see the `formatter` output in flake.nix; the wrapper +# puts nixfmt and shfmt on PATH next to treefmt). +# +# Current state (measured 2026-11-15): +# * all 137 tracked .nix files are already nixfmt-clean — the formatter is a +# guard against future drift, not a mass reformat; +# * the three tracked .sh files are NOT shfmt-clean, so `nix fmt` will +# rewrite them. That is deliberate and safe: they are scripts, not +# behaviour. Nothing is formatted automatically on commit. +# +# Deliberately absent: a JSON/YAML formatter. The .agent artefacts are +# hand-written and reformatting them would bury every real diff in noise. +# ShellCheck is a linter, not a formatter — it runs as a CI check +# (.ci/flake-checks.nix), not here. + +[global] +# A formatter that fails must not stop the others: report and continue. +onfail = "append" + +[formatter.nixfmt] +command = "nixfmt" +includes = ["**/*.nix"] + +[formatter.shfmt] +command = "shfmt" +args = ["-i", "2", "-ci", "-w"] +includes = ["**/*.sh"]