flake: instantiate the entrypoint once per system #6

Merged
kiara merged 1 commit from hoist-flake-entrypoint into main 2026-08-12 23:47:44 +02:00
Owner

The flake wrapper applied the entrypoint once per (attr, system) pair. import memoizes the file value, not the application, so none of those applications shared any of the entrypoint's internal work -- each re-ran the whole let, including the pkgs ? import sources.nixpkgs { ... } default argument, i.e. a whole fresh nixpkgs.

Binding one instantiation per system in the let and reading every keyed output out of it collapses that.

Measured on fediversity-ci, nix flake show --no-eval-cache, warm store, second of two runs:

wall user+sys maxrss nrThunks gc.totalBytes
before 1.99 s 1.31 s 223 MB 565,116 168.7 MB
after 1.50 s 0.95 s 132 MB 261,485 76.0 MB

Output is unchanged: nix flake show --json --all-systems --no-eval-cache | jq -S . is byte-identical before and after, and every drvPath is unmoved bar the treefmt check's, which hashes the project source and so moves with any edit to flake.nix itself.

This is the same defect that cost the fediversity monorepo far more (its entrypoints carry a whole deployment surface, not just a nixpkgs); the wrapper was copied from https://codeberg.org/kiara/poc-override-nix-deps, which is being fixed at the source too.

The flake wrapper applied the entrypoint once per `(attr, system)` pair. `import` memoizes the *file* value, not the *application*, so none of those applications shared any of the entrypoint's internal work -- each re-ran the whole `let`, including the `pkgs ? import sources.nixpkgs { ... }` default argument, i.e. a whole fresh nixpkgs. Binding one instantiation per system in the `let` and reading every keyed output out of it collapses that. Measured on `fediversity-ci`, `nix flake show --no-eval-cache`, warm store, second of two runs: | | wall | user+sys | maxrss | nrThunks | gc.totalBytes | |---|---|---|---|---|---| | before | 1.99 s | 1.31 s | 223 MB | 565,116 | 168.7 MB | | after | 1.50 s | 0.95 s | 132 MB | 261,485 | 76.0 MB | Output is unchanged: `nix flake show --json --all-systems --no-eval-cache | jq -S .` is byte-identical before and after, and every `drvPath` is unmoved bar the `treefmt` check's, which hashes the project source and so moves with any edit to `flake.nix` itself. This is the same defect that cost the fediversity monorepo far more (its entrypoints carry a whole deployment surface, not just a nixpkgs); the wrapper was copied from https://codeberg.org/kiara/poc-override-nix-deps, which is being fixed at the source too.
flake: instantiate the entrypoint once per system
All checks were successful
check / treefmt (pull_request) Successful in 6s
check / nix-unit (pull_request) Successful in 26s
d0c23bdd5a
`import` memoizes the file value, not the application, so applying the
entrypoint per (attr, system) shared none of its internal work: every
`(attr, system)` pair re-ran the whole `let`, `pkgs` default argument --
a whole nixpkgs -- included. Bind one instantiation per system and read
every keyed output out of it.

Output is unchanged: `nix flake show --json --all-systems` is
byte-identical before and after, and every `drvPath` is unmoved bar the
`treefmt` check's, which hashes the project source and so moves with any
edit to `flake.nix` itself.
kiara merged commit 711e977f6b into main 2026-08-12 23:47:44 +02:00
kiara deleted branch hoist-flake-entrypoint 2026-08-12 23:47:45 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
fediversity/nix-tf-schema!6
No description provided.