Bridge between treefmt and jj fix.
Nix flakes with treefmt-nix define formatters declaratively, but jj fix requires separate configuration. Maintaining both is tedious and error-prone.
Additionally, jj fix requires tools to read from stdin and write to stdout, but many formatters (deadnix, ruff --fix) only support in-place file modification.
jmt automatically generates jj fix config from your existing treefmt setup:
- Single source of truth: Define formatters once in treefmt-nix, use everywhere
- Smart caching: Only rebuilds formatter when flake.nix/flake.lock changes
- stdin/stdout adaptation: Wraps incompatible tools with temp file workarounds
Unlike traditional formatters that modify files in your working copy:
- No merge conflicts: Formatting is applied per-commit, not to working copy
- Works with
jj absorb: Format changes are automatically absorbed into the right commits - Clean history: Each commit is formatted independently, even in stacked PRs
# Format all commits in current stack
jmt
# Then absorb any other changes - no conflicts!
jj absorbjmt # Sync config + run jj fix
jmt --sync # Only sync config
jmt --print # Print generated config
jmt --list # List available formatters
jmt --only=nixfmt,ruff # Run specific tools only
jmt -- -s @- # Pass args to jj fix (format parent){
inputs.jmt.url = "github:mulatta/jmt";
}nix run github:mulatta/jmtjj fix requires tools to read stdin and write stdout. jmt handles this automatically:
| Tool Type | Strategy | Example |
|---|---|---|
| Native stdin | Pass through | nixfmt, alejandra |
| Needs flag | Add stdin arg | yamlfmt -, taplo - |
| In-place only | Temp file wrapper | deadnix, ruff check --fix |
| Linters | Passthrough (stderr only) | shellcheck, statix |
Wrapper script pattern for in-place tools:
t=$(mktemp --suffix=.nix); cat >"$t"; deadnix -e "$t"; cat "$t"; rm "$t"- Build
nix build .#formatter.<system>(cached by mtime) - Extract treefmt.toml path from wrapper script
- Parse formatters, generate jj fix TOML with stdin-compatible commands
- Write to
.jj/repo/config.toml - Run
jj fix --include-unchanged-files
MIT