From d9a46559a4a4de199c68c9b369c50ca5664ce564 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Tue, 16 Jul 2024 09:11:01 +0200 Subject: [PATCH] drv: backport CA derivations support changes from hydra-eval-jobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is not possible to query output paths for CA derivations since they're not static / known at eval time. Instead, return JSON nulls for outputs paths. This is a partial port of the following Hydra commits: - 9ba4417940ffdd0fadea43f68c61ef948a4b8d39 - 069b7775c565f5999fe33e8c3f28c7b9306039ca - fcde5908d8e51f975b883329b34d24a9f30ea4b3 By the following authors: Co-Authored-By: John Ericson Co-Authored-By: Théophane Hufschmitt Co-Authored-By: Alexander Sosedkin Co-Authored-By: Andrea Ciceri Co-Authored-By: Charlotte 🦝 Delenk Mlotte@chir.rs> Co-Authored-By: Sandro Jäckel --- src/drv.cc | 33 ++++++++++++++++++++++++++------- src/drv.hh | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/drv.cc b/src/drv.cc index 5af2dfc..dca58de 100644 --- a/src/drv.cc +++ b/src/drv.cc @@ -23,14 +23,17 @@ #include "drv.hh" #include "eval-args.hh" -static bool queryIsCached(nix::Store &store, - std::map &outputs) { +static bool +queryIsCached(nix::Store &store, + std::map> &outputs) { uint64_t downloadSize, narSize; nix::StorePathSet willBuild, willSubstitute, unknown; std::vector paths; for (auto const &[key, val] : outputs) { - paths.push_back(followLinksToStorePathWithOutputs(store, val)); + if (val) { + paths.push_back(followLinksToStorePathWithOutputs(store, *val)); + } } store.queryMissing(toDerivedPaths(paths), willBuild, willSubstitute, @@ -45,9 +48,19 @@ Drv::Drv(std::string &attrPath, nix::EvalState &state, nix::DrvInfo &drvInfo, auto localStore = state.store.dynamic_pointer_cast(); try { - for (auto out : drvInfo.queryOutputs(true)) { - if (out.second) - outputs[out.first] = localStore->printStorePath(*out.second); + // CA derivations do not have static output paths, so we have to + // defensively not query output paths in case we encounter one. + for (auto &[outputName, optOutputPath] : + drvInfo.queryOutputs(!nix::experimentalFeatureSettings.isEnabled( + nix::Xp::CaDerivations))) { + if (optOutputPath) { + outputs[outputName] = + localStore->printStorePath(*optOutputPath); + } else { + assert(nix::experimentalFeatureSettings.isEnabled( + nix::Xp::CaDerivations)); + outputs[outputName] = std::nullopt; + } } } catch (const std::exception &e) { throw nix::EvalError(state, @@ -98,10 +111,16 @@ Drv::Drv(std::string &attrPath, nix::EvalState &state, nix::DrvInfo &drvInfo, } void to_json(nlohmann::json &json, const Drv &drv) { + std::map outputsJson; + for (auto &[name, optPath] : drv.outputs) { + outputsJson[name] = + optPath ? nlohmann::json(*optPath) : nlohmann::json(nullptr); + } + json = nlohmann::json{{"name", drv.name}, {"system", drv.system}, {"drvPath", drv.drvPath}, - {"outputs", drv.outputs}, + {"outputs", outputsJson}, {"inputDrvs", drv.inputDrvs}}; if (drv.meta.has_value()) { diff --git a/src/drv.hh b/src/drv.hh index ab817c2..4cfc6a0 100644 --- a/src/drv.hh +++ b/src/drv.hh @@ -24,7 +24,7 @@ struct Drv { std::string drvPath; enum class CacheStatus { Cached, Uncached, Unknown } cacheStatus; - std::map outputs; + std::map> outputs; std::map> inputDrvs; std::optional meta;