Skip to content

Simplify DerivationGoal in many ways#13753

Merged
Mic92 merged 13 commits intoNixOS:masterfrom
obsidiansystems:simplify-derivation-goal
Aug 15, 2025
Merged

Simplify DerivationGoal in many ways#13753
Mic92 merged 13 commits intoNixOS:masterfrom
obsidiansystems:simplify-derivation-goal

Conversation

@Ericson2314
Copy link
Copy Markdown
Member

Motivation

Taking advantage of the splitting up of DerivationGoal into multiple goals to now unlock a bunch of simplifications. It's best to review this commit-by-commit.

Context

This will help me with working on floating content-addressing and dynamic derivations by "cleaning the workbench" before the work begins.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

See the comment in the code for details. Some of the code is duplicated
for now, but we'll be cleaning that up soon.
We know we want exactly want output in `DerivationGoal` now (since
recent refactors), so we can start simplifying things to take advantage
of this.
We don't need the `wanted` field. Just inline the other two fields.
More taking advantage of single wanted output. Also `auto *` not `auto`
for easy reading.
Now that the loops is gone, we can just inline this mutation to a single
simple expression.
`Store::queryPartialDerivationOutputMap` is nothing but checking
statically-known output paths, and then `Store::queryRealisation`, and
we were doing both of those things already. Inline that and simplify,
again taking advantage of the fact that we only care about one output.
Now that `DerivationGoal::checkPathValidity` is legible, we can see that
it only sets `outputKnown`, and doesn't read it. Likewise, with
co-routines, we don't have tiny scopes that make local variables
difficult. Between these two things, we can simply have
`checkPathValidity` return what it finds, rather than mutate some state,
and update everyting to use local variables.

The same transformation could probably be done to the other derivation
goal types (which currently, unfortunately, contain their own
`checkPathValidity`s, though they are diverging, and we hope and believe
that they continue to diverge).
We don't need it any more, because we only used it in the
single-wanted-output `DerivationGoal`.
We can shuffle around control flow so it's only called once. You'll
definitely want to review this diff ignoring whitespace.
Move output result filtering logic and assert just into the branch where
it is not obviously a no op / meeting the assertion.

Add a comment too, while we are at it.
We don't need to ask all these callers to build these single-entry maps
for us.
We can set both during construction, yay!
@Mic92 Mic92 requested a review from Copilot August 15, 2025 06:11

This comment was marked as resolved.

@Mic92 Mic92 merged commit 4e776a5 into NixOS:master Aug 15, 2025
14 checks passed
@Ericson2314 Ericson2314 deleted the simplify-derivation-goal branch August 15, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants