flake: instantiate the entrypoint once per system #13

Merged
kiara merged 1 commit from hoist-flake-entrypoint into main 2026-08-12 23:47:35 +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 0.73 s 0.53 s 168 MB 351,775 121.0 MB
after 0.61 s 0.41 s 83 MB 110,647 35.3 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 | 0.73 s | 0.53 s | 168 MB | 351,775 | 121.0 MB | | after | 0.61 s | 0.41 s | 83 MB | 110,647 | 35.3 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
checks-panel-forms-island / panel-forms-island (pull_request) Successful in 3s
checks-panel-forms-island-docs / panel-forms-island-docs (pull_request) Successful in 5s
checks-treefmt / treefmt (pull_request) Successful in 5s
checks-panel-forms-island-dom / panel-forms-island-dom (pull_request) Successful in 22s
c604d57ce4
`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 1e00e34061 into main 2026-08-12 23:47:35 +02:00
kiara deleted branch hoist-flake-entrypoint 2026-08-12 23:47:35 +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-module-form!13
No description provided.