Skip to content

feat: fx effects pipeline — replace legacy resolver - #475

Merged
sini merged 522 commits into
mainfrom
feat/fx-pipeline
May 9, 2026
Merged

sini merged 522 commits into
mainfrom
feat/fx-pipeline

Conversation

@sini

@sini sini commented Apr 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replace den's legacy recursive resolver with an algebraic effects pipeline (via nix-effects). The entire resolution lifecycle — from policy routing to aspect compilation to module collection — is now driven by composable effect handlers.

  • Remove legacy resolver — delete adapters.nix, resolve.nix, statics.nix (~450 lines). Fx handlers own everything: include resolution, parametric args, transitions, constraints, dedup.
  • Four-concern separation — decompose den.ctx into den.policies (directed entity edges), den.stages (scoped behavior bindings), den.schema (entity types), and den.aspects (reusable behavior).
  • Effectful bootstrap — pipeline setup is itself effectful via resolve-policy and resolve-target effects, making the entire lifecycle interceptable.
  • Per-policy named handlers — policies can declare handlers that get scope.provide'd into transition sub-computations (Layer 2 foundation).
  • den.ctx compat shim — always-imported, forwards den.ctx.* to den.stages.* with deprecation warnings. Covers scoped behavior + into forwarding.

481 tests passing (22 new). Net: -149 lines across 197 files.

Detailed walkthrough

Simplified Review Guide — plain-language explanation of the architecture, handler vocabulary, context propagation, and what changed from main.

Commits

Commit What
remove legacy resolver Delete adapters/resolve/statics, gut parametric, fx handlers own resolution
ctx-as-data transitions scope.provide + __scopeHandlers, deferred includes, fan-out identity
edge cases Fan-out dedup, cross-providers, perCtx, constraint cascade
parametric type separation __fn/__args replace __functor, scope.provide replaces scope.stateful
four-concern separation den.stages + den.policies + entity consolidation, remove den.ctx
code quality Decompose oversized functions, naming, comments, efficiency
policies rename + compat den.relationships → den.policies, ctx compat shim
effectful bootstrap resolve-policy/resolve-target effects, policy handlers, depth guards, tests

Next steps (separate PRs)

  • aspect-chain removal — 3 files still use fromAspect/aspect-chain; replace with item.resolved
  • Generic fan-out isolation — current fix scopes to targetClass == "flake"; needs hierarchical dedup
  • Layer 2: per-policy named effects — the handlers field is wired; next is user-facing documentation and batteries that use it
  • Vestigial removal — parametric.nix, take.nix, perHost-perUser.nix once downstream migrates

Test plan

Documentation overhaul

Rendered documentation can be previewed at: https://den.json64.dev/

🤖 Generated with the aid of Claude Code

@sini
sini force-pushed the feat/fx-pipeline branch from 168d607 to 7167f88 Compare April 23, 2026 20:24
@sini

sini commented Apr 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

TODO:
Docs revamp - changed some things, need another update/rework
Followup work on policies w/ ACL example - need a demo template exercising them in a rich capacity
Diagram generation -- regression, need fixing
Have some brave users actually test this branch

TODO more like DONE

@sini
sini force-pushed the feat/fx-pipeline branch 3 times, most recently from 2fb2263 to aac3d51 Compare April 23, 2026 21:09
@vic vic added allow-ci allow all CI integration tests super-autocompleted "Artificial Intelligence" terms nothing real, "Super Intelligence" is even more of a lie. labels Apr 23, 2026
@sini
sini force-pushed the feat/fx-pipeline branch 2 times, most recently from 3de71c4 to d3060d7 Compare April 23, 2026 22:50
@sini

sini commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator Author

Working on some straggling edge-cases around the flake / flake-packages / flake-system integration. Otherwise the core is ready for review, only minor fixes pending.

@sini
sini force-pushed the feat/fx-pipeline branch 3 times, most recently from 0910c3f to 3928b87 Compare April 23, 2026 23:51
@sini

sini commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator Author

I was hoping to dodge it -- but alas. Larger change coming in replacing forwards with an effect handler. :)

vic
vic previously requested changes Apr 24, 2026

@vic vic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick review up to my energy posibilities. Added a few comments, maybe we can also run a code-simplification run on code after forwards are done.

Ping me when I can review again.

