Skip to content

Comments

Way more RAII for DerivationBuildingGoal#14788

Merged
Ericson2314 merged 14 commits intomasterfrom
coroutine-child-output
Jan 11, 2026
Merged

Way more RAII for DerivationBuildingGoal#14788
Ericson2314 merged 14 commits intomasterfrom
coroutine-child-output

Conversation

@Ericson2314
Copy link
Member

Motivation

This is important for making this code possible to maintain and understand.

Context

Please review each commit individually.


Add 👍 to pull requests you find important.

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

* Line buffering and log tracking for build output.
*
* This class handles:
* - Owning the build Activity for logging
Copy link
Member

Choose a reason for hiding this comment

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

I would expect the build Activity to be broader than just the builder child process which this class seems to focus on (see eg doc for operator()). We also have things like pre and post build hooks, or the built-in reference checks that are part of the broader process of building.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think at the moment it is just using the public fiels on this for those. I don't really love that, but I think it's still a step in the right direction.

@Ericson2314 Ericson2314 force-pushed the coroutine-child-output branch 2 times, most recently from d324c7d to 071d153 Compare December 18, 2025 05:09
@Ericson2314 Ericson2314 mentioned this pull request Dec 18, 2025
This will allow for making `hook` and `builder` local variables.
Also remove uneeded arguments from `processChildOutput`.
This gets some trickier pure logic out of `DerivationBuilderGoal`.
Separate state for each loop.
Now it does more, using the logging.hh functionality as needed.
It is weird that `LogFile` and `BuildLog` are basically unrelated, but
the does currently reflect the logic that exists.
There was a bunch of logic in there which was, effectively, using the
build hook, rather than deciding *whether* to use the build hook. We
want it to only be the latter.
These are immutable parameters, not state, set in the constructor.
This makes the logic much easier to follow. Unlike before, the use of
separate functions is not making us pass a gazillion arguments or use
the crutch of class variables.
Comment on lines +178 to +179
LogFile(Store & store, const StorePath & drvPath);
~LogFile();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe explicit rule of 5 here would be nice?

Suggested change
LogFile(Store & store, const StorePath & drvPath);
~LogFile();
LogFile(Store & store, const StorePath & drvPath);
LogFile(const LogFile &) = delete;
LogFile(LogFile &&) = default;
LogFile &operator=(const LogFile &) = delete;
LogFile &operator=(LogFile &&) = default;
~LogFile();

If it is even supposed to be movable. If not, move constructors can also be deleted.

Comment on lines +634 to +636
auto openLogFile = [&]() { logFile = std::make_unique<LogFile>(worker.store, drvPath); };

auto closeLogFile = [&]() { logFile.reset(); };
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit apprehensive about capturing by reference here due to lifetime semantics with coroutines.

Copy link
Contributor

Choose a reason for hiding this comment

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

But probably ok since those variable live on the outer coroutine frame.

Copy link
Member Author

@Ericson2314 Ericson2314 Jan 11, 2026

Choose a reason for hiding this comment

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

Yeah I think it is OK for that reason --- especially now that builder is a local variable too.

* The derivation stored at drvPath.
*/
std::unique_ptr<Derivation> drv;
const std::unique_ptr<Derivation> drv;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this work?

Suggested change
const std::unique_ptr<Derivation> drv;
const std::unique_ptr<const Derivation> drv;

@Ericson2314 Ericson2314 added this pull request to the merge queue Jan 11, 2026
Merged via the queue into master with commit 1608228 Jan 11, 2026
18 checks passed
@Ericson2314 Ericson2314 deleted the coroutine-child-output branch January 11, 2026 01:01
JustAGuyTryingHisBest pushed a commit to JustAGuyTryingHisBest/nix that referenced this pull request Jan 12, 2026
Way more RAII for `DerivationBuildingGoal`
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.

3 participants