Skip to content

Commit

Permalink
Merge pull request #342 from nix-community/gcroot-fixes
Browse files Browse the repository at this point in the history
Gcroot fixes
  • Loading branch information
Mic92 authored Nov 26, 2024
2 parents b29bf47 + f1e6caf commit 8f56354
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
29 changes: 16 additions & 13 deletions src/nix-eval-jobs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ auto main(int argc, char **argv) -> int {
nix::initGC();
nix::flake::initLib(nix::flakeSettings);

std::optional<nix::AutoDelete> gcRootsDir = std::nullopt;

myArgs.parseArgs(argv, argc);

/* FIXME: The build hook in conjunction with import-from-derivation is
Expand All @@ -427,8 +429,9 @@ auto main(int argc, char **argv) -> int {
}

if (myArgs.gcRootsDir.empty()) {
nix::logger->log(nix::lvlError,
"warning: `--gc-roots-dir' not specified");
nix::Path tmpDir = nix::createTempDir();
gcRootsDir.emplace(tmpDir, true);
myArgs.gcRootsDir = tmpDir;
} else {
myArgs.gcRootsDir = std::filesystem::absolute(myArgs.gcRootsDir);
}
Expand Down Expand Up @@ -528,17 +531,17 @@ auto main(int argc, char **argv) -> int {
auto newDrvPath = store->printStorePath(
nix::writeDerivation(*store, drvAggregate));

if (myArgs.gcRootsDir.empty()) {
const nix::Path root =
myArgs.gcRootsDir + "/" +
std::string(nix::baseNameOf(newDrvPath));
if (!nix::pathExists(root)) {
auto localStore = store.dynamic_pointer_cast<
nix::LocalFSStore>();
auto storePath =
localStore->parseStorePath(newDrvPath);
localStore->addPermRoot(storePath, root);
}
assert(!myArgs.gcRootsDir.empty());
const nix::Path root =
myArgs.gcRootsDir + "/" +
std::string(nix::baseNameOf(newDrvPath));

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

nix::logger->log(
Expand Down
23 changes: 11 additions & 12 deletions src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,17 @@ void worker(
/* Register the derivation as a GC root. !!! This
registers roots for jobs that we may have already
done. */
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);
}
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);
}
} else {
auto attrs = nlohmann::json::array();
Expand Down
2 changes: 2 additions & 0 deletions tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def common_test(extra_args: List[str]) -> List[Dict[str, Any]]:
assert substituted_job["attr"] == "substitutedJob"
assert substituted_job["name"].startswith("nix-")
assert substituted_job["meta"]["broken"] is False

assert len(list(Path(tempdir).iterdir())) == 3
return results


Expand Down

0 comments on commit 8f56354

Please sign in to comment.