From c9cbcf7cb6316ab7a7b2bb1f2e2847431a93e059 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Sat, 17 Oct 2026 01:52:44 -0700 Subject: [PATCH 1/2] feat(treefmt): add the treefmt integration 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.`, 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, `..`, or with `single` the one configuration named `default` at each system. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + configs/structural/impl/default.nix | 1 + docs/development/repository-structure.md | 2 +- lib-overlays/integrations/default.nix | 40 +++- lib-overlays/treefmt/default.nix | 225 +++++++++++++++++++++++ modules/generic/core/default.nix | 1 + modules/treefmt/core | 1 + tests/argument-errors/check.sh | 1 + tests/pinned-world/default.nix | 35 ++++ tests/unit/lib-overlays.nix | 71 +++++++ 10 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 lib-overlays/treefmt/default.nix create mode 120000 modules/treefmt/core diff --git a/README.md b/README.md index 3cf5c982..df9a7610 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ source by. | `disko` | `disko` | disk layouts written as disko reads them, whose machines import disko's NixOS module, so disko's command, `disko-install` and its image builder work on them | | `caisson-facter` | none | the hardware of a machine, a nixos-facter report checked against the report versions caisson knows and extended with a project's own options, with the NixOS configurations that run on it declared inside it; a machine gets the report through nixpkgs' `hardware.facter` | | `facter` | none | a `facter.json` as nixos-facter writes it, with the NixOS configurations that run on it declared inside it; a machine gets it as `hardware.facter.reportPath` | +| `treefmt` | `treefmt-nix` | the formatters of a tree, as treefmt-nix modules; the configuration named `default` is published as the `formatter.` that `nix fmt` runs | | `system-manager` | `system-manager` | the systems of machines running another Linux distribution, published as the `systemConfigs` that `system-manager switch` reads | | `structural` | none | a configuration that only exports and holds configurations beneath it: the top of a repository whose point is what it exports, such as caisson itself, or a layer at any depth | diff --git a/configs/structural/impl/default.nix b/configs/structural/impl/default.nix index 0fd0cff4..7de75c95 100644 --- a/configs/structural/impl/default.nix +++ b/configs/structural/impl/default.nix @@ -34,6 +34,7 @@ darwin terranix system-manager + treefmt ; }; diff --git a/docs/development/repository-structure.md b/docs/development/repository-structure.md index 6c42ecd2..1dbe5874 100644 --- a/docs/development/repository-structure.md +++ b/docs/development/repository-structure.md @@ -28,7 +28,7 @@ The layer users reach for: the integrations (`structural`, `flake-parts`, `nixpkgs`, `nixos`, `nixos-minimal`, `home-manager`, `home-manager-minimal`, `darwin`, `hjem`, `caisson-colmena`, `colmena`, `caisson-disko`, `disko`, `caisson-facter`, `facter`, `terranix`, -`system-manager`), each +`system-manager`, `treefmt`), each a library overlay contributing its `lib.caisson` namespace, registering its module class where it has a class (`nixos-minimal` and `home-manager-minimal` diff --git a/lib-overlays/integrations/default.nix b/lib-overlays/integrations/default.nix index 7faa2afd..90e98dc4 100644 --- a/lib-overlays/integrations/default.nix +++ b/lib-overlays/integrations/default.nix @@ -253,7 +253,10 @@ # declared under: a function of `{ name, manifest }`, the name # the configuration is passed up under and its manifest, # returning `value`, the name to publish it under, and - # optionally `description`, a sentence saying what it did. It is + # optionally `description`, a sentence saying what it did. It may + # carry `single`, for an output that holds the one configuration + # named `default`, and `bySystem`, for an output keyed by the + # system of each evaluation first (`packages..`). It is # recorded on the manifest, and applied where the configuration # is passed up (`entriesOf`). Null for a configuration that is # not published under a name. @@ -623,6 +626,8 @@ inherit manifest; inherit (exportsTo) attrset; single = exportsTo.single or false; + bySystem = exportsTo.bySystem or false; + system = manifest.system or null; value = exportsTo.value manifest; path = init prefix ++ [ ( @@ -716,6 +721,12 @@ # of the entry named `default`, the entry whose `exportsTo` says # `single`. Any other entry for that output is refused, since the # output has no names to hold it under. + # + # An output whose entries' `exportsTo` says `bySystem` is keyed by + # the system of each evaluation first, as flakes key `packages` + # and `formatter`: `.`, holding the entries + # evaluated at that system, named by the rules above over their + # paths without the systems on them, or the single value there. publish = entries: let @@ -724,6 +735,33 @@ attrset: let members = builtins.filter (entry: entry.attrset == attrset) entries; + keyed = builtins.filter (entry: entry.bySystem or false) members; + systems = unique (builtins.map (entry: entry.system) keyed); + withoutSystems = + entry: entry // { path = builtins.filter (segment: segment.type != "system") entry.path; }; + in + if keyed == [ ] then + publishMembers attrset members + else if builtins.length keyed != builtins.length members || builtins.elem null systems then + throw '' + ${attrset}: this output is keyed by system, and these configurations + would be published there without a system: + ${builtins.concatStringsSep "\n" ( + builtins.map (entry: " ${showPath entry.path}") ( + builtins.filter (entry: !(entry.bySystem or false) || entry.system == null) members + ) + )} + '' + else + genAttrs systems ( + system: + publishMembers "${attrset}.${system}" ( + builtins.map withoutSystems (builtins.filter (entry: entry.system == system) keyed) + ) + ); + publishMembers = + attrset: members: + let names = builtins.map displayName ( final.caisson-core.elide (builtins.map (entry: entry.path) members) ); diff --git a/lib-overlays/treefmt/default.nix b/lib-overlays/treefmt/default.nix new file mode 100644 index 00000000..2a5db890 --- /dev/null +++ b/lib-overlays/treefmt/default.nix @@ -0,0 +1,225 @@ +# SPDX-License-Identifier: MIT +# +# The treefmt integration: it owns the `treefmt` class, the class of +# treefmt-nix's modules. A treefmt configuration is the formatters of a +# tree: `programs..enable` and `settings`, as treefmt-nix writes +# them. It is evaluated at every system in force where it is declared, +# on the package set selected for it. +# +# treefmt-nix evaluates its modules with `evalModules` on the library of +# a nixpkgs. caisson evaluates them with its own `evalModules`, on the +# composed library, over the modules treefmt-nix publishes for a +# configuration embedded in another, `submodule-modules`, with `pkgs` +# set to the selected package set. Those modules need treefmt-nix's +# special arguments, which treefmt-nix publishes only inside the type +# its `submoduleWith` returns, so caisson reads them from that type. +# +# The outputs are what treefmt-nix builds: `wrapper`, treefmt with its +# configuration, which `nix fmt` runs; `configFile`, the `treefmt.toml`; +# `programs`, the formatters by name; and `check`, the function that +# takes a source tree and builds a derivation that fails when the tree +# is not formatted. The configuration declared under the name `default` +# is published as `formatter.`, its wrapper, which `nix fmt` +# reads. +{ + mkLibOverlay, + ... +}: +{ + + imports = [ + # The library of nixpkgs, which this overlay calls through the + # composed library, imported by key so it is composed wherever + # this is. + ((mkLibOverlay ../nixpkgs-lib) // { key = "nixpkgs-lib"; }) + # What an integration is written from, imported by key so it is + # composed wherever this integration is. + ((mkLibOverlay ../integrations) // { key = "integrations"; }) + ]; + + overlay = + final: prev: + let + context = "lib.caisson.treefmt.mkConfiguration"; + + resolveEcosystemSrc = final.caisson.integrations.resolveEcosystemSrc { + name = "treefmt-nix"; + context = "caisson.treefmt"; + }; + + # A treefmt-nix source: the treefmt-nix flake or source tree, whose + # `default.nix` is its library. + libraryOf = + ecosystemSrc: + let + path = if builtins.isAttrs ecosystemSrc then ecosystemSrc.outPath or null else ecosystemSrc; + library = if path != null && builtins.pathExists "${path}/default.nix" then import path else { }; + in + if library ? submodule-modules && library ? submoduleWith then + library + else + throw "${context} requires `ecosystemSrc` to be a treefmt-nix flake or source tree (whose default.nix has submodule-modules and submoduleWith)."; + + evaluate = + args: + { lib, manifest }: + let + selection = lib.caisson.integrations; + treefmt = libraryOf (resolveEcosystemSrc { + explicit = args.ecosystemSrc or null; + manifest = lib.caisson-core.libManifest or { }; + }); + + name = manifest.name or null; + inherit (manifest) system; + what = + if name != null then + "the treefmt configuration `${name}` at ${system}" + else + "this treefmt configuration at ${system}"; + + pkgSets = selection.pkgSetsAt { inherit context what; } manifest system; + pkgs = selection.pkgSetOf { inherit context what; } manifest pkgSets; + + registry = lib.caisson.modules.treefmt or { }; + frameworkModules = selection.frameworkModules "treefmt" registry; + moduleImports = selection.moduleImportsOf "treefmt" { inherit lib manifest; } args; + + # The configuration's module: the module passed, else the + # configuration registered under the configuration's name + # (`configs/treefmt/`), else none. + registered = lib.caisson.configs.treefmt or { }; + configModule = + if (args.configModule or null) != null then + args.configModule + else if name != null then + registered.${name} or null + else + null; + + # treefmt-nix's special arguments, from the type its + # `submoduleWith` returns. + upstreamSpecialArgs = (treefmt.submoduleWith lib { }).functor.payload.specialArgs; + + value = lib.evalModules ( + { + class = "treefmt"; + specialArgs = + upstreamSpecialArgs + // { + inherit lib pkgSets; + } + // (if (args.specialArgs or null) != null then args.specialArgs else { }); + modules = + treefmt.submodule-modules + ++ [ + { + _file = "caisson-treefmt:pkgs"; + inherit pkgs; + } + ] + ++ frameworkModules + ++ moduleImports registry + ++ (if configModule == null then [ ] else [ configModule ]); + } + // (if (args.ecosystemArgs or null) != null then args.ecosystemArgs else { }) + ); + inherit (value.config) build; + in + { + inherit value; + outputs = { + inherit (build) + wrapper + configFile + programs + check + ; + }; + }; + + # The configuration named `default` is published as + # `formatter.`, which `nix fmt` reads. + exportsTo = { + attrset = "formatter"; + single = true; + bySystem = true; + value = manifest: manifest.outputs.wrapper; + }; + + configuration = + args: + final.caisson.integrations.mkModuleConfiguration { + type = "treefmt"; + # A treefmt configuration is evaluated at a system: it has an + # evaluation for every system in force where it is declared. + perSystem = true; + defaultPkgs = args.defaultPkgs or null; + inherit exportsTo; + evaluate = evaluate args; + }; + + integration = final.caisson.integrations.mkIntegration { + name = "treefmt"; + class = "treefmt"; + # A treefmt configuration that is a top, as a tool reads it: the + # evaluation, or the evaluations by system where several are in + # force. + top = final.caisson.integrations.topValue; + # What these return is a configuration, a function of + # `{ name, parent }`: a parent that declares it under + # `caisson.treefmt.configurations.` finalizes it, and + # `mkTopConfiguration` finalizes it at a top. + mkConfiguration = + { + # The configuration's module. When absent, the configuration + # registered under the configuration's name + # (`lib.caisson.configs.treefmt.`), if any. Further + # modules of the class are selected with `moduleImports`, + # from the registry. + configModule ? null, + # The treefmt-nix flake or source tree; resolved from the + # composition's declarations under the name `treefmt-nix` + # when absent. + ecosystemSrc ? null, + # The package set the configuration runs on: a function + # that receives the package sets available where it is + # declared, by package config name, each at the system of + # the evaluation, and returns the set to run on. When + # absent, the selection of the nearest configuration above, + # and the set named `default` where none above selects. + defaultPkgs ? null, + # The selection over the treefmt class of the registry. It + # replaces the default of the class, which is every entry + # named `default` followed by what the configurations + # above added. + moduleImports ? null, + # A selection added to that selection, whichever it is. + extraModuleImports ? null, + # Extra module arguments, merged over those the framework + # supplies. + specialArgs ? null, + }@args: + configuration args; + # The same arguments and `ecosystemArgs`, the evaluator's + # arguments merged over the composed call last. + mkConfigurationWithEcosystemArgs = + { + configModule ? null, + ecosystemSrc ? null, + defaultPkgs ? null, + moduleImports ? null, + extraModuleImports ? null, + specialArgs ? null, + ecosystemArgs ? null, + }@args: + configuration args; + }; + in + { + caisson = (prev.caisson or { }) // { + treefmt = integration.namespace; + }; + }; + +} diff --git a/modules/generic/core/default.nix b/modules/generic/core/default.nix index 9e8d3a2f..0d756b9b 100644 --- a/modules/generic/core/default.nix +++ b/modules/generic/core/default.nix @@ -43,6 +43,7 @@ "structural" "system-manager" "terranix" + "treefmt" ]) ] else diff --git a/modules/treefmt/core b/modules/treefmt/core new file mode 120000 index 00000000..3715354a --- /dev/null +++ b/modules/treefmt/core @@ -0,0 +1 @@ +../generic/core \ No newline at end of file diff --git a/tests/argument-errors/check.sh b/tests/argument-errors/check.sh index 1e1aa83a..3f3ffbfe 100755 --- a/tests/argument-errors/check.sh +++ b/tests/argument-errors/check.sh @@ -40,6 +40,7 @@ namespaces=( facter terranix system-manager + treefmt ) failures=0 diff --git a/tests/pinned-world/default.nix b/tests/pinned-world/default.nix index 0a92fa96..26f34d95 100644 --- a/tests/pinned-world/default.nix +++ b/tests/pinned-world/default.nix @@ -71,6 +71,7 @@ let registered."caisson/darwin" registered."caisson/terranix" registered."caisson/system-manager" + registered."caisson/treefmt" registered."caisson/structural" # Last, so its value replaces the pin the overlays carry while # its position stays where the first import placed it. @@ -125,6 +126,7 @@ let "structural" "system-manager" "terranix" + "treefmt" ]; expectedCoreNames = [ @@ -480,6 +482,7 @@ let "caisson/darwin" "caisson/terranix" "caisson/system-manager" + "caisson/treefmt" "caisson/structural" ]; @@ -579,6 +582,7 @@ let "darwin" "terranix" "system-manager" + "treefmt" ]; minimalNixosSystemEvaluates = @@ -1628,6 +1632,37 @@ let ]; }).hash; + # A treefmt configuration declared under the name `default` is + # published as `formatter.`, and its wrapper is the + # derivation treefmt-nix's own `mkWrapper` builds from the same + # module on the same package set. Its outputs carry the + # configuration file and the check over a source tree. + treefmtIsTheFormatterTreefmtNixBuilds = + let + module = { + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; + }; + top = hiveLib.caisson.structural.mkTopConfiguration { + moduleImports = _modules: [ ]; + configModule = + { lib, ... }: + { + caisson.treefmt.configurations.default = lib.caisson.treefmt.mkConfiguration { + ecosystemSrc = inputs.treefmt-nix; + configModule = module; + }; + }; + }; + evaluation = top.caisson.manifest.children.system.x86_64-linux.children.treefmt.default; + upstream = inputs.treefmt-nix.lib.mkWrapper pkgs module; + in + builtins.attrNames top.formatter == [ "x86_64-linux" ] + && top.formatter.x86_64-linux.drvPath == upstream.drvPath + && evaluation.outputs.programs ? nixfmt + && builtins.isString evaluation.outputs.configFile.drvPath + && builtins.isString (evaluation.outputs.check ./.).drvPath; + # A terranix configuration that is a top is its `config.tf.json` # file, built from the package set of the composition with the # evaluated configuration in its `passthru`, and its modules get the diff --git a/tests/unit/lib-overlays.nix b/tests/unit/lib-overlays.nix index 9fb0442e..4087d6e6 100644 --- a/tests/unit/lib-overlays.nix +++ b/tests/unit/lib-overlays.nix @@ -126,6 +126,7 @@ let "facter" "terranix" "system-manager" + "treefmt" ]; in @@ -2969,6 +2970,74 @@ in }; }; + # An output whose entries are keyed by system is published under + # the system of each entry first, and named within it from the + # path without its systems; with `single`, it holds the entry named + # `default` at each system. An entry with no system is refused + # there. + "test: an output keyed by system publishes each entry under its system" = { + expr = + let + entryAt = + system: name: extra: + { + attrset = "packages"; + value = "${name} at ${system}"; + manifest = { }; + bySystem = true; + inherit system; + path = [ + { + type = "system"; + name = system; + } + { + type = "treefmt"; + inherit name; + } + ]; + } + // extra; + publish = myLib.caisson.integrations.publish; + refused = entries: !(builtins.tryEval (builtins.deepSeq (publish entries) true)).success; + in + { + named = publish [ + (entryAt "x86_64-linux" "a" { }) + (entryAt "x86_64-linux" "b" { }) + (entryAt "aarch64-linux" "a" { }) + ]; + single = publish [ + (entryAt "x86_64-linux" "default" { + attrset = "formatter"; + single = true; + }) + (entryAt "aarch64-linux" "default" { + attrset = "formatter"; + single = true; + }) + ]; + withoutSystem = refused [ + (entryAt "x86_64-linux" "a" { }) + (entryAt "x86_64-linux" "b" { system = null; }) + ]; + }; + expected = { + named.packages = { + x86_64-linux = { + a = "a at x86_64-linux"; + b = "b at x86_64-linux"; + }; + aarch64-linux.a = "a at aarch64-linux"; + }; + single.formatter = { + x86_64-linux = "default at x86_64-linux"; + aarch64-linux = "default at aarch64-linux"; + }; + withoutSystem = true; + }; + }; + # A `lib` the caller passes in `specialArgs` takes precedence # over the `lib` the composition sets, the way every other special # argument does. @@ -5321,6 +5390,7 @@ in "system-manager" "caisson-facter" "facter" + "treefmt" ]; setsFromTheComposition = builtins.elem name [ "nixos" @@ -5333,6 +5403,7 @@ in "system-manager" "caisson-facter" "facter" + "treefmt" ]; in signature ? configModule From ffce7681355c8acad7d34d0ecba8340e25d028a7 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Sun, 18 Oct 2026 00:23:32 -0700 Subject: [PATCH 2/2] feat(treefmt): publish the check of the default configuration, and only that configuration A tree with a treefmt configuration named `default` now also publishes `checks..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 --- lib-overlays/integrations/default.nix | 41 +++++++++++++----- lib-overlays/treefmt/default.nix | 36 ++++++++++++---- tests/pinned-world/default.nix | 60 ++++++++++++++++++++++----- 3 files changed, 107 insertions(+), 30 deletions(-) diff --git a/lib-overlays/integrations/default.nix b/lib-overlays/integrations/default.nix index 90e98dc4..88bf9d97 100644 --- a/lib-overlays/integrations/default.nix +++ b/lib-overlays/integrations/default.nix @@ -256,10 +256,15 @@ # optionally `description`, a sentence saying what it did. It may # carry `single`, for an output that holds the one configuration # named `default`, and `bySystem`, for an output keyed by the - # system of each evaluation first (`packages..`). It is - # recorded on the manifest, and applied where the configuration - # is passed up (`entriesOf`). Null for a configuration that is - # not published under a name. + # system of each evaluation first (`packages..`). It + # may carry `only`, a function of the manifest that says whether + # the configuration is published there at all; a configuration it + # leaves out is still passed up. + # `exportsTo` may also be a list of such exports, for an + # integration whose configurations are published in more than + # one output. It is recorded on the manifest, and applied where + # the configuration is passed up (`entriesOf`). Null for a + # configuration that is not published under a name. mkModuleConfiguration = { type, @@ -594,10 +599,25 @@ isManifest = value: builtins.isAttrs value && (value._type or null) == "caisson-manifest"; - # How a configuration is published: the `exportsTo` its - # manifest records, or null for a configuration that is not - # published under a name (structural, flake-parts). - exportsToOf = manifest: manifest.exportsTo or null; + # How a configuration is published: the exports its manifest + # records in `exportsTo`, as a list, empty for a configuration + # that is not published under a name (structural, flake-parts). + # An integration may give one export or a list of them; an export + # with `only` applies to the configurations whose manifest it + # holds true for. + exportsOf = + manifest: + let + recorded = manifest.exportsTo or null; + all = + if recorded == null then + [ ] + else if builtins.isList recorded then + recorded + else + [ recorded ]; + in + builtins.filter (exportsTo: (exportsTo.only or (_: true)) manifest) all; showPath = path: @@ -609,9 +629,8 @@ # its path, on which the name its `exportsTo` gives, where it # gives one, stands in place of that name. entryOf = - prefix: manifest: + prefix: manifest: exportsTo: let - exportsTo = exportsToOf manifest; leaf = last prefix; named = if exportsTo ? name then @@ -701,7 +720,7 @@ in builtins.concatMap ( { prefix, manifest }: - (if exportsToOf manifest == null then [ ] else [ (entryOf prefix manifest) ]) + builtins.map (entryOf prefix manifest) (exportsOf manifest) ++ builtins.map (entry: entry // { path = prefix ++ entry.path; }) ( manifest.outputs.exports.configurations or [ ] ) diff --git a/lib-overlays/treefmt/default.nix b/lib-overlays/treefmt/default.nix index 2a5db890..72158e36 100644 --- a/lib-overlays/treefmt/default.nix +++ b/lib-overlays/treefmt/default.nix @@ -20,7 +20,8 @@ # takes a source tree and builds a derivation that fails when the tree # is not formatted. The configuration declared under the name `default` # is published as `formatter.`, its wrapper, which `nix fmt` -# reads. +# reads, and as `checks..treefmt`, its check over the root of +# the tree (`mkLib`'s `root`), which `nix flake check` builds. { mkLibOverlay, ... @@ -138,14 +139,31 @@ }; }; - # The configuration named `default` is published as - # `formatter.`, which `nix fmt` reads. - exportsTo = { - attrset = "formatter"; - single = true; - bySystem = true; - value = manifest: manifest.outputs.wrapper; - }; + # Only the configuration named `default` is published: as + # `formatter.`, its wrapper, which `nix fmt` reads, and, + # in a tree that knows its root, as `checks..treefmt`, + # its check over that tree, which fails `nix flake check` when + # the tree is not formatted. + isDefault = manifest: (manifest.name or null) == "default"; + exportsTo = [ + { + attrset = "formatter"; + single = true; + bySystem = true; + only = isDefault; + value = manifest: manifest.outputs.wrapper; + } + { + attrset = "checks"; + bySystem = true; + only = manifest: isDefault manifest && (manifest.root or null) != null; + name = _: { + value = "treefmt"; + description = "named `treefmt`, the check of the configuration named `default`"; + }; + value = manifest: manifest.outputs.check manifest.root; + } + ]; configuration = args: diff --git a/tests/pinned-world/default.nix b/tests/pinned-world/default.nix index 26f34d95..d8d46337 100644 --- a/tests/pinned-world/default.nix +++ b/tests/pinned-world/default.nix @@ -1636,32 +1636,72 @@ let # published as `formatter.`, and its wrapper is the # derivation treefmt-nix's own `mkWrapper` builds from the same # module on the same package set. Its outputs carry the - # configuration file and the check over a source tree. + # configuration file and the check over a source tree. In a tree + # that knows its root, its check over the root is published as + # `checks..treefmt`. A tree may declare treefmt + # configurations under other names beside `default`. treefmtIsTheFormatterTreefmtNixBuilds = let module = { projectRootFile = "flake.nix"; programs.nixfmt.enable = true; }; + declares = + { lib, ... }: + { + caisson.treefmt.configurations.default = lib.caisson.treefmt.mkConfiguration { + ecosystemSrc = inputs.treefmt-nix; + configModule = module; + }; + caisson.treefmt.configurations.docs = lib.caisson.treefmt.mkConfiguration { + ecosystemSrc = inputs.treefmt-nix; + configModule = { + projectRootFile = "book.toml"; + programs.nixfmt.enable = true; + }; + }; + }; top = hiveLib.caisson.structural.mkTopConfiguration { moduleImports = _modules: [ ]; - configModule = - { lib, ... }: - { - caisson.treefmt.configurations.default = lib.caisson.treefmt.mkConfiguration { - ecosystemSrc = inputs.treefmt-nix; - configModule = module; - }; + configModule = declares; + }; + root = { + outPath = ./.; + }; + rootedLib = core.mkLib ( + declaresPkgs + // { + sources = { }; + inherit root; + projects.caisson = inputs.caisson; + defaultEcosystemSrc = { + inherit (inputs) nixpkgs; }; + } + ); + rooted = rootedLib.caisson.structural.mkTopConfiguration { + moduleImports = _modules: [ ]; + configModule = declares; }; - evaluation = top.caisson.manifest.children.system.x86_64-linux.children.treefmt.default; + children = top.caisson.manifest.children.system.x86_64-linux.children.treefmt; + evaluation = children.default; + rootedEvaluation = rooted.caisson.manifest.children.system.x86_64-linux.children.treefmt.default; upstream = inputs.treefmt-nix.lib.mkWrapper pkgs module; in builtins.attrNames top.formatter == [ "x86_64-linux" ] && top.formatter.x86_64-linux.drvPath == upstream.drvPath && evaluation.outputs.programs ? nixfmt && builtins.isString evaluation.outputs.configFile.drvPath - && builtins.isString (evaluation.outputs.check ./.).drvPath; + && builtins.isString (evaluation.outputs.check ./.).drvPath + # The check is published in the tree that has a root, as the + # check of `default` over it. + && !(top ? checks) + && builtins.attrNames rooted.checks == [ "x86_64-linux" ] + && builtins.attrNames rooted.checks.x86_64-linux == [ "treefmt" ] + && rooted.checks.x86_64-linux.treefmt.drvPath == (rootedEvaluation.outputs.check root).drvPath + && rooted.formatter.x86_64-linux.drvPath == upstream.drvPath + # The configuration `docs` is evaluated. + && builtins.isString children.docs.outputs.wrapper.drvPath; # A terranix configuration that is a top is its `config.tf.json` # file, built from the package set of the composition with the