Comment thread modules/options.nix Resolved
Comment thread modules/policies/flake.nix Resolved
Comment thread modules/policies/flake.nix Resolved
Comment thread modules/policies/flake.nix Resolved
Comment thread modules/policies/core.nix Resolved
Comment thread modules/policies/batteries.nix Resolved
Comment thread modules/policies/batteries.nix Resolved
Comment thread nix/lib/aspects/fx/trace.nix Resolved
Comment thread nix/lib/aspects/fx/handlers/include.nix Resolved
Comment thread nix/lib/aspects/fx/aspect.nix Resolved
@sini
sini force-pushed the feat/fx-pipeline branch from 3928b87 to c0d9dc5 Compare April 24, 2026 02:06
@sini
sini marked this pull request as draft April 24, 2026 03:06
@sini
sini force-pushed the feat/fx-pipeline branch 4 times, most recently from 35706cb to 2c20b4b Compare April 24, 2026 04:29
@sini
sini marked this pull request as ready for review April 24, 2026 04:45
Comment thread modules/aspects/provides/os-class.nix Resolved
Comment thread modules/aspects/provides/os-user.nix Resolved
@vic
vic dismissed their stale review April 24, 2026 19:00

reviewing lib

Comment thread nix/lib/aspects/types.nix Resolved
Comment thread nix/lib/synthesize-policies.nix Resolved
Comment thread nix/lib/stage-types.nix Resolved
Comment thread nix/lib/resolve-stage.nix Resolved
Comment thread nix/lib/namespace.nix Resolved
sini added 4 commits May 8, 2026 15:24
The subtree collection added in 8659af2 walked all descendant scopes
for every simple route. Non-flake routes (e.g. flake-parts template
class routes) don't need subtree collection and it caused two bugs:
packages collision with the builtin to-packages route, and missing
scope args (tux) when user-scope test modules were pulled into the
flake-parts route context where adaptArgs discards entity-specific args.

Restrict collectFromSubtree to flake routes only. Non-flake routes
fall back to single-scope lookup, matching pre-8659af23 behavior.
pnpm 11 requires Node.js v22.13+. The GitHub runner ships v20 which
lacks the node:sqlite builtin that pnpm 11 depends on.
pnpm 11 blocks dependency build scripts by default. Add
pnpm-workspace.yaml with onlyBuiltDependencies whitelist for
esbuild and sharp, which need native compilation.
onlyBuiltDependencies was removed in pnpm 11. The replacement is
allowBuilds with a map of package names to booleans.
@sini
sini requested a review from vic May 8, 2026 22:36
sini added 5 commits May 8, 2026 16:28
…s null

policy.instantiate can now collect class modules from any scope level
(e.g., flake-system scope for perSystem class collection) instead of
dropping to mainModule when no entity scope matches.
Three fixes for collect-perSystem to work correctly:

1. flake-parts.nix: merge duplicate perSystem attrs (nix-unit settings
   + class wiring) into single block; use evalClassModules for files
   class since files perSystem doesn't expose .imports

2. resolve.nix: guard mainModule fallback with `spec ? mainModule` so
   non-entity instantiate specs (which lack mainModule) get empty list
   instead of crashing when no walked modules found

3. resolve.nix: gate findHostScopeId single-child fallback to entity
   specs only — non-entity specs (collect-perSystem) must fall through
   to sourceScopeId to collect from full flake-system subtree, not just
   the host subtree
Replace old den.ctx/provides.forward with policy.route and
den.schema.flake-parts. Each custom class (treefmt, devshell,
packages, files, tests) has a route policy delivering into the
flake-parts class with adaptArgs for perSystem args.

Uses den.lib.aspects.resolve for the flake-parts class resolution
(separate pipeline). Test helpers (tux/igloo) provided via
adaptArgs closure over config.flake.nixosConfigurations.

Pipeline extensions:
- resolve.nix: sourceScopeId fallback for non-entity instantiate
- resolve.nix: intoPath support and hasOutput check for intoPath
- route/apply.nix: collectSubtree flag for non-flake routes

Template outputs: packages (cowsay, htop, hola, write-files),
devShells.default, treefmt, nix-unit (1 test), files/README.md,
nixosConfigurations.igloo. 757/757 CI tests pass.
@sini
sini force-pushed the feat/fx-pipeline branch from 3e713bc to 6593d1b Compare May 9, 2026 01:40
Replace den.ctx/provides.forward with policy.route and
den.schema.flake-parts. Each custom class (treefmt, devshell,
packages, files, tests) has its own file with a route policy.

Pipeline changes:
- resolve.nix: sourceScopeId fallback for non-entity instantiate specs
- resolve.nix: merge all instantiate outputs into single module via
  recursiveUpdate (reverts 6118a7c grouping which broke freeform
  unique-type merge for multi-key outputs)
- route/apply.nix: collectSubtree flag for non-flake routes

Template uses den.lib.aspects.resolve for the flake-parts class.
Test helpers (tux/igloo) provided via adaptArgs closure.

All outputs verified: packages (cowsay, htop, hola, write-files),
devShells.default, treefmt, nix-unit (1/1), files/README.md,
nixosConfigurations.igloo. 757/757 CI tests pass.
@sini
sini force-pushed the feat/fx-pipeline branch from b4a891b to 2b505b4 Compare May 9, 2026 02:40
theutz
theutz previously approved these changes May 9, 2026
@sini
sini dismissed vic’s stale review May 9, 2026 02:45

stale

Replace dagre with elkjs for layout with configurable node placement
strategies (LINEAR_SEGMENTS default). Add scope-based grouping with
host containers and nested user sub-groups. Implement interactive
collapse/expand via double-click on scope nodes with edge rerouting
and hidden node count badges. Add edge hover highlighting and node
click to highlight connected edges. Pipe edges excluded from layout.

Update diagram-demo to include fleet views (pipe-flow, scope-topology,
aspect-matrix, policy-resolution, pipe-sequence, fleet-dag, fleet-ir)
and text summaries matching fleet-demo capabilities.
@sini
sini merged commit 6254414 into main May 9, 2026
47 checks passed
@sini
sini deleted the feat/fx-pipeline branch May 9, 2026 13:46
@drupol

drupol commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Massive :) congratulations!

drupol added a commit to drupol/infra that referenced this pull request May 9, 2026
charlesfire pushed a commit to charlesfire/den that referenced this pull request May 16, 2026
## Summary

Replace den's legacy recursive resolver with an algebraic effects
pipeline (via nix-effects). The entire resolution lifecycle — from
policy routing to aspect compilation to module collection — is now
driven by composable effect handlers.

- **Remove legacy resolver** — delete adapters.nix, resolve.nix,
statics.nix (~450 lines). Fx handlers own everything: include
resolution, parametric args, transitions, constraints, dedup.
- **Four-concern separation** — decompose `den.ctx` into `den.policies`
(directed entity edges), `den.stages` (scoped behavior bindings),
`den.schema` (entity types), and `den.aspects` (reusable behavior).
- **Effectful bootstrap** — pipeline setup is itself effectful via
`resolve-policy` and `resolve-target` effects, making the entire
lifecycle interceptable.
- **Per-policy named handlers** — policies can declare `handlers` that
get `scope.provide`'d into transition sub-computations (Layer 2
foundation).
- **`den.ctx` compat shim** — always-imported, forwards `den.ctx.*` to
`den.stages.*` with deprecation warnings. Covers scoped behavior + into
forwarding.

**481 tests passing** (22 new). Net: -149 lines across 197 files.

## Detailed walkthrough

