Simplify DerivationGoal in many ways#13753
Merged
Mic92 merged 13 commits intoNixOS:masterfrom Aug 15, 2025
Merged
Conversation
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!
xokdvium
reviewed
Aug 14, 2025
Mic92
approved these changes
Aug 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Taking advantage of the splitting up of
DerivationGoalinto 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.