Skip to content

feat: built-in flake-parts entity kind - #543

Merged
sini merged 13 commits into
mainfrom
feat/builtin-flake-parts-entity
May 15, 2026
Merged

sini merged 13 commits into
mainfrom
feat/builtin-flake-parts-entity

Conversation

@sini

@sini sini commented May 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Makes flake-parts a built-in entity kind, eliminating ~80 lines of boilerplate users previously had to write for flake-parts integration (custom policies, manual perSystem.imports injection, systems derivation, isEntity flag).

  • Register flake-parts as unconditional schema kind
  • Define system-to-flake-parts and packages-to-flake-parts policies (guarded on inputs ? flake-parts, opt-in via schema wiring)
  • Auto-inject resolved flake-parts entity into perSystem.imports and set systems = den.systems
  • Simplify flake-parts-modules template: delete flake-parts.nix + systems.nix, simplify packages.nix from 23→4 lines, remove inline policy definitions from den.nix

Fixes #545 — all shipped policy names now follow source-to-target convention:

Old New
to-systems flake-to-systems
to-os-outputs system-to-os-outputs
to-hm-outputs system-to-hm-outputs
to-packages packages-to-flake
to-apps apps-to-flake
to-checks checks-to-flake
to-devShells devShells-to-flake
to-legacyPackages legacyPackages-to-flake

Design constraints: no secondary pipeline, no hardcoded filter lists, no mkForce/merge overrides. Content flows naturally through route policies into perSystem.imports.

User-facing change

# Before: ~80 lines of boilerplate
den.policies.to-flake-parts = { system, ... }: [ ... ];
den.schema.flake-parts.isEntity = true;
perSystem.imports = [ (den.lib.aspects.resolve ...) ];
systems = builtins.attrNames den.hosts;

# After: schema wiring only
den.schema.flake-system.includes = [ den.policies.system-to-flake-parts ];
den.schema.flake-system.excludes = [ den.policies.packages-to-flake ];
den.schema.flake-parts.includes = [ den.policies.packages-to-flake-parts ];

Test plan

  • nix develop -c just ci — 808/808 tests pass
  • nix develop -c just check-all — all templates pass
  • Code review — no critical/important issues

@sini
sini requested a review from vic as a code owner May 14, 2026 21:23
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label May 14, 2026
@sini
sini force-pushed the feat/builtin-flake-parts-entity branch 8 times, most recently from f349718 to 69fac9c Compare May 15, 2026 06:34
@sini

sini commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

Adding a update for #545 here as well

sini added 13 commits May 15, 2026 00:25
The perSystem option only exists in flake-parts mkFlake contexts,
not in denTest evalModules. Checking options ? perSystem causes
infinite recursion. Instead, denTest sets __denTest specialArg
and outputs.nix skips injection when it's present.
flakeModule now supports three modes:
  inputs.den.flakeModule               -- no bridging (backwards compat)
  inputs.den.flakeModule true          -- auto-discover outer options, bridge all
  inputs.den.flakeModule ["flake-file"] -- explicit bridge keys

Auto-discovery uses builtins.attrNames options inside a { config = ... }
return, which avoids the module system's eager key enumeration cycle.
The inner flake evalModules has freeformType to capture routes at
arbitrary paths; den.lib.flakeRouted exposes the content lazily.
flakeModule auto-discovers declared top-level options and bridges
routed flake content to them. No manual bridging needed.

Uses builtins.attrNames options (config-free) inside { config = ... }
to avoid the module system's eager key enumeration cycle. Guarded on
inputs ? flake-parts to skip non-flake-parts contexts.

Route any path:
  den.lib.policy.route { intoClass = "flake"; path = ["X" "Y"]; }
Content auto-arrives at config.X.Y in flake-parts.

For explicit key override: inputs.den.flakeBridge ["key"]
The flake-parts entity content flows naturally through route policies
into perSystem.imports — the secondary evalModules with freeformType,
hardcoded internalKeys filters, and mkIf/genAttrs bridge were unnecessary.
Restore __denTest sentinel — needed because nix-unit tests in
flake-parts-modules evaluate through denTest where perSystem doesn't
exist. Two separate guards: no-flake-parts (inputs only) controls the
flakeOutputs import, has-flake-parts (inputs + sentinel) controls
perSystem injection.
Transition policies now read as source-to-target:
  system-to-flake-parts, packages-to-flake-parts,
  devshell-to-flake-parts, treefmt-to-flake-parts,
  tests-to-flake-parts, files-to-flake-parts
to-systems         → flake-to-systems
to-os-outputs      → system-to-os-outputs
to-hm-outputs      → system-to-hm-outputs
to-packages        → packages-to-flake
to-apps            → apps-to-flake
to-checks          → checks-to-flake
to-devShells       → devShells-to-flake
to-legacyPackages  → legacyPackages-to-flake

Policy names now describe both source and destination, matching
the convention established by host-to-users, system-to-flake-parts,
and packages-to-flake-parts.
@sini
sini force-pushed the feat/builtin-flake-parts-entity branch from 9cad81b to 78ef223 Compare May 15, 2026 07:29
@sini
sini enabled auto-merge (squash) May 15, 2026 07:31

@theutz theutz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice. Oh, that's so much easier to understand for me. Thank you!

@sini
sini merged commit 40ed2f9 into main May 15, 2026
27 of 29 checks passed
@sini
sini deleted the feat/builtin-flake-parts-entity branch May 15, 2026 08:18
charlesfire pushed a commit to charlesfire/den that referenced this pull request May 16, 2026
## Summary

Makes flake-parts a built-in entity kind, eliminating ~80 lines of
boilerplate users previously had to write for flake-parts integration
(custom policies, manual `perSystem.imports` injection, `systems`
derivation, `isEntity` flag).

- Register `flake-parts` as unconditional schema kind
- Define `system-to-flake-parts` and `packages-to-flake-parts` policies
(guarded on `inputs ? flake-parts`, opt-in via schema wiring)
- Auto-inject resolved flake-parts entity into `perSystem.imports` and
set `systems = den.systems`
- Simplify `flake-parts-modules` template: delete `flake-parts.nix` +
`systems.nix`, simplify `packages.nix` from 23→4 lines, remove inline
policy definitions from `den.nix`

Fixes denful#545 — all shipped policy names now follow `source-to-target`
convention:

| Old | New |
|-----|-----|
| `to-systems` | `flake-to-systems` |
| `to-os-outputs` | `system-to-os-outputs` |
| `to-hm-outputs` | `system-to-hm-outputs` |
| `to-packages` | `packages-to-flake` |
| `to-apps` | `apps-to-flake` |
| `to-checks` | `checks-to-flake` |
| `to-devShells` | `devShells-to-flake` |
| `to-legacyPackages` | `legacyPackages-to-flake` |

**Design constraints:** no secondary pipeline, no hardcoded filter
lists, no mkForce/merge overrides. Content flows naturally through route
policies into `perSystem.imports`.

## User-facing change

```nix
# Before: ~80 lines of boilerplate
den.policies.to-flake-parts = { system, ... }: [ ... ];
den.schema.flake-parts.isEntity = true;
perSystem.imports = [ (den.lib.aspects.resolve ...) ];
systems = builtins.attrNames den.hosts;

# After: schema wiring only
den.schema.flake-system.includes = [ den.policies.system-to-flake-parts ];
den.schema.flake-system.excludes = [ den.policies.packages-to-flake ];
den.schema.flake-parts.includes = [ den.policies.packages-to-flake-parts ];
```

## Test plan

- [x] `nix develop -c just ci` — 808/808 tests pass
- [x] `nix develop -c just check-all` — all templates pass
- [x] Code review — no critical/important issues
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make all Den shipped policy names to read a-to-b

2 participants