Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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