Add flag to enable meta

I removed meta from the output in 434376f8e1 with the intention of adding it back gated by a flag, but that never happened.

Adding meta is quite a substantial increase in output size and has some non-trivial performance impact at scale, so it's best to leave it as opt-in.
This commit is contained in:
adisbladis 2022-01-06 13:19:15 +13:00
parent 0570194d0a
commit 3268f3a6af
2 changed files with 26 additions and 15 deletions

View file

@ -34,6 +34,7 @@ struct MyArgs : MixEvalArgs, MixCommonArgs
Path releaseExpr; Path releaseExpr;
Path gcRootsDir; Path gcRootsDir;
bool flake = false; bool flake = false;
bool meta = false;
size_t nrWorkers = 1; size_t nrWorkers = 1;
size_t maxMemorySize = 4096; size_t maxMemorySize = 4096;
pureEval evalMode = evalAuto; pureEval evalMode = evalAuto;
@ -94,6 +95,12 @@ struct MyArgs : MixEvalArgs, MixCommonArgs
.handler = {&flake, true} .handler = {&flake, true}
}); });
addFlag({
.longName = "meta",
.description = "include derivation meta field in output",
.handler = {&meta, true}
});
expectArg("expr", &releaseExpr); expectArg("expr", &releaseExpr);
} }
}; };
@ -182,21 +189,24 @@ static void worker(
reply["outputs"][out.first] = out.second; reply["outputs"][out.first] = out.second;
} }
nlohmann::json meta; if (myArgs.meta) {
for (auto & name : drv->queryMetaNames()) { nlohmann::json meta;
PathSet context; for (auto & name : drv->queryMetaNames()) {
std::stringstream ss; PathSet context;
std::stringstream ss;
auto metaValue = drv->queryMeta(name); auto metaValue = drv->queryMeta(name);
// Skip non-serialisable types // Skip non-serialisable types
// TODO: Fix serialisation of derivations to store paths // TODO: Fix serialisation of derivations to store paths
if (metaValue == 0) { if (metaValue == 0) {
continue; continue;
} }
printValueAsJSON(state, true, *metaValue, noPos, ss, context); printValueAsJSON(state, true, *metaValue, noPos, ss, context);
nlohmann::json field = nlohmann::json::parse(ss.str()); nlohmann::json field = nlohmann::json::parse(ss.str());
meta[name] = field; meta[name] = field;
}
reply["meta"] = meta;
} }
/* Register the derivation as a GC root. !!! This /* Register the derivation as a GC root. !!! This

View file

@ -13,7 +13,7 @@ BIN = PROJECT_ROOT.joinpath("build", "src", "nix-eval-jobs")
def common_test(extra_args: List[str]) -> None: def common_test(extra_args: List[str]) -> None:
with TemporaryDirectory() as tempdir: with TemporaryDirectory() as tempdir:
cmd = [str(BIN), "--gc-roots-dir", tempdir] + extra_args cmd = [str(BIN), "--gc-roots-dir", tempdir, "--meta"] + extra_args
res = subprocess.run( res = subprocess.run(
cmd, cmd,
cwd=TEST_ROOT.joinpath("assets"), cwd=TEST_ROOT.joinpath("assets"),
@ -30,11 +30,12 @@ def common_test(extra_args: List[str]) -> None:
assert built_job["name"] == "job1" assert built_job["name"] == "job1"
assert built_job["outputs"]["out"].startswith("/nix/store") assert built_job["outputs"]["out"].startswith("/nix/store")
assert built_job["drvPath"].endswith(".drv") assert built_job["drvPath"].endswith(".drv")
assert built_job["meta"]['broken'] is False
substituted_job = results[1] substituted_job = results[1]
assert substituted_job["attr"] == "substitutedJob" assert substituted_job["attr"] == "substitutedJob"
assert substituted_job["name"].startswith("hello-") assert substituted_job["name"].startswith("hello-")
assert substituted_job["meta"]['broken'] is False
def test_flake() -> None: def test_flake() -> None: