Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/libexpr-c/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Sto
return unsafe_new_with_self<nix_eval_state_builder>([&](auto * self) {
return nix_eval_state_builder{
.store = nix::ref<nix::Store>(store->ptr),
.asyncPathWriter = nix::ref<nix::AsyncPathWriter>(store->asyncPathWriter),
.settings = nix::EvalSettings{/* &bool */ self->readOnlyMode},
.fetchSettings = nix::fetchers::Settings{},
.readOnlyMode = true,
Expand Down Expand Up @@ -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),
};
});
}
Expand Down
1 change: 1 addition & 0 deletions src/libexpr-c/nix_api_expr_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {
struct nix_eval_state_builder
{
nix::ref<nix::Store> store;
nix::ref<nix::AsyncPathWriter> asyncPathWriter;
nix::EvalSettings settings;
nix::fetchers::Settings fetchSettings;
nix::LookupPath lookupPath;
Expand Down
5 changes: 3 additions & 2 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ EvalState::EvalState(
ref<Store> store,
const fetchers::Settings & fetchSettings,
const EvalSettings & settings,
std::shared_ptr<Store> buildStore)
std::shared_ptr<Store> buildStore,
std::shared_ptr<AsyncPathWriter> asyncPathWriter)
: fetchSettings{fetchSettings}
, settings{settings}
, symbols(StaticEvalSymbols::staticSymbolTable())
Expand Down Expand Up @@ -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<decltype(srcToStore)::element_type>())
, importResolutionCache(make_ref<decltype(importResolutionCache)::element_type>())
, fileEvalCache(make_ref<decltype(fileEvalCache)::element_type>())
Expand Down
14 changes: 8 additions & 6 deletions src/libexpr/include/nix/expr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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> store,
const fetchers::Settings & fetchSettings,
const EvalSettings & settings,
std::shared_ptr<Store> buildStore = nullptr);
std::shared_ptr<Store> buildStore = nullptr,
std::shared_ptr<AsyncPathWriter> asyncPathWriter = nullptr);
~EvalState();

/**
Expand Down
20 changes: 15 additions & 5 deletions src/libstore-c/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/libstore-c/nix_api_store_internal.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#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"

extern "C" {

struct Store
{
nix::ref<nix::AsyncPathWriter> asyncPathWriter;
nix::ref<nix::Store> ptr;
};

Expand Down