Skip to content

Dedup some derivation initialization logic, and test#14560

Merged
Ericson2314 merged 2 commits intoNixOS:masterfrom
obsidiansystems:fill-in-outputs
Nov 24, 2025
Merged

Dedup some derivation initialization logic, and test#14560
Ericson2314 merged 2 commits intoNixOS:masterfrom
obsidiansystems:fill-in-outputs

Conversation

@Ericson2314
Copy link
Member

Motivation

nix derivation add, and its C API counterpart, now works a bit closer to builtins.derivation in that they don't require the user to fill-in input addressed paths correctly ahead of time.

The logic for this is carefully deduplicated, between all 3 entry points, and also between the existing checkInvariants function. There are some more functional tests, and there are also many more unit tests.

Context


Add 👍 to pull requests you find important.

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

@github-actions github-actions bot added new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority c api Nix as a C library with a stable interface labels Nov 13, 2025
*
* @param store The store to use for validation
*/
void checkInvariants(Store & store) const;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this version needed now?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used in parseJsonAndValidate, we validate the derivation before we compute its drvPath now. The drvPath was just used for error messages, but it we can write a better error message --- since we just computed the drv path, it won't mean anything to the human reading the error anyways where ("derivation from JSON" or similar will)


# If we remove the input addressed to make it a deferred derivation, we
# still get the same result because Nix will see that need not be
# deferred and fill in the right input address for us.
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a good thing? From reading checkInvariants, it looks like this is new behavior.

Copy link
Member Author

@Ericson2314 Ericson2314 Nov 17, 2025

Choose a reason for hiding this comment

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

checkInvariants doesn't do this, but fillInOutputPaths does. It is new behavior in the nix derivation add code path (which is unstable), but not new behavior in the builtins.derivation code path.

return;
}
auto & value = j->second;
if (value == "") {
Copy link
Member

Choose a reason for hiding this comment

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

Can this actually happen - I did not see it in the old code?

Copy link
Member Author

@Ericson2314 Ericson2314 Nov 17, 2025

Choose a reason for hiding this comment

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

The user-submitted JSON is arbitrary data, so yes it can happen. It also does happen in the builtins.derivationStrict code path already.

@Ericson2314 Ericson2314 force-pushed the fill-in-outputs branch 2 times, most recently from 8149291 to 745c307 Compare November 17, 2025 19:50
@Ericson2314 Ericson2314 force-pushed the fill-in-outputs branch 7 times, most recently from 7f3f8f1 to 79cf901 Compare November 19, 2025 19:54
Ericson2314 and others added 2 commits November 20, 2025 00:49
These do a read/write test in the middles of some computation. They are
an imperative way to test intermediate values rather than functionally
testing end outputs.
`nix derivation add`, and its C API counterpart, now works a bit closer
to `builtins.derivation` in that they don't require the user to fill-in
input addressed paths correctly ahead of time.

The logic for this is carefully deduplicated, between all 3 entry
points, and also between the existing `checkInvariants` function. There
are some more functional tests, and there are also many more unit tests.

Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
Co-authored-by: edef <edef@edef.eu>
auto drv = static_cast<Derivation>(json);
auto drv = Derivation::parseJsonAndValidate(*store, json);

auto drvPath = writeDerivation(*store, drv, NoRepair, /* read only */ dryRun);
Copy link
Member

Choose a reason for hiding this comment

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

why do we actually have writeDerivation twice here?

@Ericson2314 Ericson2314 added this pull request to the merge queue Nov 24, 2025
Merged via the queue into NixOS:master with commit 3ba51bf Nov 24, 2025
16 checks passed
@Ericson2314 Ericson2314 deleted the fill-in-outputs branch November 24, 2025 21:58
Mic92 added a commit to Mic92/nix-1 that referenced this pull request Dec 8, 2025
…utputs"

This reverts commit 3ba51bf, reversing
changes made to 0c786f3.
Mic92 added a commit to Mic92/nix-1 that referenced this pull request Dec 8, 2025
…utputs"

This reverts commit 3ba51bf, reversing
changes made to 0c786f3.
@edolstra edolstra mentioned this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants