From 572c938a55d8cae847c26f5c075fb8d7cc13623d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Jun 2025 14:52:25 +0200 Subject: [PATCH] nix flake prefetch-inputs: Keep going if an input fails --- src/nix/flake-prefetch-inputs.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/nix/flake-prefetch-inputs.cc b/src/nix/flake-prefetch-inputs.cc index fe676726c..1d4209d4d 100644 --- a/src/nix/flake-prefetch-inputs.cc +++ b/src/nix/flake-prefetch-inputs.cc @@ -2,6 +2,7 @@ #include "nix/fetchers/fetch-to-store.hh" #include "nix/util/thread-pool.hh" #include "nix/store/filetransfer.hh" +#include "nix/util/exit.hh" #include @@ -35,16 +36,23 @@ struct CmdFlakePrefetchInputs : FlakeCommand Sync state_; + std::atomic nrFailed{0}; + std::function visit; visit = [&](const Node & node) { if (!state_.lock()->done.insert(&node).second) return; if (auto lockedNode = dynamic_cast(&node)) { - Activity act(*logger, lvlInfo, actUnknown, fmt("fetching '%s'", lockedNode->lockedRef)); - auto accessor = lockedNode->lockedRef.input.getAccessor(store).first; - if (!evalSettings.lazyTrees) - fetchToStore(*store, accessor, FetchMode::Copy, lockedNode->lockedRef.input.getName()); + try { + Activity act(*logger, lvlInfo, actUnknown, fmt("fetching '%s'", lockedNode->lockedRef)); + auto accessor = lockedNode->lockedRef.input.getAccessor(store).first; + if (!evalSettings.lazyTrees) + fetchToStore(*store, accessor, FetchMode::Copy, lockedNode->lockedRef.input.getName()); + } catch (Error & e) { + printError("%s", e.what()); + nrFailed++; + } } for (auto & [inputName, input] : node.inputs) { @@ -56,6 +64,8 @@ struct CmdFlakePrefetchInputs : FlakeCommand pool.enqueue(std::bind(visit, *flake.lockFile.root)); pool.process(); + + throw Exit(nrFailed ? 1 : 0); } };