diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index 1a4cce8f5..1d0dd3d60 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -612,7 +612,7 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a if (auto store2 = store.dynamic_pointer_cast()) { std::string symlink = drvPrefix; if (outputName != "out") symlink += "-" + outputName; - store2->addPermRoot(outputPath, absPath(symlink)); + aio.blockOn(store2->addPermRoot(outputPath, absPath(symlink))); } outPaths.push_back(outputPath); diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index a164f3aba..f8db06ef9 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -80,7 +80,7 @@ void processExpr(EvalState & state, const Strings & attrPaths, if (++rootNr > 1) rootName += "-" + std::to_string(rootNr); auto store2 = state.ctx.store.dynamic_pointer_cast(); if (store2) - drvPathS = store2->addPermRoot(drvPath, rootName); + drvPathS = state.aio.blockOn(store2->addPermRoot(drvPath, rootName)); } std::cout << fmt("%s%s\n", drvPathS, (outputName != "out" ? "!" + outputName : "")); } diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index f1ce0298e..742a2db0b 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -92,7 +92,7 @@ try { Path rootName = gcRoot; if (rootNr > 1) rootName += "-" + std::to_string(rootNr); if (i->first != "out") rootName += "-" + i->first; - retPath = store2->addPermRoot(outPath, rootName); + retPath = TRY_AWAIT(store2->addPermRoot(outPath, rootName)); } } outputs.insert(retPath); @@ -111,7 +111,7 @@ try { Path rootName = gcRoot; rootNr++; if (rootNr > 1) rootName += "-" + std::to_string(rootNr); - co_return PathSet{store2->addPermRoot(path.path, rootName)}; + co_return PathSet{TRY_AWAIT(store2->addPermRoot(path.path, rootName))}; } } co_return PathSet{store->printStorePath(path.path)}; diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index 2925fe3bd..a9ec776d2 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -782,7 +782,7 @@ ProcessLineResult NixRepl::processLine(std::string line) auto localStore = evaluator.store.dynamic_pointer_cast(); if (localStore && command == ":bl") { std::string symlink = "repl-result-" + outputName; - localStore->addPermRoot(outputPath, absPath(symlink)); + state.aio.blockOn(localStore->addPermRoot(outputPath, absPath(symlink))); logger->cout(" ./%s -> %s", symlink, evaluator.store->printStorePath(outputPath)); } else { logger->cout(" %s -> %s", outputName, evaluator.store->printStorePath(outputPath)); diff --git a/lix/libfetchers/registry.cc b/lix/libfetchers/registry.cc index 732d87421..bb6bc4338 100644 --- a/lix/libfetchers/registry.cc +++ b/lix/libfetchers/registry.cc @@ -184,8 +184,11 @@ try { ); auto storePath = downloadFile(store, path, "flake-registry.json", false).storePath; - if (auto store2 = store.dynamic_pointer_cast()) - store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json"); + if (auto store2 = store.dynamic_pointer_cast()) { + TRY_AWAIT( + store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json") + ); + } path = store->toRealPath(storePath); } diff --git a/lix/libstore/gc.cc b/lix/libstore/gc.cc index e5636a994..c8c78b5f4 100644 --- a/lix/libstore/gc.cc +++ b/lix/libstore/gc.cc @@ -51,8 +51,8 @@ void LocalStore::addIndirectRoot(const Path & path) } -Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot) -{ +kj::Promise> IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot) +try { Path gcRoot(canonPath(_gcRoot)); if (isInStore(gcRoot)) @@ -73,7 +73,9 @@ Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _g makeSymlink(gcRoot, printStorePath(storePath)); addIndirectRoot(gcRoot); - return gcRoot; + co_return gcRoot; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/indirect-root-store.hh b/lix/libstore/indirect-root-store.hh index 9bfa1f68b..26b023efd 100644 --- a/lix/libstore/indirect-root-store.hh +++ b/lix/libstore/indirect-root-store.hh @@ -31,7 +31,8 @@ struct IndirectRootStore : public virtual LocalFSStore * The implementation of this method is concrete, but it delegates * to `addIndirectRoot()` which is abstract. */ - Path addPermRoot(const StorePath & storePath, const Path & gcRoot) override final; + kj::Promise> + addPermRoot(const StorePath & storePath, const Path & gcRoot) override final; /** * Add an indirect root, which is a weak reference to the diff --git a/lix/libstore/local-fs-store.hh b/lix/libstore/local-fs-store.hh index b9ad4480b..d31264b47 100644 --- a/lix/libstore/local-fs-store.hh +++ b/lix/libstore/local-fs-store.hh @@ -59,7 +59,8 @@ public: * How the permanent GC root corresponding to this symlink is * managed is implementation-specific. */ - virtual Path addPermRoot(const StorePath & storePath, const Path & gcRoot) = 0; + virtual kj::Promise> + addPermRoot(const StorePath & storePath, const Path & gcRoot) = 0; virtual Path getRealStoreDir() { return config().realStoreDir; } diff --git a/lix/libstore/profiles.cc b/lix/libstore/profiles.cc index 675b46bbf..f4f74b6d3 100644 --- a/lix/libstore/profiles.cc +++ b/lix/libstore/profiles.cc @@ -1,5 +1,6 @@ #include "lix/libstore/profiles.hh" #include "lix/libstore/local-fs-store.hh" +#include "lix/libutil/async.hh" #include "lix/libutil/users.hh" #include "lix/libutil/strings.hh" @@ -102,7 +103,7 @@ try { view). If we didn't do it this way, the GC might remove the user environment etc. we've just built. */ Path generation = makeName(profile, num + 1); - store.addPermRoot(outPath, generation); + TRY_AWAIT(store.addPermRoot(outPath, generation)); co_return generation; } catch (...) { diff --git a/lix/nix/build.cc b/lix/nix/build.cc index 384369e56..7602f719f 100644 --- a/lix/nix/build.cc +++ b/lix/nix/build.cc @@ -3,6 +3,7 @@ #include "lix/libmain/shared.hh" #include "lix/libstore/store-api.hh" #include "lix/libstore/local-fs-store.hh" +#include "lix/libutil/async.hh" #include @@ -42,7 +43,12 @@ static nlohmann::json builtPathsWithResultToJSON(const std::vector& buildables, LocalFSStore& store2) +static void createOutLinks( + AsyncIoRoot & aio, + const Path & outLink, + const std::vector & buildables, + LocalFSStore & store2 +) { for (const auto & [_i, buildable] : enumerate(buildables)) { auto i = _i; @@ -50,14 +56,14 @@ static void createOutLinks(const Path& outLink, const std::vector()) - createOutLinks(outLink, buildables, *store2); + createOutLinks(aio(), outLink, buildables, *store2); if (printOutputPaths) { logger->pause(); diff --git a/lix/nix/bundle.cc b/lix/nix/bundle.cc index 79bcc7112..261cd8416 100644 --- a/lix/nix/bundle.cc +++ b/lix/nix/bundle.cc @@ -125,7 +125,9 @@ struct CmdBundle : InstallableCommand } // TODO: will crash if not a localFSStore? - store.dynamic_pointer_cast()->addPermRoot(outPath, absPath(*outLink)); + aio().blockOn( + store.dynamic_pointer_cast()->addPermRoot(outPath, absPath(*outLink)) + ); } };