Skip to content

Commit

Permalink
drv: backport CA derivations support changes from hydra-eval-jobs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-Authored-By: Théophane Hufschmitt <[email protected]>
Co-Authored-By: Alexander Sosedkin <[email protected]>
Co-Authored-By: Andrea Ciceri <[email protected]>
Co-Authored-By: Charlotte 🦝 Delenk [email protected]>
Co-Authored-By: Sandro Jäckel <[email protected]>
  • Loading branch information
6 people authored and Mic92 committed Aug 11, 2024
1 parent 8802412 commit bc4f360
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions src/drv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

static Drv::CacheStatus
queryCacheStatus(nix::Store &store,
std::map<std::string, std::string> &outputs) {
std::map<std::string, std::optional<std::string>> &outputs) {
uint64_t downloadSize, narSize;
nix::StorePathSet willBuild, willSubstitute, unknown;

std::vector<nix::StorePathWithOutputs> 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,
Expand All @@ -58,11 +60,21 @@ Drv::Drv(std::string &attrPath, nix::EvalState &state,
nix::PackageInfo &packageInfo, MyArgs &args) {

auto localStore = state.store.dynamic_pointer_cast<nix::LocalFSStore>();
const bool hasCaDerivations =
nix::experimentalFeatureSettings.isEnabled(nix::Xp::CaDerivations);

try {
for (auto out : packageInfo.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] :
packageInfo.queryOutputs(!hasCaDerivations)) {
if (optOutputPath) {
outputs[outputName] =
localStore->printStorePath(*optOutputPath);
} else {
assert(hasCaDerivations);
outputs[outputName] = std::nullopt;
}
}
} catch (const std::exception &e) {
state
Expand Down Expand Up @@ -113,10 +125,16 @@ Drv::Drv(std::string &attrPath, nix::EvalState &state,
}

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},
{"system", drv.system},
{"drvPath", drv.drvPath},
{"outputs", drv.outputs},
{"outputs", outputsJson},
{"inputDrvs", drv.inputDrvs}};

if (drv.meta.has_value()) {
Expand Down
2 changes: 1 addition & 1 deletion src/drv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Drv {
std::string drvPath;

enum class CacheStatus { Local, Cached, NotBuilt, 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::optional<nlohmann::json> meta;

Expand Down

0 comments on commit bc4f360

Please sign in to comment.