diff --git a/src/libexpr-c/nix_api_expr.cc b/src/libexpr-c/nix_api_expr.cc index bfbd0a9c361..28b1c328313 100644 --- a/src/libexpr-c/nix_api_expr.cc +++ b/src/libexpr-c/nix_api_expr.cc @@ -137,6 +137,7 @@ nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Sto return unsafe_new_with_self([&](auto * self) { return nix_eval_state_builder{ .store = nix::ref(store->ptr), + .asyncPathWriter = nix::ref(store->asyncPathWriter), .settings = nix::EvalSettings{/* &bool */ self->readOnlyMode}, .fetchSettings = nix::fetchers::Settings{}, .readOnlyMode = true, @@ -190,7 +191,13 @@ EvalState * nix_eval_state_build(nix_c_context * context, nix_eval_state_builder return EvalState{ .fetchSettings = std::move(builder->fetchSettings), .settings = std::move(builder->settings), - .state = nix::EvalState(builder->lookupPath, builder->store, self->fetchSettings, self->settings), + .state = nix::EvalState( + builder->lookupPath, + builder->store, + self->fetchSettings, + self->settings, + nullptr, + builder->asyncPathWriter), }; }); } diff --git a/src/libexpr-c/nix_api_expr_internal.h b/src/libexpr-c/nix_api_expr_internal.h index 07c7a2194df..c3fd8631209 100644 --- a/src/libexpr-c/nix_api_expr_internal.h +++ b/src/libexpr-c/nix_api_expr_internal.h @@ -13,6 +13,7 @@ extern "C" { struct nix_eval_state_builder { nix::ref store; + nix::ref asyncPathWriter; nix::EvalSettings settings; nix::fetchers::Settings fetchSettings; nix::LookupPath lookupPath; diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 46393b79c5e..9aff0c1b61f 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -262,7 +262,8 @@ EvalState::EvalState( ref store, const fetchers::Settings & fetchSettings, const EvalSettings & settings, - std::shared_ptr buildStore) + std::shared_ptr buildStore, + std::shared_ptr asyncPathWriter) : fetchSettings{fetchSettings} , settings{settings} , symbols(StaticEvalSymbols::staticSymbolTable()) @@ -325,7 +326,7 @@ EvalState::EvalState( , debugRepl(nullptr) , debugStop(false) , trylevel(0) - , asyncPathWriter(AsyncPathWriter::make(store)) + , asyncPathWriter(asyncPathWriter ? asyncPathWriter : AsyncPathWriter::make(store)) , srcToStore(make_ref()) , importResolutionCache(make_ref()) , fileEvalCache(make_ref()) diff --git a/src/libexpr/include/nix/expr/eval.hh b/src/libexpr/include/nix/expr/eval.hh index 70bc5f6fbff..61837542ac4 100644 --- a/src/libexpr/include/nix/expr/eval.hh +++ b/src/libexpr/include/nix/expr/eval.hh @@ -516,18 +516,20 @@ private: public: /** - * @param lookupPath Only used during construction. - * @param store The store to use for instantiation - * @param fetchSettings Must outlive the lifetime of this EvalState! - * @param settings Must outlive the lifetime of this EvalState! - * @param buildStore The store to use for builds ("import from derivation", C API `nix_string_realise`) + * @param lookupPath Only used during construction. + * @param store The store to use for instantiation + * @param fetchSettings Must outlive the lifetime of this EvalState! + * @param settings Must outlive the lifetime of this EvalState! + * @param buildStore The store to use for builds ("import from derivation", C API `nix_string_realise`) + * @param asyncPathWriter The async path writer to use */ EvalState( const LookupPath & lookupPath, ref store, const fetchers::Settings & fetchSettings, const EvalSettings & settings, - std::shared_ptr buildStore = nullptr); + std::shared_ptr buildStore = nullptr, + std::shared_ptr asyncPathWriter = nullptr); ~EvalState(); /** diff --git a/src/libstore-c/nix_api_store.cc b/src/libstore-c/nix_api_store.cc index 80fcf10cb0d..8c63be0f992 100644 --- a/src/libstore-c/nix_api_store.cc +++ b/src/libstore-c/nix_api_store.cc @@ -44,17 +44,26 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char *** try { std::string uri_str = uri ? uri : ""; - if (uri_str.empty()) - return new Store{nix::openStore()}; + if (uri_str.empty()) { + auto store = nix::openStore(); + auto asyncPathWriter = nix::AsyncPathWriter::make(store); + return new Store{asyncPathWriter, store}; + } - if (!params) - return new Store{nix::openStore(uri_str)}; + if (!params) { + auto store = nix::openStore(uri_str); + auto asyncPathWriter = nix::AsyncPathWriter::make(store); + return new Store{asyncPathWriter, store}; + } nix::Store::Config::Params params_map; for (size_t i = 0; params[i] != nullptr; i++) { params_map[params[i][0]] = params[i][1]; } - return new Store{nix::openStore(uri_str, params_map)}; + + auto store = nix::openStore(uri_str, params_map); + auto asyncPathWriter = nix::AsyncPathWriter::make(store); + return new Store{asyncPathWriter, store}; } NIXC_CATCH_ERRS_NULL } @@ -127,6 +136,7 @@ StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const c context->last_err_code = NIX_OK; try { nix::StorePath s = store->ptr->parseStorePath(path); + store->asyncPathWriter->waitForPath(s); return new StorePath{std::move(s)}; } NIXC_CATCH_ERRS_NULL diff --git a/src/libstore-c/nix_api_store_internal.h b/src/libstore-c/nix_api_store_internal.h index 0199628da8a..44757c42518 100644 --- a/src/libstore-c/nix_api_store_internal.h +++ b/src/libstore-c/nix_api_store_internal.h @@ -1,5 +1,6 @@ #ifndef NIX_API_STORE_INTERNAL_H #define NIX_API_STORE_INTERNAL_H +#include "nix/store/async-path-writer.hh" #include "nix/store/store-api.hh" #include "nix/store/derivations.hh" @@ -7,6 +8,7 @@ extern "C" { struct Store { + nix::ref asyncPathWriter; nix::ref ptr; };