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

Port of https://github.com/nix-community/nix-eval-jobs/pull/344 #346

Merged
merged 4 commits into from
Dec 10, 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
15 changes: 7 additions & 8 deletions src/nix-eval-jobs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,29 +528,28 @@ auto main(int argc, char **argv) -> int {
drvAggregate.outputs.insert_or_assign(
"out", nix::DerivationOutput::InputAddressed{
.path = outPath});
auto newDrvPath = store->printStorePath(
nix::writeDerivation(*store, drvAggregate));
auto newDrvPath =
nix::writeDerivation(*store, drvAggregate);
auto newDrvPathS = store->printStorePath(newDrvPath);

assert(!myArgs.gcRootsDir.empty());
const nix::Path root =
myArgs.gcRootsDir + "/" +
std::string(nix::baseNameOf(newDrvPath));
std::string(nix::baseNameOf(newDrvPathS));

if (!nix::pathExists(root)) {
auto localStore =
store.dynamic_pointer_cast<nix::LocalFSStore>();
auto storePath =
localStore->parseStorePath(newDrvPath);
localStore->addPermRoot(storePath, root);
localStore->addPermRoot(newDrvPath, root);
}

nix::logger->log(
nix::lvlDebug,
nix::fmt("rewrote aggregate derivation %s -> %s",
store->printStorePath(drvPathAggregate),
newDrvPath));
newDrvPathS));

job_json["drvPath"] = newDrvPath;
job_json["drvPath"] = newDrvPathS;
job_json["outputs"]["out"] =
store->printStorePath(outPath);
job_json.erase("namedConstituents");
Expand Down
23 changes: 12 additions & 11 deletions src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,18 @@ void worker(
/* Register the derivation as a GC root. !!! This
registers roots for jobs that we may have already
done. */
assert(!args.gcRootsDir.empty());
const nix::Path root =
args.gcRootsDir + "/" +
std::string(nix::baseNameOf(drv.drvPath));
if (!nix::pathExists(root)) {
auto localStore =
state->store
.dynamic_pointer_cast<nix::LocalFSStore>();
auto storePath =
localStore->parseStorePath(drv.drvPath);
localStore->addPermRoot(storePath, root);
if (!args.gcRootsDir.empty()) {
const nix::Path root =
args.gcRootsDir + "/" +
std::string(nix::baseNameOf(drv.drvPath));
if (!nix::pathExists(root)) {
auto localStore =
state->store
.dynamic_pointer_cast<nix::LocalFSStore>();
auto storePath =
localStore->parseStorePath(drv.drvPath);
localStore->addPermRoot(storePath, root);
}
}
} else {
auto attrs = nlohmann::json::array();
Expand Down
14 changes: 14 additions & 0 deletions tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import subprocess
import os
import pytest
from pathlib import Path
from tempfile import TemporaryDirectory
Expand All @@ -12,6 +13,15 @@
BIN = PROJECT_ROOT.joinpath("build", "src", "nix-eval-jobs")


def check_gc_root(gcRootDir: str, drvPath: str):
"""
Make sure the expected GC root exists in the given dir
"""
link_name = os.path.basename(drvPath)
symlink_path = os.path.join(gcRootDir, link_name)
assert os.path.islink(symlink_path) and drvPath == os.readlink(symlink_path)


def common_test(extra_args: List[str]) -> List[Dict[str, Any]]:
with TemporaryDirectory() as tempdir:
cmd = [str(BIN), "--gc-roots-dir", tempdir, "--meta"] + extra_args
Expand Down Expand Up @@ -149,6 +159,10 @@ def absent_or_empty(f: str, d: dict) -> bool:
assert "error" not in indirect
assert "error" not in mixed

check_gc_root(tempdir, direct["drvPath"])
check_gc_root(tempdir, indirect["drvPath"])
check_gc_root(tempdir, mixed["drvPath"])


def test_constituents_error() -> None:
with TemporaryDirectory() as tempdir:
Expand Down
Loading