Skip to content

Remove useDerivation#13177

Merged
Ericson2314 merged 2 commits intoNixOS:masterfrom
obsidiansystems:less-useDerivation
May 20, 2025
Merged

Remove useDerivation#13177
Ericson2314 merged 2 commits intoNixOS:masterfrom
obsidiansystems:less-useDerivation

Conversation

@Ericson2314
Copy link
Copy Markdown
Member

@Ericson2314 Ericson2314 commented May 13, 2025

Motivation

Try to make DerivationGoal care less whether we're working from an in-memory derivation or not.

Context

It's a clean-up in its own right, but it will also help with other cleanups under the umbrella of #12628


Add 👍 to pull requests you find important.

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

@Ericson2314 Ericson2314 force-pushed the less-useDerivation branch from 52ba749 to 3c070d9 Compare May 13, 2025 21:55
Comment on lines -447 to -421
if (!useDerivation)
throw Error("some dependencies of '%s' are missing", worker.store.printStorePath(drvPath));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think the idea was that in the 0-dep case, this is more of an internal error. I think that's a small detail and it's fine to just use the other error code-path regardless?

See change originating in 1511aa9

Comment on lines 405 to +376
};

for (const auto & [inputDrvPath, inputNode] : dynamic_cast<Derivation *>(drv.get())->inputDrvs.map) {
for (const auto & [inputDrvPath, inputNode] : drv->inputDrvs.map) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Cast has been obsolete for a while now.

@Ericson2314 Ericson2314 force-pushed the less-useDerivation branch from 3c070d9 to c2141e7 Compare May 13, 2025 23:37
@Ericson2314 Ericson2314 changed the title Remove useDerivation in many places Remove useDerivation May 13, 2025
if (useDerivation) {
auto & fullDrv = *dynamic_cast<Derivation *>(drv.get());
{
auto & fullDrv = *drv;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess we can replace all uses of fullDrv by drv-> ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes we can, but I wanted to save such churn for later :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reading more, this looks like a "free bonus feature" to me also?

If you have the build closure, the "outputs to drv" map provides strictly more ways to repair the path.


/* If we're working from an in-memory derivation with no in-store
`*.drv` file, we cannot do this part. */
if (worker.store.isValidPath(drvPath))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems fishy. It makes the behaviour dependent on whether drvPath happens to exist, rather than whether we're building from an in-memory drv or not.

Copy link
Copy Markdown
Member Author

@Ericson2314 Ericson2314 May 14, 2025

Choose a reason for hiding this comment

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

That's true, but I think it's fine. Repairing is a best-effort operation where we through the kitchen sink at the problem. If we have the drv on hand, that's another tool in our toolbox.

I think you added the original conditional in 1511aa9 simply because this part wouldn't work without the file on hand, there wasn't some deeper reason for it.

Finally, I kinda doubt anyone is doing remote building (current buildDerivation code path) with bmRepair anyways :)

if (settings.buildHook.get().empty() || !worker.tryBuildHook || !useDerivation) return rpDecline;
/* This should use `worker.evalStore`, but per #13179 the build hook
doesn't work with eval store anyways. */
if (settings.buildHook.get().empty() || !worker.tryBuildHook || !worker.store.isValidPath(drvPath)) return rpDecline;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Idem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If you have the drv on hand, it's a "free bonus feature" that now the build hook works. No change in the semantics of what's trying to be accomplished.

At the same time, the only reason the build hook requires an in-store drv file is because the build hook protocol sucks (as we all agree). Once it's inlined per #5025 (Fixing #13179) in the process, this conditional goes away.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you have the drv on hand, it's a "free bonus feature" that now the build hook works.

I mean, that's the problem: something mysteriously succeeding or failing depending on whether the .drv happens to be present.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah it will be better with the build hook mechanism removed, and then no more mysterious failure/success for this one.

@Ericson2314 Ericson2314 force-pushed the less-useDerivation branch from c2141e7 to b82e21f Compare May 15, 2025 00:20
Now, each class provides the initial coroutine by value. This avoids
some sketchy virtual function stuff, and will also be further put to
good use in the next commit.
Try to make `DerivationGoal` care less whether we're working from an
in-memory derivation or not.

It's a clean-up in its own right, but it will also help with other
cleanups under the umbrella of NixOS#12628.
@Ericson2314 Ericson2314 force-pushed the less-useDerivation branch from b82e21f to 01207fd Compare May 15, 2025 17:40
@Mic92 Mic92 added this to Nix team May 18, 2025
@github-project-automation github-project-automation bot moved this to To triage in Nix team May 18, 2025
@Ericson2314 Ericson2314 merged commit a6c5d56 into NixOS:master May 20, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from To triage to Done in Nix team May 20, 2025
@Ericson2314 Ericson2314 deleted the less-useDerivation branch May 20, 2025 15:40
@roberth roberth added the backports rejected PR should not be backported (or at least not in full, or unless an overriding need arises) label Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backports rejected PR should not be backported (or at least not in full, or unless an overriding need arises)

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants