drv: backport CA derivations support changes from hydra-eval-jobs #10

Merged
delroth merged 1 commit from delroth/nix-eval-jobs:ca-derivations into main 2024-07-17 05:56:39 +00:00
2 changed files with 27 additions and 8 deletions

View file

@ -23,14 +23,17 @@
#include "drv.hh" #include "drv.hh"
#include "eval-args.hh" #include "eval-args.hh"
static bool queryIsCached(nix::Store &store, static bool
std::map<std::string, std::string> &outputs) { queryIsCached(nix::Store &store,
std::map<std::string, std::optional<std::string>> &outputs) {
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
nix::StorePathSet willBuild, willSubstitute, unknown; nix::StorePathSet willBuild, willSubstitute, unknown;
std::vector<nix::StorePathWithOutputs> paths; std::vector<nix::StorePathWithOutputs> paths;
for (auto const &[key, val] : outputs) { 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, 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<nix::LocalFSStore>(); auto localStore = state.store.dynamic_pointer_cast<nix::LocalFSStore>();
try { try {
for (auto out : drvInfo.queryOutputs(true)) { // CA derivations do not have static output paths, so we have to
if (out.second) // defensively not query output paths in case we encounter one.
outputs[out.first] = localStore->printStorePath(*out.second); 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) { } catch (const std::exception &e) {
throw nix::EvalError(state, 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) { void to_json(nlohmann::json &json, const Drv &drv) {
std::map<std::string, nlohmann::json> outputsJson;
for (auto &[name, optPath] : drv.outputs) {
outputsJson[name] =
optPath ? nlohmann::json(*optPath) : nlohmann::json(nullptr);
}
json = nlohmann::json{{"name", drv.name}, json = nlohmann::json{{"name", drv.name},
{"system", drv.system}, {"system", drv.system},
{"drvPath", drv.drvPath}, {"drvPath", drv.drvPath},
{"outputs", drv.outputs}, {"outputs", outputsJson},
{"inputDrvs", drv.inputDrvs}}; {"inputDrvs", drv.inputDrvs}};
if (drv.meta.has_value()) { if (drv.meta.has_value()) {

View file

@ -24,7 +24,7 @@ struct Drv {
std::string drvPath; std::string drvPath;
enum class CacheStatus { Cached, Uncached, Unknown } cacheStatus; enum class CacheStatus { Cached, Uncached, Unknown } cacheStatus;
std::map<std::string, std::string> outputs; std::map<std::string, std::optional<std::string>> outputs;
std::map<std::string, std::set<std::string>> inputDrvs; std::map<std::string, std::set<std::string>> inputDrvs;
std::optional<nlohmann::json> meta; std::optional<nlohmann::json> meta;