Repository navigation
feat(treefmt): add the treefmt integration - #98
Merged
Merged
Conversation
This was referenced Oct 17, 2026
clhodapp
force-pushed
the
feat/treefmt
branch
2 times, most recently
from
October 18, 2026 06:38
bd84099 to
697bee8
Compare
clhodapp
force-pushed
the
feat/treefmt
branch
from
October 18, 2026 08:25
81d46cf to
abf4292
Compare
A treefmt configuration is the formatters of a tree, written as treefmt-nix modules and evaluated at every system in force on the selected package set. caisson evaluates treefmt-nix's `submodule-modules` with its own `evalModules` on the composed library, with `pkgs` set to that package set and treefmt-nix's special arguments read from the type its `submoduleWith` returns. The outputs are the wrapper, the configuration file, the formatters and the check over a source tree. The configuration named `default` is published as `formatter.<system>`, which `nix fmt` runs; the pinned-world suite checks that it is the derivation treefmt-nix's `mkWrapper` builds. Publishing gains `exportsTo.bySystem`: an output keyed by the system of each evaluation first, `<attrset>.<system>.<name>`, or with `single` the one configuration named `default` at each system. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ly that configuration A tree with a treefmt configuration named `default` now also publishes `checks.<system>.treefmt`, the configuration's `check` over the root of the tree (`root` on `mkLib`), so `nix flake check` fails when the tree is not formatted. A tree without a root, such as a library composed inside a test, publishes no check. Every treefmt configuration used to be an entry for `formatter`, which holds a single value, so a second configuration, under any other name, was refused when the top published. Now only the configuration named `default` is published; one under another name is evaluated, passed up, and found through the manifest. `exportsTo` may be a list of exports, for an integration published in more than one output, and an export may carry `only`, a function of the manifest saying whether the configuration is published there. `exportsOf` replaces `exportsToOf` in the integrations library. The pinned-world test declares a second configuration, `docs`, which the previous integration refused, and checks the check is published over the root and absent without one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clhodapp
force-pushed
the
feat/treefmt
branch
from
October 18, 2026 17:35
abf4292 to
ffce768
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
caisson.treefmt, the first of the survey's strong candidates, and the publishing mode it needs. This PR is based on #97. Merge #94 through #97 first, then change the base of this PR tomain.The treefmt integration
A treefmt configuration is the formatters of a tree, written as treefmt-nix modules. It is evaluated per system, once for each system in force, on the selected package set. The integration is named
treefmtand resolves the ecosystem sourcetreefmt-nix, as the darwin integration resolvesnix-darwin.treefmt-nix's own
evalModuleruns on the library of a nixpkgs. Instead, caisson evaluates treefmt-nix's publishedsubmodule-moduleswith its ownevalModuleson the composed library, withpkgsset to the selected set. Those modules need treefmt-nix's special arguments, which treefmt-nix publishes only inside the type itssubmoduleWithreturns. caisson reads them from that type'sfunctor.payload.specialArgs, an attribute of the module system that isn't documented as public.The outputs are:
wrapper, the programnix fmtruns;configFile, thetreefmt.toml;programs, the formatters by name;check, a function from a source tree to a derivation that fails when the tree is not formatted.Only the configuration named
defaultis published, in two outputs:formatter.<system>nix fmtrunschecks.<system>.treefmtcheckover the root of the tree,rootonmkLib, whichnix flake checkbuilds; it fails when the tree is not formattedThe check is published where
mkLibis given aroot. A tree may declare treefmt configurations under other names besidedefault. For this,exportsTomay be a list of exports, and an export may carryonly, a function of the manifest that says whether the configuration is published in that output.exportsOfreads them in the integrations library.The pinned-world test checks four things:
formatterholds the exact derivation treefmt-nix'smkWrapperbuilds from the same module;checks.<system>holds onlytreefmt, the configuration'scheckover the root;docs, is evaluated.Built for real, the published check succeeds on a formatted tree and fails on an unformatted one, with the diff.
Publishing keyed by system
Flakes key
packages,formatterand others by system first, and caisson's publishing produced only flat names.exportsTo.bySystempublishes each configuration under the system of its evaluation, as<attrset>.<system>.<name>, named by the usual rules over its path without the systems on it. Combined withsingle, the output holds the configuration nameddefaultat each system, asformatter.<system>does. An output that mixes entries keyed by system with entries that aren't is refused, with their paths. A unit test covers all three cases. nvf, nixvim and kubenix will publish their packages this way.Checks
nix flake checkpasses.nix flake check --no-buildwith this branch in place of both caisson pins.🤖 Generated with Claude Code