1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 07:22:43 +01:00

Merge pull request #13802 from obsidiansystems/post-build-hook-later

Move `runPostBuildHook` out of `DerivationBuilder`
This commit is contained in:
John Ericson 2025-08-27 15:48:05 -04:00 committed by GitHub
commit 6c8f5ef9f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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()
@ -811,6 +814,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
@ -824,7 +832,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));