From bdd6bd5e38d3bdba5f1fd0a1fd5c7184427456d3 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Tue, 9 Dec 2025 23:17:10 +0100 Subject: [PATCH] libcmd/repl: factor out `buildWithProgressBar` This logic is used in the various build-related REPL commands and is factored out to make it easier to write the handlers for each build-related REPL commands. Change-Id: Iaa18df489db75495b12924e9a76b3fff1975eb64 Signed-off-by: Raito Bezarius --- lix/libcmd/repl.cc | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index b92e1ea14..840bd93ed 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -148,6 +148,11 @@ struct NixRepl * to a derivation, or evaluates to an invalid derivation. */ StorePath getDerivationPath(Value & v); + /** + * Build a path and show a progress bar for it. + */ + Derivation buildWithProgressBar(const StorePath & drvPath); + ProcessLineResult processLine(std::string line); bool inDebugger() const @@ -496,6 +501,25 @@ StorePath NixRepl::getDerivationPath(Value & v) { return *drvPath; } +Derivation NixRepl::buildWithProgressBar(const StorePath & drvPath) +{ + // TODO: this only shows a progress bar for explicitly initiated builds, + // not eval-time fetching or builds performed for IFD. + // But we can't just show it everywhere, since that would erase partial output from evaluation. + logger->resetProgress(); + logger->resume(); + Finally stopLogger([&]() { logger->pause(); }); + state.aio.blockOn(evaluator.store->buildPaths({ + DerivedPath::Built{ + .drvPath = makeConstantStorePath(drvPath), + .outputs = OutputsSpec::All{}, + }, + })); + auto drv = state.aio.blockOn(evaluator.store->readDerivation(drvPath)); + + return drv; +} + void NixRepl::loadDebugTraceEnv(const DebugTrace & dt) { initEnv(); @@ -758,22 +782,7 @@ ProcessLineResult NixRepl::processLine(std::string line) Path drvPathRaw = evaluator.store->printStorePath(drvPath); if (command == ":b" || command == ":bl") { - // TODO: this only shows a progress bar for explicitly initiated builds, - // not eval-time fetching or builds performed for IFD. - // But we can't just show it everywhere, since that would erase partial output from evaluation. - logger->resetProgress(); - logger->resume(); - Finally stopLogger([&]() { - logger->pause(); - }); - - state.aio.blockOn(evaluator.store->buildPaths({ - DerivedPath::Built { - .drvPath = makeConstantStorePath(drvPath), - .outputs = OutputsSpec::All { }, - }, - })); - auto drv = state.aio.blockOn(evaluator.store->readDerivation(drvPath)); + auto drv = buildWithProgressBar(drvPath); logger->cout("\nThis derivation produced the following outputs:"); for (auto & [outputName, outputPath] : state.aio.blockOn(evaluator.store->queryDerivationOutputMap(drvPath)))