1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

Move runPostBuildHook out of DerivationBuilder

It is suppposed to be "post build" not "during the build" after all. Its
location now matches that for the hook case (see elsewhere in
`DerivationdBuildingGoal`).

It was in a try-catch before, and now it isn't, but I believe that it is
impossible for it to throw `BuildError`, which is sufficient for this
code motion to be correct.
This commit is contained in:
John Ericson 2025-08-20 19:11:28 -04:00
parent c1e2396d58
commit 0250d50df3
4 changed files with 9 additions and 12 deletions

View file

@ -148,6 +148,9 @@ std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & dr
return msg; return msg;
} }
static void runPostBuildHook(
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
/* At least one of the output paths could not be /* At least one of the output paths could not be
produced using a substitute. So we have to build instead. */ produced using a substitute. So we have to build instead. */
Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution() Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
@ -810,6 +813,11 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
outputLocks.unlock(); outputLocks.unlock();
co_return done(std::move(ste->first), {}, std::move(ste->second)); co_return done(std::move(ste->first), {}, std::move(ste->second));
} else if (auto * builtOutputs = std::get_if<1>(&res)) { } else if (auto * builtOutputs = std::get_if<1>(&res)) {
StorePathSet outputPaths;
for (auto & [_, output] : *builtOutputs)
outputPaths.insert(output.outPath);
runPostBuildHook(worker.store, *logger, drvPath, outputPaths);
/* It is now safe to delete the lock files, since all future /* It is now safe to delete the lock files, since all future
lockers will see that the output paths are valid; they will lockers will see that the output paths are valid; they will
not create new lock files with the same names as the old not create new lock files with the same names as the old
@ -823,7 +831,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
#endif #endif
} }
void runPostBuildHook( static void runPostBuildHook(
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths) const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths)
{ {
auto hook = settings.postBuildHook; auto hook = settings.postBuildHook;

View file

@ -49,9 +49,6 @@ struct InitialOutput
std::optional<InitialOutputStatus> known; std::optional<InitialOutputStatus> known;
}; };
void runPostBuildHook(
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
/** /**
* Format the known outputs of a derivation for use in error messages. * Format the known outputs of a derivation for use in error messages.
*/ */

View file

@ -14,9 +14,6 @@ namespace nix {
using std::map; using std::map;
/** Used internally */
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
/** /**
* A goal for realising a single output of a derivation. Various sorts of * A goal for realising a single output of a derivation. Various sorts of
* fetching (which will be done by other goal types) is tried, and if none of * fetching (which will be done by other goal types) is tried, and if none of

View file

@ -506,11 +506,6 @@ std::variant<std::pair<BuildResult::Status, Error>, SingleDrvOutputs> Derivation
being valid. */ being valid. */
auto builtOutputs = registerOutputs(); auto builtOutputs = registerOutputs();
StorePathSet outputPaths;
for (auto & [_, output] : builtOutputs)
outputPaths.insert(output.outPath);
runPostBuildHook(store, *logger, drvPath, outputPaths);
/* Delete unused redirected outputs (when doing hash rewriting). */ /* Delete unused redirected outputs (when doing hash rewriting). */
for (auto & i : redirectedOutputs) for (auto & i : redirectedOutputs)
deletePath(store.Store::toRealPath(i.second)); deletePath(store.Store::toRealPath(i.second));