Aspect-oriented composition types for Nix module systems.
A pure type library: no resolve, no pipeline, no framework. It provides the structural types for defining aspects — composable configuration units with identity, includes, and class-separated content. Consumers (like den) bring their own evaluation pipeline.
nixpkgs-lib-free. The type system is re-hosted on gen-merge: evalModuleTree, the structural types and mkOption/mkMerge stand in for lib.types and lib.evalModules, with leaf checkers arriving from gen-types through merge. The grammar in lib/types.nix produces the aspect node set without evalModules at all, and nixpkgs is pulled only in ci/, for the harness. Enforced by ci/tests/purity.nix rather than by convention.
Sibling dependencies: gen-identity, gen-merge, gen-prelude and gen-schema.
- Terminology
- Overview
- Gen Ecosystem
- Usage
- Core Concepts
- Schema Integration
- Flat Registry
- API Reference
- Demo
- Testing
- Theoretical Foundations
| Term | Definition |
|---|---|
| Traits | The aspect type — one type, dispatch in merge (Palmer 2024) |
| Classes | Output targets (NixOS, darwin, homeManager module systems) |
| Collections | Named data aggregation (aspect keys matching registered collection names) |
| Edges | includes (forward I) — the one core structural edge, declared inline on each aspect. neededBy (reverse I) — a consumer-declared, predicate-based reverse reference; its semantics live in the consumer's dispatch layer, not in these types. |
| Constraints | Pruning rules: meta.guard, meta.drop, meta.substitute |
gen-aspects gives you the types, not a framework. An aspect is a submodule carrying structural identity (name, key, meta, includes) plus freeform, class-separated content. You register your target module systems as classes (nixos, homeManager, darwin); each class becomes a clean deferredModule option so content stays free of the structural keys.
One flat type (aspectType) dispatches by value shape at merge time (Palmer 2024): attrsets and module functions become aspect submodules, guard records are checked against their cnf (a guard body's undeclared keys are judged as a static body's are, with the same refusal text), a context closure is refused by name (it crosses the gen-rules door, the one closure crossing), a functor-form module function is refused by name (write it as a lambda), and so is a functor whose __functor yields a context closure, a refusal value another library returned and a caller forwarded unread is refused by name, and primitives pass through unchanged, except a scalar or list reached below an undeclared key's nested aspect: nothing gave it a meaning, so it is refused by name as an orphan leaf, naming its full key path and the declared class keys. The library computes stable identity keys, and via graphFacts publishes the aspect graph's facts — the node set, the parent and include relations, and the node values — for a framework to assemble a graph from. flatten renders the same walk as a flat path-keyed registry.
Everything downstream — evaluation, scheduling, conflict resolution, dispatch policy — is the consumer's job. gen-aspects supplies the type surface and the identity keys; the pipeline lives in gen-resolve / gen-dispatch / den.
| Library | Role |
|---|---|
| gen-prelude | Pure nixpkgs-lib-free utility base (builtins re-exports + vendored lib utils) |
| gen-algebra | Pure primitives (record, either, intensional identity) |
| gen-types | Clean-room MIT structural type checker (leaf/poly checkers; verify: v → null|err) |
| gen-merge | Byte-mode module merge engine (evalModuleTree, byte-identical to nixpkgs lib.evalModules over the priority subset) |
| gen-schema | Typed registries (kinds, instances, collections, refs); re-hosted on gen-merge |
| gen-aspects | This lib — Aspect type system (traits, classification, dispatch); re-hosted on gen-merge |
| gen-scope | HOAG scope-graph evaluator (demand-driven, _eval memoization, circular attributes) |
| gen-graph | Accessor-based graph query combinators (traversal, condensation, phaseOrder) |
| gen-select | Selector algebra (pattern matching over graph positions) |
| gen-bind | Module binding (inject external args into NixOS modules) |
| gen-dispatch | Relational rule dispatch STEP (stratified phases, conflict resolution) |
| gen-memo | The incremental plane — decides reuse, never evaluates (change propagation, AFFECTED set) |
| gen-vars | Pure-Nix vars/secrets (den-agnostic) |
| gen-flake | Orphaned as reference rather than deleted, so its record stays readable — dissolution complete. Was the nixpkgs boundary; successors: compose → hub lib.compose/flakeModule (INTERIM, not the settled framework interface), warm/override/trace → gen-memo, projection+realize → gen-delivery, inject/terminals → the crossing's Adapter set via the hub |
The flake exposes a single .lib value output (no __functor); nixpkgs lib and gen-schema are wired in by the flake.
# flake.nix
{
inputs.gen-aspects.url = "github:sini/gen-aspects";
outputs = { gen-aspects, ... }: {
# bind the value directly — lib + gen-schema are wired in by the flake
lib.aspects = gen-aspects.lib;
};
}default.nix takes lib and auto-fetches gen-schema from the pinned flake.lock:
aspects = import gen-aspects { inherit lib; };let
aspects = gen-aspects.lib;
eval = lib.evalModules {
modules = [{
options.aspects = lib.mkOption {
type = aspects.aspectsType {
keySemantics = {
nixos = { category = "class"; };
homeManager = { category = "class"; };
};
};
default = {};
};
config.aspects.networking = {
nixos.networking.hostName = "myhost";
nixos.networking.firewall.enable = true;
};
config.aspects.desktop = {
includes = [ eval.config.aspects.fonts ];
homeManager.programs.alacritty.enable = true;
};
config.aspects.fonts = {
nixos.fonts.packages = [ pkgs.noto-fonts ];
};
}];
};
in
eval.config.aspects.networking.nixos
# => { imports = [{ networking.hostName = "myhost"; ... }]; }
# Clean deferredModule — no structural keys (name, includes, meta, etc.)Aspects are submodules with structural identity (name, key, meta, includes) and freeform content. Every non-structural, non-class key becomes a nested aspect with its own identity.
Key semantics declare, per aspect key, a category ∈ { class, channel, facet } through cnf.keySemantics. aspectSubmodule builds each declared key's option generically from this one surface:
class(e.g.nixos,homeManager,darwin) → an explicitnullOr deferredModuleoption defaulting tonull— clean content buckets with no structural keys injected. A class DECLARED but never given content readsnull, so absence is representable rather than fabricated: a{ }default merges to{ imports = [ { } ]; }, shape-indistinguishable from real content, and a consumer projecting classes by shape would realize the mere declaration.channel→ a raw passthrough (mkOption { type = raw; }); the value rides verbatim, and is not turned into a nested aspect. A channel may supply its ownoptionto override the raw default.facet→ the entry's ownoption(a baremkOption) or a fullmodule(mounted viaimports) — for typed instance fields likeneededBy/settings/id.
An undeclared key falls through the freeform fallback to a nested aspect (it gets identity). This is the module system's own option/freeform separation driven by one declared map, not a custom dispatch mechanism — the bounded category set and its meaning live in gen-aspects; gen-schema records category opaquely. There is no hardcoded classes arm: a class is simply a keySemantics entry with category = "class". The category is validated per key, lazily: a malformed entry throws a named error where that key is read, and never while reading an unrelated aspect.
Context closures like { thimble, ... }: { nixos = ...; } are told apart from module functions via canTake (a module function's required args are all known module args) and refused by name: a closure crosses the gen-rules door, which lowers it to a door node. A context-dependent aspect is written as a guard record, guard (pred.has "thimble") { … }, whose body reads the context through read terms.
Module functions like { config, ... }: { ... } or { aspect, ... }: { ... } are evaluated immediately by the submodule — they have access to _module.args.aspect (self-reference) and standard module args.
Every aspect carries an intrinsic path identity — its .key is a function of where it sits in the aspect tree, computed at merge and never reconstructed downstream. The top aspect container (aspectsRoot) re-roots its children so that below it the prefix gen-merge threads into every module body is container-relative (the module-system mount segment is dropped); aspectSubmodule reads that prefix and stamps it as meta.loc, the declared path; key then computes pathKey(meta.loc) = pathKey(prefix). name (last prefix) and meta.aspect-chain (init prefix) are stamped beside it as its renderings, never identity inputs (identity design §1): a caller may set name, which moves no identity, and a meta.aspect-chain that contradicts the declared path refuses by name at key (Q4). The type is the one writer of meta.loc, key and id_hash: a caller's write that differs from the type's own value refuses by name where it is read (a write equal to it mints nothing and is accepted), and a typed value carried to a second position (an include by value, an alias) is a reference, passed through unmerged.
The path is a structured value; pathKey is its one rendering. pathKey escapes % (as %25) and then / (as %2F) in each segment before joining with /, so aspects."f/x" keys f%2Fx and aspects.f.x keys f/x: two declarations, never one. A segment holding neither renders byte-identically to the raw join. parsePath is the inverse. aspectId mints a declaration over its declared path as a LIST ([ "origin" "path" ]), never its rendering.
The rule (VERBATIM):
A-IDENT (intrinsic path identity). Let an aspect container hold a tree of nested aspects. For every nested aspect
aat container-relative pathp = [k₀ … kₙ](the sequence of freeform keys from the container root down toa, EXCLUDING the module-system mount prefix and EXCLUDING registered class/structural keys), gen-aspects stamps, intrinsically on the value:a.name = kₙanda.meta.aspect-chain = [k₀ … kₙ₋₁]. Its identity key iskey(a) = pathKey(a.meta.aspect-chain ++ [a.name]) = pathKey(p). Collision law: two aspects share a key iff they occupy the same container-relative path. Corollary (no name-only collapse): distinct paths ⇒ distinct keys; in particularkey(hardware.cpu.intel) = "hardware/cpu/intel" ≠ "hardware/gpu/intel" = key(hardware.gpu.intel). Guards share the discipline: a guard placed at an aspect position is a declaration, identified by origin + declared path (identity design §1): itskeyis itsmeta.loc, stamped by placement, and its instances add the sources of what it reads. Its TERM is identified by the mint over its condition and body (guardKey), which is never a declaration's key: the class payload is outside that mint, so two declarations one payload apart would otherwise be one.
The formula's middle term is a rendering, and the stamp is meta.loc: key(a) = pathKey(a.meta.loc) = pathKey(p), and pathKey(a.meta.aspect-chain ++ [a.name]) equals it only while neither rendering is set by a caller. An element written in an includes list is never keyed by its merge position ([definition N-entry M]), which moves with module order: identity is the declaring position, and each element's tree is evaluated at its declared position, so everything keyed below it is too. A NAMED element is keyed at its enclosing element's declared loc ++ includes ++ <name>@<line>:<column>:<file>, the source position of its name attribute (the name's % and @ escaped; at depth 1 the enclosing loc is the owner's, <owner>/includes/<name>@…), so two elements sharing a name at two positions are two declarations, and a reformat that moves the name moves the key (internal addressing). In gen's engine, reordering moves no key whose ancestors are declared by a path or a keyed module; below an unnamed ancestor declared in an inline unkeyed module, the key moves with that ancestor. Mounted through unmodified nixpkgs lib.evalModules, an unnamed element has no ID guarantee across a module reorder: nixpkgs hands each definition over as { file; value; } and drops the module's key, so the element is addressed by its definition's position in that hand-over order, keyed and path modules included, and its key, id_hash, meta.loc and default name move when the modules are reordered; within one evaluation they stay distinct. There the stable route is a named element, keyed alike by both engines: its key survives a module reorder for as long as its name's source position does not change, and an arbitrary source edit that moves the name moves it (ci/tests/foreign-include-order.nix). The key carries a source path, so assert relations between keys, never a literal. An UNNAMED element (an aspect literal, a module function, or a bare { imports = [ … ]; } module) is keyed by its declaration address (see Published facts), and its default name and description (Aspect <name>) render that address, one JSON segment that isMeaningfulName reads as no name; an element handed no address has no declaring position and refuses by name. id is reserved on an include element, as an authored id would key nothing: it refuses by name at every include member (a named or unnamed literal, under mkIf, mkMerge or mkForce, and a bare module), and data the type never stamped (a guard's fired body, a handed or context-routed instance body, a raw tree) refuses where it is read, at includesDoor. The word is reserved whole, so a nested aspect named id in an include element refuses too; a literal module's config.id, a reference, a keyRef and a guard element's body are not include-element writes and are served.
Key form — container-RELATIVE. The stamped prefix is the merge loc re-rooted at the aspect container: the top container aspectsRoot merges each first-level aspect at prefix = [key] (dropping the module-system mount segment the container is mounted under — aspects in these tests, den/aspects in den), and descendants accumulate relative from there. So key(apps.media.spicetify) = "apps/media/spicetify", no mount. This form was chosen (over mount-absolute) because:
- It is origin-invariant. An aspect's key is a function of its position within its aspect tree, independent of where the consumer mounts that tree. This is the property the future aspect-registry / cross-flake origin work needs (an imported aspect keys by its definition origin, not the consumer's mount point — spec §3a north-star): the container root IS the proto-namespace root, and an origin qualifier prepends additively (
pathKey(origin ++ path)). - It matches den-hoag's identity form. den-hoag's
__providerreconstruction is already root-relative (apps/media/spicetify), so consuming the native relative.keyis byte-for-byte the same key — the lowest-churn path to retiring the shadow layer. - It keeps plain and guard unified. The re-root is a uniform reset applied to every value the container merges (not a depth-based strip), so a guard record placed at a path (its
meta.loc, also re-rooted) lands in the SAME relative namespace as plain aspects.
One identity, two views — modulo the origin qualifier, and for plain aspects only. For a plain aspect under an empty origin, flatten's walk key and .key are literally equal: both are container-relative (flatten walks from the container root; .key is re-rooted there), so key(a) == flattenKey(a) (e.g. both "apps/media/spicetify"). Two scopes on that, both load-bearing:
- The origin qualifier moves one side and not the other. A published node id is
pathKey(origin ++ path), while.keytakes no origin at all — its arms are a placed declaration'spathKey(meta.loc)(static or guard), an unplaced guard'sguardKeyand a record with no declared path'spathKey(aspectPath), none of which sees one. The two agree only after the qualifier is stripped, and coincide exactly whencnf.providerPrefixis[ ]. - Guard records and wrapped fns are outside the claim. They are bare records rather than submodule instances, so they carry no
keyoption at all — a placed guard'sidentity.keyrenders its declared path (meta.loc), but only an unplaced one's falls back toguardKey, which content-addresses the term ("guard:<hash>"). Their positions are answered by the publishedparentOf(see Flat Registry), never by.key.
Unit-tested in flat-registry test-node-id-agrees-with-key-modulo-origin, which enumerates over the published nodes, names those two exclusions rather than filtering them away, and asserts the fixture actually carried one of each.
gen-aspects depends on gen-schema and provides mkAspectSchema to bridge aspect types with gen-schema's kind-level infrastructure (collections, introspection, schema extensions).
aspects = gen-aspects.lib;
schema = aspects.mkAspectSchema cnf;mkAspectSchema cnf returns:
| Field | Description |
|---|---|
schemaOption |
gen-schema option wrapping aspectType as the custom entry type |
mkAspectOption { providerPrefix? } |
Declares options.aspects with lazyAttrsOf aspectType |
mkAspectModule { providerPrefix? } |
NixOS module declaring both options.aspects and options.schema, lazily threading schema-declared options into every aspect instance |
mkNamespaceType config |
Submodule type for namespace composition — includes schema, classes, and freeform aspect content. config (positional) is the enclosing evaluation's config: a namespace's aspects read its schema.aspect extensions |
aspectType |
Re-exported aspect type |
identity |
Bundled identity functions (aspectPath, pathKey, key, isMeaningfulName) |
canTake |
Re-exported function arg introspection |
mkIsModuleFn |
Re-exported module function predicate |
The three constructors take a closed options set: a field outside the ones shown is refused by name, catchably, naming the constructor (gen-aspects.mkAspectSchema.<name>) and the accepted set.
Redeclaration. The per-cnf types are built per construction, so a container declared twice (two mkAspectModule calls, or mkAspectModule beside mkAspectOption) meets two records of one name. They state their merge relation through gen-schema's constructionRelation, read off lib/cnf.nix cnfConstruction, by each key's regime in cnfVocabulary: one construction (one cnf, reached through one slot) merges, and two are refused by name. The module lists aspectModules and metaModules are not identity: as a nixpkgs submodule's modules do, two declarations' lists concatenate and the merged type is built over both, so each side's options reach the aspect. ref, the framework's door, is read by no type and distinguishes nothing. Stated limits: module content is outside the relation's records — a module in collections, or a facet entry's module, declaring an option typed by a per-call mkOptionType aborts when two constructions are compared in the order that interns functor first, and in every order when that type has a description back-edge; a function in a compared key reached by a selection written at each site is two slots, refused on Nix and Determinate and merged on Lix; and a module list is concatenated, so an anonymous module in both declarations is never deduplicated and is imported twice (a list option it defines holds its definition twice), while a keyed or path module is imported once, as in nixpkgs.
Schema-declared options propagate to aspect instances via mkAspectModule. When a schema kind entry declares options (e.g., priority, tier), those options become available on every aspect:
{ config, ... }:
{
imports = [ (schema.mkAspectModule { }) ];
# Collections and extensions declared on the schema kind
schema.aspect = {
settings = { }; # collection
tags = { }; # collection
# options.priority = lib.mkOption { ... }; # schema extension
};
# Every aspect now has access to schema-declared options
aspects.networking.priority = 10;
}mkAspectModule lazily injects config.schema.aspect.__defsModule into each aspect's aspectModules, so schema extensions are available without manual wiring. This __defsModule seam is why aspectSubmodule mounts imports = facetModules ++ cnf.aspectModules — aspectModules must stay live even though per-key channels are now declared through keySemantics rather than injected as modules.
A construction formal written at the kind entry's top level is refused by name, because there it
would land on every aspect as a nested aspect while the schema's own formal stayed what the
constructor fixed: schema.aspect.keySemantics = … (meant to widen the class vocabulary) or
schema.aspect.providerPrefix = …. The names are the mkAspectSchema cnf keys (aspects.cnfKeys)
and gen-schema's own formals, and a cnf collection named for a cnf key is refused the same way. Pass
a formal to mkAspectSchema; an aspect field of the same name is written on the aspect, or as
schema.aspect.config.<name> (under closedKeys it must be declared or listed in freeformKeys; freeformKeys also lists node ids, a second grammar read by graphFacts' dead-nested warning only: a /-bearing entry names a node and opens no gate for any ordinary attribute name; only a body key spelled with that exact /-bearing string would be admitted, and its own node id is the escaped form, so it is still said). The id carries the providerPrefix of the cnf the facts are read with.
The refusal covers every route into the entry: a formal at the top level of a module the entry
imports (nested imports, require, a function or path module, a whole-module mkIf) is refused by
gen-merge's collector with the same text, saying it was written in a module the kind entry imports and
naming the module. The reservation rides on the record of a functor module wrapping each def that
imports anything, so config.schema.aspect mounted in a nixpkgs lib.evalModules carries no marker,
and a def writing its own __reservedKeys beside an imported formal is still refused (the record is
read first). Over a gen-merge whose moduleSyntax.functorRecord does not list __reservedKeys the
kind refuses by name; that guard sees only the gen-merge gen-aspects is built with, so a kind value
evaluated by another, older gen-merge in the same evaluation never reads the record, and an imported
formal lands there silently.
The flatten function walks the recursive aspect tree and produces a flat attrset keyed by path identity:
aspects = gen-aspects.lib;
flat = aspects.flatten eval.config.aspects;
# => { "networking" = ...; "networking/firewall" = ...; }Entries are the aspect values unchanged — flatten does not inject any fields. Guard records (__guard) are included as entries but never recursed into.
The path key is a RENDERING of a parent edge, not the edge. Do not split it. "networking/firewall" looks like it says its parent is "networking", and for a plain aspect it happens to agree — but a nested guard leaf is in the registry carrying no meta.aspect-chain at all, so the two derivations a consumer might reach for disagree on it, and the meta.aspect-chain or [ ] one answers root for a node whose parent is its container. Worse, that wrong answer is indistinguishable from a right one: a genuine root aspect yields [ ] through the same accessor, so absence and root are the same value. Read graphFacts instead.
Detection is structural rather than relying on a hardcoded key list:
- Nested aspects are attrsets with a
namefield (fromaspectSubmodule) - Class content (
deferredModule) lacksnameand is skipped - Primitives (strings, lists) are skipped
graphFacts publishes what a graph is built FROM — the node set, the edge relations and the node values — as plain data. gen-aspects imports no query library for this: the query libraries are needed to query a graph, never to state one, and every fact here is an attrset, a list or a string.
facts = aspects.graphFacts cnf eval.config.aspects;
# => { nodes = [ "networking" "networking/firewall" … ];
# parentOf = { "networking" = null; "networking/firewall" = "networking"; … };
# includeSitesOf = { "networking" = [ ]; … };
# includesOf = { "networking" = [ ]; … };
# foreignIncludesOf = { "networking" = [ ]; … };
# unresolvedIncludesOf = { "networking" = [ ]; … };
# nodeIdOf = { "networking" = "networking"; … };
# nodeData = { "networking" = <the aspect value, unchanged>; … }; }- A node id is
pathKey(cnf.providerPrefix ++ walkPath)— the walk position the registry already keys on, qualified by origin. It is deliberately notidentity.key: that function content-addresses a guard record, which would move every guard node's name off its position. parentOfis the node's own WALK POSITION, and the id and the parent come from one source. A framework holding only the registry and the values would have to join onmeta, and that join is wrong rather than merely redundant — a nested guard leaf carries nometa.aspect-chainat all, someta.aspect-chain or [ ]answers root for it, indistinguishably from a genuine root. That is why the relation is published here. It is not why it should be computed frommetahere: this library holds the walk, and reading a position out ofmetainstead is wrong on values this library accepts — a guard built by the publicguardin a tree no aspect type stamped carries nometa.loc, and a guard carried by value from another tree carries themeta.locof where it was placed there.parentOfis total, andnullmeans root and only root. Every node has an answer. Totality holds by construction rather than by a check: the walk descends only into values it also emits, so a non-root node's parent is necessarily already a node — there is no dangling case for a refusal to guard.includesOfcarries the edges this library CHECKED, and every target it emits is innodes— universally, with no exception and at every provider-prefix length. It resolves the include elements that reference a local node, and it lists every anonymous declaration written at an include position as an edge to that declaration's own node (below).foreignIncludesOfcarries the references it could NOT check. A foreignkeyRefnames a node in a fixpoint gen-aspects does not hold, so it is not an edge of this graph; it is published as a reference in the declaration's own{ origin; path; key; }shape, and the framework — which unions providers — is what resolves it. That is whatkeyRefis for. Which keyRefs are foreign is decided by the origin, and the string sugar takes its origin from the FIRST SEGMENT —keyRef "prov/a/b"has origin[ "prov" ], always exactly one element, by construction. So the sugar can name a local node only whencnf.providerPrefixis itself one segment long: under the default[ ]— gen-link'sself, the state of a corpus whose origin is assigned at federation — every string-sugar keyRef is foreign and contributes no edge toincludesOf. Use the structured form (keyRef { origin = [ ]; path = [ … ]; }) for a reference you want checked locally. The shape is structured rather than a rendered"origin/path"string on purpose: a rendering has to be re-split downstream to recover the qualifier, and that re-split is a second source for a fact the declaration already stated. The two relations are exclusive, which is the point — left together, an unchecked reference is spelled exactly like a checked edge, and a consumer unioning edge targets into a node set widens the graph past its own membership predicate on a value nothing refused.- Inline content is an anonymous declaration, and an anonymous declaration is a node. An aspect literal or a module written at an include position (and, recursively, inline content inside it) enters
nodes,nodeData,parentOf(its declaring node, or the enclosing anonymous node) andincludeSitesOflike every node. Its id is its owner,includes, and its declaration address rendered as one segment: the declaring module (k<key>for a keyed or path module,a:<i>for an anonymous one, by its position in its importer), the option path and the structural path the definition took, as JSON with%and@escaped (app/includes/["kmA","aspects","app","includes",0]). The address is where the element was declared, never where it was merged: in gen's engine it does not move when keyed or path modules are reordered or a sibling'smkIfis discharged, and an anonymous module's elements move with that module's own position. Mounted through nixpkgs'lib.evalModules, the declaring module is the definition's position in nixpkgs' hand-over order (a:<i>, keyed and path modules included), so there the id moves on any module reorder (see Aspect identity on the stable route). It is an injective rendering, never a hash. One literal included at two places is two nodes, and a typed content value copied to a second position (edited or not, from this tree or another) is re-declared there with that site's id, its content unchanged.nodesis inattrNamesorder, soattrNamesof any relation equals it. Named inline content is one node per class of its sightings (identity design §2). A raw value with a positionednameis keyed by its §2 key, the position of itsnameand the name (<name>@<line>:<column>:<file>). The sightings at one §2 key are one node when the rung says so over their authored values (meta.sighting.value): two exact constructor outputs of gen-algebra'smkIntensionalby itsconservativeEq, any other pair by Nix==. The classes are the connected components, so they do not depend on order: one value at two takers is one node, and a factory called with two different contents is two. A class's id is@/includes/<§2 key>, qualified by origin, and when one §2 key holds several classes, that plus/and the class's least inclusion site as one segment. ItsparentOfisnull, the content inside it is keyed under it (<class id>/includes/<i>), and a named value reached again on its own path is a back edge to its class. The==comparison forces the authored content; one that throws (a lazythrowno reader demands, an unfree package'soutPath) is not the same, so the sightings stay two classes, and named content whose comparison does not terminate (a cycle or an infinite unfolding) aborts the evaluation (identity design §4 row 4). Named content and string context: a stated boundary.==does not see string context, and a class keeps its least sighting's value without walking the others, so when two sightings differ only in context, the class drops the other sightings' store dependencies silently: a host reaching the context-carrying sighting receives the value without it. This is a declared exception to the rule that a result is "a value or a named refusal", beside gen-view's stated boundaries. Carrying the loss would need a walk that collects every sighting's context.==forces the content but collects no context, and it shortcuts on a pointer-shared value, so it is not that walk: an edge walk overflows uncatchably on a self-referential value shared by two takers (which is a class today, and a value), and a walk bounded so that it refuses past its bound would refuse deep valid input, and gen admits no bound invented to limit cost. It retires when store dependencies become graph edges, unless that lands by walking values. Pinned by…-static-collapse-drops-the-twins-context-the-stated-boundaryand…-shared-self-referential-class-is-a-value. Named content in an applied body (an instance's fired entry,includeSitesOfInstance) is keyed by its §2 key and its own sighting. A sighting gen-identity's mint takes that the rung identifies with a static member at its key the mint also takes joins that member's class and names its id, so no static id moves, whatever the class's other members are. A class can mix the two only on the float domain the mint excludes, because above2^53Nix's==is not an equivalence relation, so the mint takes a float only when its magnitude is strictly below2^53: an int beyond2^53is==to a float the mint refuses ({ v = 9007199254740993; } == { v = 9007199254740992.0; }), so the static pair is one class and an applied sighting of the int joins it. Content the mint refuses never joins a static class. Otherwise, content the mint takes is keyed by its content,@/includes/<§2 key>/<digest>(hashIdentity "aspect-content"), so its id is the same whichever instance or host reads it, and a value every instance fires from one declaration is digested once, at the declaration. Content the mint refuses (a value holding a function, a path or a derivation, or past the mint's bounds) is keyed per instance: its class is the rung's component among that instance's own refused sightings at the key, and its id is that component's least instance-relative site (<iid>/includes/<i>…). So one refused value fired by two instances is two nodes, whatever is declared statically, and a sighting the mint takes never shares a class with one it refuses. A reader forces only the comparisons its own answer is made of, and reads anameonly at its ownname's position. An applied named content site carriesinfo, its sighting's record:id, the §2 keyk2, andjoined(whether it joins a static class, decided by the rung without a digest).infois lazy, so a reader that needs no id, one that holds no second sighting at the key, never forces the digest. A value whose digest aborts (anabort, a missing attribute) aborts the readers of its id and any reader deduplicating it beside a second sighting at its key, and no other reader. The string-context boundary above holds for these classes too. Two kinds of inline content are not nodes and stay positions: content nested 256 levels deep or more (a literal that includes itself is 256 nodes, and only a reader descending past them is refused), and a parametric declaration's members, whose unnamed content is keyed per instance (includeSitesOfInstance). unresolvedIncludesOfnames the declared positions that reference no node. Anincludeslist holds two kinds of thing: a reference (akeyRef, a by-value aspect whose key is a node, or a bare string — never a bare string as content; see below), and inline content written at the include position (a wrapped fn, a guard record, a deferred closure or policy record, an aspect literal). An anonymous declaration is an edge inincludesOf; every other inline position — content past the depth budget, a guard record, a function, a deferred member — is published here rather than dropped: index back intonodeData.<id>.includesfor the element itself. A keyed value is inline content only when it was written at an include position — its.keyand itsmeta.aspect-chainboth carryincludespast their first segment. A bare string is always a reference (a use-site name is a reference, never a declaration), resolved locally against this tree's own registry exactly like a by-value element's.key; it is never published here as unresolved content, and one naming no node is refused by name, catchably. A term (readCtx,lit,list,attrs, …) is not inline content: at a static include position (a node's ownincludes, an applied body's, a multi-definition carrier's unconditional fragment) it is refused by name, catchably, asunsafe-readforReadCtxandDefaultand asstatic-termfor every other former, naming the aspect and the include position; a term belongs in aguardbody or a parametric declaration.includeSitesOfis every include position of a node, in declared order, classified — and the three relations above are its projections. Each site is{ kind = "local"; target; },{ kind = "foreign"; ref; },{ kind = "content"; target; sites; }(targetnames the content's node, absent where the content is no node; a named content site in an applied body also carries the lazyinfo, its sighting's record, above),{ kind = "sealed"; }or{ kind = "deferred"; }. Content is a keyed aspect literal written at the include position (including the elementaspectTypecoerces a function definition into when it is one of several definitions of an aspect), or a key-less attrset that is not a guard leaf — the literal in a guard's fired body, which the aspect type never merged — and itssitesare that element's own includes, classified by the same rule. A key-less literal writingidrefuses by name where it is read, at its site and at its node's data (A-IDENT). Sealed is every other inline element: a guard record, whose content exists only once a context is supplied, and a function (a module function in an applied body is sealed, a defaulted, reversible choice pending an owner reading). The rule is one for a node's value and an applied body (includeSitesOfInstance).includesOfis the top-levellocaland targetedcontenttargets,foreignIncludesOftheforeignrefs,unresolvedIncludesOfthe target-lesscontent,sealedanddeferredpositions: one classification pass feeds all four, so they cannot disagree. A position is a list index (at depth, a path of them); nothing is minted for inline content. A parametric declaration publishes its members without firing (van Antwerpen 2018's instantiation scopes: a declaration's members stay reachable from its instances): its checked body term'sincludeselements, each context-free one resolved once at the declaration (one that refuses there is refused by name, naming the aspect and the include position, wherever the declaration's sites are read, even if nothing instantiates it), and each context-dependent one deferred — its target exists only per instance, so it is classified there. A wholeincludesthat reads the context, a door body, and a carrier whose record fragments carry sites publish onedeferred. Acontentsite'ssitesis lazy, so a bad reference inside inline content refuses only for a reader that descends into it, and content nested past 256 levels (almost always a literal that includes itself) refuses by name there rather than growing without end.nodeIdOfmaps the local key a member is named by to its node id. A consumer naming an aspect by its key reads the id here rather than re-renderingproviderPrefix ++ [ key ], which would be a second source for it.isGuardLeaf v(top level, besidegraphFacts) answers whether a node value is a guard leaf — a__guardrecord, the node shape whose content exists only in a context. It is the predicate the walk itself stops at, so a consumer readingnodeDataasks it here rather than re-deriving the shape test.- References resolve by identity, never by the key field alone. A by-value element that is not inline content, and a bare string, resolve through
gen-prelude'sresolveagainst this tree's nodes: a bare string must name a node by its local key, and a by-value element is the node whose stamp (id_hash) andkeyit carries — the key only locates the candidate, and the verdict compares the canonical entry, minting nothing. So a member resolves whether written by name or by value (including one whosenamemoved its key off its walk id), and each of these is refused by name, catchably, atgen-aspects.includes (aspect '<id>', include position <i>): a key naming no node (a value from another tree, a key set by hand), a member edited off its canonical entry (base // { key = "app"; }keeps base's stamp and so is notapp), a value carrying no stamp, and a bare string naming nothing. AkeyRefcarrying this tree's own origin is checked the same way against the walk and refused when it names no node; a genuinely foreign origin names a node in a fixpoint this library does not hold and is not checkable here. A refusal surfaces in every include relation of that node (includesOf,foreignIncludesOf,unresolvedIncludesOf) and in no other node's. The scope is keyed values: a key-less node value (a guard leaf, a wrapped fn) from another tree is still read as content. - ★ The one admission that is not a refusal: another tree's value with the same origin and the same key IS the local node.
id_hashis minted over origin and key, so such a value carries the local node's stamp and key, and by the identity law it is that node: it resolves to the local id, andnodeDataserves the LOCAL value — the foreign value's content is dropped, and nothing says so. No loud arm exists without either widening aspect identity to content (module functions refuse identity, so most aspects would have none) or giving each tree a distinct origin (every aspect id moves, and every tree at the default origin[ ]breaks). To keep two trees' aspects apart, give them distinctproviderPrefixes — their stamps then differ, and the foreign value is refused by name — or reference the other tree's node withkeyRef. Pinned bytest-references-resolve-by-identity'sotherTreeSameKeyrows.
childrenOf cnf aspects path is a node's children as include elements, and childBundle cnf aspects path is the named include value over them, so "include every nested child of X" is one include element with one identity:
p.includes = [ (aspects.childBundle cnf config.aspects [ "loom" ]) ];
# childrenOf cnf config.aspects [ "loom" ]
# => [ { origin = [ ]; path = [ "loom" "gate" ]; … } { …"loom" "warp"… } { …"loom" "weft"… } ]- A child is exactly a walk node whose
parentOfis the parent: a nested aspect or a guard leaf directly below it, inattrNamesorder. Class content, structural options and primitives are not children. The predicate is the walk's own (lib/walk.nix), read one level down. - Each child is a structured
keyRefunder the tree's origin, so an include site with the same origin checks it (a dangling one refuses by name there), and one with another origin publishes it inforeignIncludesOf. - The origin and the coordinate are the tree's, checked, never the caller's claim. The parent's stamp is re-derived under
cnf.providerPrefixand compared with the one it carries, and its declared path is compared withpath. A tree stamped under another origin, a stampless one, or a node handed in at a path it was not declared at refuses by name. An absent parent, a guard leaf, class content, the container[ ]and a path that is not a list of strings refuse by name too, so no refusal reads as a childless node. childBundleis ONE node wherever it is included from one gen-aspects source in one evaluation. It is a raw named value: itsnameistoJSON { origin; path; }(injective over the pair) and its value carries the children's references, so two parents are two nodes, and two trees with one origin and parent path but different children are two classes. The bundle node is a root, as every named include node is.- Only the node's attribute names, each value's shape and the parent's stamp are read. No child content and no
includesare forced, so a bundle may be written inside the tree it enumerates. - Bind
childBundle cnfonce percnf. The door is taken per call, so an unbound call pays it each time.
A framework builds the graph from these with gen-graph.fromRegistry, or lifts them into a gen-scope evaluated scope read by resolve, and expresses its named views over gen-select's algebra; the registry above is one such view.
The .lib value exposes the five aspect types (incl. aspectsRoot, the re-rooting container), the value-shape introspection (canTake), the retired wrapFn and wrapGatedFn and the renamed includeSitesOfEntry (each refused by name; includeSitesOfEntry's refusal names its successor includeSitesOfInstance), the instance mint and relation (instanceOf, instancesFor), the identity/introspection utilities plus guardKey and keyRef, the schema-and-registry entry points (mkAspectSchema, flatten, graphFacts, includeSitesOfInstance, isGuardLeaf, keyCategory, structuralKeys, cnfKeys), and the guard vocabulary (mkGuardVocab, applyGuard, pred, guard). The roster itself is the binding, not a count restated in prose — read lib/default.nix.
aspects = gen-aspects.lib;-
aspectsType cnf— top-level container. Submodule withfreeformType = lazyAttrsOf (aspectType cnf)and fixpoint (_module.args.aspects = config). -
aspectSubmodule cnf— aspect entry. Submodule with structural options (name,description,key,id_hash,meta,includes; acnf.keySemanticskey naming one, or naming a key the module engine owns in every aspect's option tree (_module,_freeformOptions), is refused by name at thecnfdoor), one option per declaredcnf.keySemanticskey built generically from its category (class →nullOr deferredModuledefaulting tonull, channel →raw, facet → the entry'soption/module), and freeform for undeclared (nested) aspects. -
aspectType cnf— Palmer flat dispatch. One type, dispatch in merge. Attrsets and module functions →aspectSubmodule. Guard records → checked against thecnf. A guard body's undeclared keys get the static body's judgement (the closed-key gate, the orphan leaf): a plain-data body where the record is checked, and a body whose keys exist only once fired (a context read, a door's output) at its firing, by key name only, so no fired field is forced. Known residues, served unjudged: a fired value's orphan leaf, a fired key below a listedfreeformKeyskey or underrecursiveClosed, and, in open mode, a guard body's empty nested aspect, whichgraphFacts' dead-nested warning does not reach. A context closure → refused by name, naming the gen-rules door. A functor-form module function (an attrset with__functorwhose__functionArgsare satisfiable bycnf.moduleArgs) → refused by name, telling the author to write a lambda; a functor with malformed formals is not one (canTakeis total on it). A functor context closure (an attrset whose__functoryields a closure that is not a module function) → refused by name, as a lambda closure is: the submodule would read it as config, and gen-rules' lowering does not lower a functor at an aspect position. Both functor refusals also meet a functor at a nested key of a plain definition beside a guard record, which is coerced into that key'sincludesas a lambda is. A refusal value at any aspect position → refused by name, naming its encoding, its code and the gen-rules door. The encodings are recognised by exact shape: gen-program's record{ refused = true; code; … }, the Either left{ left = { code; witness; }; }(gen-algebra, gen-rules), the failure-list left{ left = [ failure … ]; }(gen-types and gen-schemarunValidators, gen-algebracollectErrors), and gen-bind's crossing refusal. An encoding whose keys the aspect type declares is the author's aspect and is not recognised. Primitives → passthrough. -
aspectOrFn cnf—either aspectType aspectSubmodule. Recursion-safe binding forincludesand nested aspect positions. -
wrapFn,wrapGatedFn— RETIRED. Each refuses by name at its first application: a context closure crosses the gen-rules door, which lowers it to a door node, so declare the aspect through the framework's surface or write it as a guard term (guard (pred.has <coordinate>) <body>). The same refusal meets a context closure anywhere a gen-aspects type reads one (an aspect, anincludeselement, a definition beside others), andapplyGuardhanded a closure. A closure inside the result of a module function written at an aspect position is refused the same way; the message says the lowering does not enter that result.The declared set and the entity kinds. A framework declares its coordinates as
cnf.entityKinds:null, the default, is the open world; a list declares its names, all of them entity kinds ([ ]is a closed world with no coordinates); an attrset{ <name> = <bool>; }declares its names and marks an entity kindtrue. Any other value is refused by name. A context key is the name of the entity kind whose value it carries (entity kinds are the framework's to declare). A guard's condition is a term, not an aspect: it reads the context unnarrowed, and a read of a coordinate outside the declared set (with this library's ownclassandtags) is refused when the guard is checked. -
instanceOf cnf { scope ? { }; } { aspect; context; sources; } value— the instance mint. A parametric aspect (a first-order guard, or a guard carrier) applied to a context is a node of its own, the instance:{ id; entry; formals; scope; }. A first-order guard receives its DERIVED READS, the coordinates its condition and body terms read, so it is keyed on what it reads and not on the whole context.formalsmaps each key the aspect receives atcontextto its entry insources, the identity of the entity or argument binding that supplied it, andidishashIdentity "aspect-instance"over{ aspect; formals; }. So two contexts handing the aspect different values are two instances, two that differ only in keys it never reads are one, and a guard that reads nothing is one instance everywhere.entryis the guard fired atcontext, andscopeits instantiation scope: the closures of the door nodes its firing left inentryunfired. Such a node fired later throughinstanceOfhanded thatscopereads its closure there; handed none, the door re-applies the outer to recover it, the same value at one outer application per firing.scopenever enters the id, and it is the caller's to hand the right one: it is checked only by key. A key with no source and a source that is a value rather than an identity are each refused by name. No source is refused by its kind tag, since a framework names its own kinds: holding no graph, the mint admits any identity, an aspect's or an instance's included (instancesForrefuses its own nodes'). -
instancesFor cnf aspects { suppliers; containment; } scopes: the instance relation,{ vertices; instantiates; reaches; nestedAt; declined; }. Each node's scope is{ members; sources; }, and each tuple's context is derived from its sources throughsuppliers.<source>.<key> = <value>, so one scope never reads another's content.containment.<identifier> = { parent; key; identity; marked; bindings; }is the entity graph's one-step containment, handed as data and required ({ }when there is none): gen derives each entity's coordinate (its key and argument bindings and every ancestor's; an argument binding re-declared below shadows the ancestor's, as a new binding id, and an entity key is bound once along a chain) and its descendants (never through a marked entity). A node's members are walked through static aspects to the parametric ones they reach, and each is minted at the node's own tuple, or, where that tuple does not satisfy its condition, once per descendant whose coordinate does and whose crossed levels below the node's entities the aspect takes (a{spool}aspect at a thimble fans over its spools; a{dot}aspect at the thimble does not reach through the spool level, a{spool, dot}one fans over the pairs):reaches.<node>.<aspect>lists those instance ids, each once at its first occurrence, siblings in the descendants' identifier order; never in id order, since an instance id is internal addressing that nothing durable may depend on, and it moves when its aspect is renamed. The order is canonical by construction (ruling 13). Every instance is one vertex,vertices.<id> = { formals; entry; scope; }, however many nodes reach it, andinstantiates.<id> = [ <aspect> ]is its edge to its declaration (van Antwerpen 2018'sIedge): followinginstantiatesthenincludesfrom an instance answers the declaration's resolved members, and the substitution is the vertex'sformals, applied to each field ofentrywhere that field is read, so one member that refuses refuses at its own read, named by aspect and field, and nothing else does. The parametric aspects among its members are minted, per node reaching it, at the meet of its tuple and that node's, fanning out the same way, asnestedAt.<node>.<id>.<aspect>; the vertex itself is shared, one id and one application. A static aspect inside a body resolves at the reaching node's scope. A pair no tuple supplies has no edge.declined = { reaches.<node>; nestedAt.<node>.<id>; }publishes the decision beside the edges: an entry per handed scope and per (node, vertex) listing, ascending, the walked first-order guards with no edge whose condition was decided FALSE at every tuple tried (aneqthat does not match, or, under a declared coordinate set, an absent coordinate). A guard whose condition the evaluator refused (hasover a coordinate the scope lacks under the open world) and a guard never walked there are in neither, so a consumer that finds a reach in neither refuses it; a declined reach is no edge, anddeclinedonly tells a consumer that, never what to fold, count or order. Malformed scopes and containment records refuse by name, and so does a node binding an argument against the coordinate of an entity it binds (the override belongs on the containment record, where it shadows). A source that is a node of the relation's own graph, an aspect node's id or one of its vertices, supplies no argument and is refused by name; the test is membership, never the kind tag, so a framework entity kind spelledaspectis admitted, and so is an instance id minted by an earlier relation.
cnf is a closed vocabulary, not an open attrset. Every entry point that takes one constructs it
through a single checkedCnf, so a key outside the recognised set is refused by name — the
refusal lists the offending keys and renders the recognised set; a key the library no longer reads
is refused like any other unknown key (a class is a keySemantics entry,
keySemantics.<class>.category = "class", never a classes key). The refusal is a throw, catchable with tryEval, and reachable by forcing
the entry point's own result. The recognised set is aspects.cnfKeys; read it from there rather than
restating it. The default behind each key stays internal — the question a consumer asks of this
surface is whether a key is recognised, not what it falls back to.
This closes a silent failure mode rather than adding a strictness. Under the previous cnf.<key> or <default> reads nothing ever inspected the key SET, so an unrecognised key was not reinterpreted —
it was inert, and whatever it meant to declare stayed undeclared and fell through the aspect
submodule's freeform fallback into a nested aspect tree. mkAspectSchema { classes = …; } computed
exactly mkAspectSchema { }.
aspectsType {
# Per-key semantics — one surface for class/channel/facet dispatch.
# class → nullOr deferredModule, default null (clean content buckets; unset reads null)
# channel → raw passthrough (value rides verbatim; may carry its own `option`)
# facet → the entry's `option` (bare mkOption) or `module` (mounted via imports)
keySemantics = {
nixos = { category = "class"; };
firewall = { category = "channel"; };
neededBy = { category = "facet"; option = lib.mkOption { type = lib.types.listOf lib.types.str; default = []; }; };
};
# Known module args for module/guard function detection
# Default: { lib, config, options, pkgs, modulesPath, aspect }
moduleArgs = { lib = true; config = true; /* ... */ };
# Additional NixOS modules imported into every aspect entry.
# Use for pipeline-specific options (excludes, policies, etc.).
# ALSO the `__defsModule` seam: mkAspectModule injects
# config.schema.aspect.__defsModule here, so schema-declared instance
# options propagate — keep aspectModules mounted (see Schema extensions).
aspectModules = [
({ config, ... }: {
options.excludes = lib.mkOption { default = []; type = lib.types.listOf lib.types.str; };
})
];
# List of NixOS modules imported into each aspect's `meta` submodule.
# Allows consumers to declare typed meta options (e.g., `meta.guard`,
# `meta.priority`) alongside the freeform attrs.
metaModules = [ ];
}canTake— function arg introspection.canTake.upTo params fnchecks if all required args offnare satisfiable byparams.mkIsModuleFn cnf—canTake.upTo cnf.moduleArgs. Returns a predicate that classifies functions as module fns or guard fns.key,aspectPath,pathKey,parsePath,isMeaningfulName,guardKey— identity computation frommeta;pathKeyis the one escaping rendering of a path andparsePathits inverse.keyroutes two ways: static aspects (viameta.loc, the declared path stamped intrinsically at merge from the option path — A-IDENT;nameandmeta.aspect-chainare its renderings and a contradicting chain refuses by name; a named element written in anincludeslist keys by its declaring site and an unnamed one by its declaration address, both stamped as itsmeta.loc) and first-order guard records (__guard: a placed guard keys by its declared path,meta.loc, stamped by placement, so two declarations one payload apart are two keys; an unplaced guard answersguardKey, its TERM's identity — the mint over the condition and body terms, defined once the guard is checked against its cnf; a module function in the body is a slot keyed by its position, never its payload, and there is no source-position fallback). Both are container-relative (re-rooted byaspectsRoot), so plain and guard keys share one namespace.
mkAspectSchema cnf— bridges aspect types to gen-schema kind-level infrastructure. ReturnsschemaOption,mkAspectOption,mkAspectModule,mkNamespaceType, plus re-exports (aspectType,identity,canTake,mkIsModuleFn). See Schema Integration.flatten aspects— walks the recursive aspect tree into a flat attrset keyed bypathidentity ("parent/child"), structurally detecting nested aspects vs class content. The key is a rendering of a parent edge, never the edge; readgraphFactsfor parenthood. See Flat Registry.graphFacts cnf aspects— the aspect graph's facts as plain data:{ nodes; parentOf; includeSitesOf; includesOf; foreignIncludesOf; unresolvedIncludesOf; nodeIdOf; nodeData; deliversOf; deadNested; }, keyed by origin-qualified node id (nodeIdOfby local key).parentOfis the walk position and is total by construction;includeSitesOfclassifies every include position in order and the three include relations project from it; inline include content is published as positions, and a reference whose target is missing refuses by name.deliversOfsays whether a node's subtree delivers (declared class content, includes, a guard leaf, or a delivering child), anddeadNestedis the nested nodes whose subtree does not; the record warns once each time it is forced whiledeadNestedholds a node whose node id is not listed incnf.freeformKeys(a misspelt class key warns; intended placeholder taxonomy is declared by listing its id, e.g."hemline/placket/eyelet", which silences it for that node only). See Published facts.includeSitesOfInstance cnf aspects instances iid: the include sites of the vertexiidof the instance relationinstances(instancesFor's), by the classificationgraphFactspublishes asincludeSitesOf, so the relation and its reader classify a body with one rule. It reads the vertex's entry itself, and a vertex with no entry has no sites. Anonymous content is keyed underiid, each content site'starget<iid>/includes/<i>, recursively; a named value'stargetis its class: the static class it joins, its content digest, or, for content the identity mint refuses, a class within its instance, and its site carriesinfo, the sighting's record (see Published facts). Partially applied toinstances, the classes are computed once. A non-attrset where the relation goes (the earlieriid entrycall) is refused by name.isGuardLeaf v— whether an aspect value is a guard leaf (a wrapped fn or a guard record), the node shapeflattenandgraphFactsstop at.
The examples/demo/ directory exercises nine gen libraries together: gen-algebra, gen-schema, gen-aspects, gen-graph, gen-scope, gen-select, gen-bind, gen-dispatch, and gen-delivery. It demonstrates entities, aspects, namespaces, policies, queries, bindings, composition, settings, and delivery-class realization in a single integrated flake, over invented node kinds: gen names no domain entities, and a framework supplies its own names.
nix develop ./ci --command cici refuses when anything under a declared read root is unknown to git — any extension or name,
_-prefixed included — and the remedy is git add or a move. The bare nix-unit --flake ./ci#tests
and nix flake check ./ci are unguarded: they read a git-filtered copy of the tree, so an untracked
cell is silently absent and the run stays green.
626 cells on the value plane and 167 on the error plane (nix develop ./ci --command ci ⇒ 626/626 successful, ci --tests-error ⇒ 167/167 successful) — one file per suite under ci/tests/, which is the count's own source rather than a list restated here, since the last three restatements (115/17, 236/33, then 247/34) each went stale by the next landing. Coverage spans class content cleanliness, nested aspect identity, includes fixpoint, module vs guard function dispatch, first-order guards over gen-algebra's term algebra (ci/tests/first-order-guards.nix: the condition vocabulary, the declared set, identity, instance keys, the door and its totality, nested guards and the depth budget behind a cyclic body), lazy classification, parametric aspects, multi-def merging, reserved keys, primitive passthrough, deep nesting, extensions, meta modules, canTake introspection, schema integration, and the flat registry.
| Paper | Relationship | Mechanism |
|---|---|---|
| Palmer et al. (2024) "Intensional Functions" | Implements | Flat dispatch via one type in merge §2, identity §2.2; identity keys enable consumer-side dedup |
| Lorenzen et al. (2025) "First-Order Laziness" | Informed by | deferredModule inspectable before forcing (via Nix native laziness, not Lorenzen's mechanism) §1-2.3 |
| Reynolds (1972) "Definitional Interpreters" · Danvy & Nielsen (2001) "Defunctionalization at Work" | Implements | §6 "Elimination of Higher-Order Functions" for guards (mkGuardVocab/pred/applyGuard/guardKey): a guard is a condition term and a body term of gen-algebra's one first-order algebra, interpreted by its one resolver through this library's read environment, keyed by the mint over the two. A raw { thimble, … }: closure is refused by name: it crosses the gen-rules door |
Palmer et al. (2024) "Intensional Functions" — One type dispatches by value shape in merge (§2). Guard functions are defunctionalized as callable first-order data with inspectable args (§5.1). Identity keys enable consumer-side diamond dedup (Lemma 5.12 + Theorem 1, closure consistency); gen-aspects supplies the keys, the dedup lives in the consumer.
Lorenzen et al. (2025) "First-Order Laziness" (informed by) — Class content as deferredModule is inspectable before forcing, evaluated only when the consuming NixOS evaluation imports it (§1-2.3). This property comes from Nix native laziness plus nixpkgs deferredModule, NOT from Lorenzen's mechanism (first-order named constructors, defunctionalized deferred operations, in-place memoization). The citation is provenance for the laziness idea, not an implementation of the paper.
Reynolds (1972) "Definitional Interpreters" + Danvy & Nielsen (2001) "Defunctionalization at Work" — a guard is { __guard; condition; body; }, a condition term and a body term of gen-algebra's ONE first-order algebra (lib/guard-term.nix is this library's instance of it). The condition vocabulary (pred.class/tagEq/eq/has/all/any/always/not) is constructors emitting core terms, so there is one interpreter, the core's resolver (Reynolds' apply), whose read environment gen-aspects supplies. A custom condition is a Nix function that builds a term at declaration: a new interpreted atom would need a case in the one apply function, a closure held beside it, which is what defunctionalization removes. A body is a term or first-order data, lifted to its term where the guard meets its cnf and checked there (shape, declared names, safety); a class key's value is a declared module slot, carried opaque, and a module function at another position of the body is a slot keyed by its position. A guard's identity is the mint over (condition, body), defined once it is checked, with no source-position fallback. A guard nested in a body stays a guard: it is checked as its own clause and fires at its own firing. The lift spends one depth budget, so a cyclic body is refused by name (guard-depth), catchably, rather than aborting the evaluator. Honest boundary: arbitrary { thimble, … }: { … } closures cannot be auto-defunctionalized in pure Nix (function equality is undecidable — the closure wall), so gen-aspects holds none: a context closure is refused by name, naming the gen-rules door, the one closure crossing (design Q8 (c′)), which lowers it to a door node.
MIT — see LICENSE.