[Simplified Review
Guide](https://gist.github.com/sini/dea443d26352b3cbd667d88ee4b34508) —
plain-language explanation of the architecture, handler vocabulary,
context propagation, and what changed from main.

## Commits

| Commit | What |
|--------|------|
| remove legacy resolver | Delete adapters/resolve/statics, gut
parametric, fx handlers own resolution |
| ctx-as-data transitions | scope.provide + __scopeHandlers, deferred
includes, fan-out identity |
| edge cases | Fan-out dedup, cross-providers, perCtx, constraint
cascade |
| parametric type separation | __fn/__args replace __functor,
scope.provide replaces scope.stateful |
| four-concern separation | den.stages + den.policies + entity
consolidation, remove den.ctx |
| code quality | Decompose oversized functions, naming, comments,
efficiency |
| policies rename + compat | den.relationships → den.policies, ctx
compat shim |
| effectful bootstrap | resolve-policy/resolve-target effects, policy
handlers, depth guards, tests |

## Next steps (separate PRs)

- **aspect-chain removal** — 3 files still use
`fromAspect`/`aspect-chain`; replace with `item.resolved`
- **Generic fan-out isolation** — current fix scopes to `targetClass ==
"flake"`; needs hierarchical dedup
- **Layer 2: per-policy named effects** — the `handlers` field is wired;
next is user-facing documentation and batteries that use it
- **Vestigial removal** — `parametric.nix`, `take.nix`,
`perHost-perUser.nix` once downstream migrates

## Test plan

- [x] 481/481 CI tests pass (`nix develop -c just ci`)
- [x] Downstream validation against:
  - [theutz/slashfiles](https://github.com/theutz/slashfiles)
  - [drupol/infra](https://github.com/drupol/infra)
  - [sjcobb2022/nix-den](https://github.com/sjcobb2022/nix-den)
-- all hosts work with ctx compat shim -- even fixed another bug the
owner was facing 🥇
- [ ] Review by @vic

## Documentation overhaul
Rendered documentation can be previewed at: https://den.json64.dev/

🤖 Generated with the aid of [Claude
Code](https://claude.com/claude-code)

---------

Co-authored-by: Michael Utz <[email protected]>
sini added a commit that referenced this pull request Jun 1, 2026
## Problem

Fixes #583. When two aspects contribute to the same forward source class
and the forward fires at a child (user) scope while routing into a
parent (host) class, the host's own contribution is silently dropped:

```nix
den.aspects.atuin = {
  includes = [ atuinClass ];   # forwards `atuin` → nixos programs.atuin
  atuin.flags = [ "--hello" ];
};
den.aspects.igloo = {
  provides.to-users.includes = [ den.aspects.atuin ];
  atuin.flags = [ "--world" "--baz" ];
};
```

Produces `programs.atuin.flags = [ "--hello" ]` instead of the merged `[
"--hello" "--world" "--baz" ]`.

Worked in v0.16; regressed with the fx-pipeline rewrite (#475).

## Root cause

`route/apply.nix:getCollectedSource` merges a complex forward's
own-scope source modules with the root (host) scope's `fromClass`
content, but filtered the root content unconditionally through
`isDenDefaultModule` — keeping only `@default`-keyed modules. The host's
own `atuin` content (module key `atuin@igloo`) is not a `den.default`
module, so it was filtered out, leaving only the user-scope `--hello`.

That `@default`-only filter is **correct** for entity-owned classes: the
home-manager battery's `homeManager → nixos` forward must not implicitly
pull a host's own `homeManager` config into every user's home — that
projection is opt-in via `host-aspects`. It is **wrong** for a custom
forward-only class like `atuin`, whose host-scope content exists solely
to be aggregated.

## Fix

Restrict root content to `@default` only when `fromClass` is a class an
entity in the scope chain owns (`user.classes`, `host.class`,
`home.class`, read from `scopeContexts`); otherwise keep the root
content in full. The owned-class set is total over all three entity
kinds so the decision never falls open for a non-user-owned scope.

The discriminator keys on `fromClass` rather than `intoClass`
deliberately — `host-aspects.test-opt-in-only` and
`user-host-mutual-config.test-host-owned-unidirectional` both forward
`homeManager` into `nixos` yet must keep their opt-in projection
semantics.

## Validation

- New regression test `deadbugs/issue-583-forwarding-overwrite.nix`
(mirrors the report): overwrite → ✅ 1/1
- `host-aspects` ✅ 10/10 and `user-host-mutual-config` ✅ 9/9 — opt-in
projection unchanged
- Full CI: **839/839** ✅
- Formatting clean
sini added a commit that referenced this pull request Nov 10, 2026
#758)

## Summary

A new docs page, **What's Changed in Den** (`/whats-changed/`, linked
under Start), so a user on any old release can answer "what's changed
since 0.X?". [Discussion
#757](#757) asked exactly this
when upgrading from 0.8 to 0.19, and found the release notes too
fine-grained to give the big picture.

The page has:
- **A table of every release** from 0.1 to the upcoming #694 release,
one line each.
- **A section per release or group of releases,** with only the changes
that alter how you write a config. Each section gives before/after code
where the form changed: the `den.default` merge (0.3), the `{ OS, host
}` markers going away (0.9), `user.classes` (0.10–0.11), parametric by
default and `den.base` → `den.schema` (0.12), explicit `provides`
(0.13), the effects rewrite (0.17) with its two big ideas, **policies**
(relations between entities as rules, with an example) and **identity**
(`id_hash` on every entity, plus aspect identity behind dedup), the
`den.ctx` → `den.schema` plus `den.policies` split, and scoped context
(0.18).
- **An "Upgrading in one jump" checklist.** It names the forms that stop
evaluation outright (`den.base`, `den._.home-manager`, pre-0.3
`den.default.host`) and the silent one: users now default to `classes =
[ "user" ]`, so a config that relied on `den._.home-manager` has to set
home-manager explicitly. It ends with comparing derivations old against
new.

It covers the big features and patterns only; the release notes stay the
place for detail.

## How it was written

From every release's notes (v0.1.0–v0.19.0), with each claim checked
against den's history and current code:
- `parametric.context` became `fixedTo` in #85.
- `den.provides.home-manager` throws from v0.11
(`hm-integration.nix:70`), and no `den.batteries.home-manager` exists on
main.
- `user.classes` defaults to `[ "user" ]`
(`nix/lib/entities/host.nix:156`).
- The `den.ctx` split was #475, and `den.batteries` with the `den._` /
`den.provides` aliases was #504.

The checklist matches a real migration of a 0.8 config to main: every
host evaluated with no deprecation warnings, and each drv matched up to
list order.

## Validation

- `just docs-build` (CI's docs command): builds, and **all internal
links are valid** (starlight-links-validator).
- It links only to pages that already exist on `main`, so it doesn't
depend on the #694 stack. The "next" section points to the #750
announcement instead of the new pages in #753 and #756. Those links can
be added once the stack lands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests super-autocompleted "Artificial Intelligence" terms nothing real, "Super Intelligence" is even more of a lie.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants