Skip to content
Draft
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
11 changes: 6 additions & 5 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "nix/cmd/command.hh"
#include "nix/cmd/legacy.hh"
#include "nix/cmd/markdown.hh"
#include "nix/main/shared.hh"
#include "nix/store/store-open.hh"
#include "nix/store/local-fs-store.hh"
#include "nix/store/derivations.hh"
Expand Down Expand Up @@ -74,7 +75,7 @@ ref<Store> StoreCommand::getStore()

ref<Store> StoreCommand::createStore()
{
return openStore();
return openStore(settings);
}

void StoreCommand::run()
Expand All @@ -101,15 +102,15 @@ CopyCommand::CopyCommand()

ref<Store> CopyCommand::createStore()
{
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
return srcUri.empty() ? StoreCommand::createStore() : openStore(settings, srcUri);
}

ref<Store> CopyCommand::getDstStore()
{
if (srcUri.empty() && dstUri.empty())
throw UsageError("you must pass '--from' and/or '--to'");

return dstUri.empty() ? openStore() : openStore(dstUri);
return dstUri.empty() ? openStore(settings) : openStore(settings, dstUri);
}

EvalCommand::EvalCommand()
Expand All @@ -131,7 +132,7 @@ EvalCommand::~EvalCommand()
ref<Store> EvalCommand::getEvalStore()
{
if (!evalStore)
evalStore = evalStoreUrl ? openStore(*evalStoreUrl) : getStore();
evalStore = evalStoreUrl ? openStore(settings, *evalStoreUrl) : getStore();
return ref<Store>(evalStore);
}

Expand Down Expand Up @@ -297,7 +298,7 @@ void MixProfile::updateProfile(const BuiltPaths & buildables)

MixDefaultProfile::MixDefaultProfile()
{
profile = getDefaultProfile().string();
profile = getDefaultProfile(settings).string();
}

MixEnvironment::MixEnvironment()
Expand Down
6 changes: 3 additions & 3 deletions src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

namespace nix {

fetchers::Settings fetchSettings;
fetchers::Settings fetchSettings{settings};

static GlobalConfig::Register rFetchSettings(&fetchSettings);

EvalSettings evalSettings{
settings.readOnlyMode,
settings,
{
{
"flake",
Expand Down Expand Up @@ -135,7 +135,7 @@ MixEvalArgs::MixEvalArgs()
fetchers::overrideRegistry(from.input, to.input, extraAttrs);
}},
.completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
completeFlakeRef(completions, openStore(), prefix);
completeFlakeRef(completions, openStore(settings), prefix);
}},
});

Expand Down
1 change: 0 additions & 1 deletion src/libcmd/include/nix/cmd/installable-attr-path.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
///@file

#include "nix/store/globals.hh"
#include "nix/cmd/installable-value.hh"
#include "nix/store/outputs-spec.hh"
#include "nix/cmd/command.hh"
Expand Down
4 changes: 2 additions & 2 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
} else if (command == ":log") {
settings.readOnlyMode = true;
Finally roModeReset([&]() { settings.readOnlyMode = false; });
auto subs = getDefaultSubstituters();
auto subs = getDefaultSubstituters(settings);

subs.push_front(state->store);

Expand Down Expand Up @@ -919,7 +919,7 @@ ReplExitStatus AbstractNixRepl::runSimple(ref<EvalState> evalState, const ValMap
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete)
auto repl = std::make_unique<NixRepl>(
lookupPath,
openStore(),
openStore(settings),
evalState,
getValues,
/*runNix=*/nullptr);
Expand Down
8 changes: 3 additions & 5 deletions src/libexpr-c/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ 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),
.settings = nix::EvalSettings{/* &bool */ self->readOnlyMode},
.fetchSettings = nix::fetchers::Settings{},
.readOnlyMode = true,
.settings = nix::EvalSettings{cStoreSettings},
.fetchSettings = nix::fetchers::Settings{cStoreSettings},
};
});
}
Expand All @@ -153,8 +152,7 @@ nix_err nix_eval_state_builder_load(nix_c_context * context, nix_eval_state_buil
if (context)
context->last_err_code = NIX_OK;
try {
// TODO: load in one go?
builder->settings.readOnlyMode = nix::settings.readOnlyMode;
loadConfFile(cStoreSettings);
loadConfFile(builder->settings);
loadConfFile(builder->fetchSettings);
}
Expand Down
2 changes: 0 additions & 2 deletions src/libexpr-c/nix_api_expr_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ struct nix_eval_state_builder
nix::EvalSettings settings;
nix::fetchers::Settings fetchSettings;
nix::LookupPath lookupPath;
// TODO: make an EvalSettings setting own this instead?
bool readOnlyMode;
};

struct EvalState
Expand Down
18 changes: 9 additions & 9 deletions src/libexpr-test-support/include/nix/expr/tests/libexpr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ public:
}

protected:
LibExprTest(ref<Store> store, auto && makeEvalSettings)
: LibStoreTest()
, evalSettings(makeEvalSettings(readOnlyMode))
LibExprTest(auto && makeEvalSettings, auto &&... args)
: LibStoreTest(args...)
, evalSettings(makeEvalSettings(settings))
, state({}, store, fetchSettings, evalSettings, nullptr)
{
}

LibExprTest()
: LibExprTest(openStore("dummy://"), [](bool & readOnlyMode) {
EvalSettings settings{readOnlyMode};
settings.nixPath = {};
return settings;
: LibExprTest([](Settings & settings) {
EvalSettings evalSettings{settings};
evalSettings.nixPath = {};
return evalSettings;
})
{
}
Expand Down Expand Up @@ -66,8 +66,8 @@ protected:
}

bool readOnlyMode = true;
fetchers::Settings fetchSettings{};
EvalSettings evalSettings{readOnlyMode};
fetchers::Settings fetchSettings{settings};
EvalSettings evalSettings{settings};
EvalState state;
};

Expand Down
15 changes: 9 additions & 6 deletions src/libexpr-tests/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ class PureEvalTest : public LibExprTest
{
public:
PureEvalTest()
: LibExprTest(openStore("dummy://", {{"read-only", "false"}}), [](bool & readOnlyMode) {
EvalSettings settings{readOnlyMode};
settings.pureEval = true;
settings.restrictEval = true;
return settings;
})
: LibExprTest{
[](auto & settings) {
EvalSettings evalSettings{settings};
evalSettings.pureEval = true;
evalSettings.restrictEval = true;
return evalSettings;
},
[](auto & settings) { return openStore(settings, "dummy://", {{"read-only", "false"}}); },
}
{
}
};
Expand Down
14 changes: 8 additions & 6 deletions src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct AttrDb

SymbolTable & symbols;

AttrDb(const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
AttrDb(bool useSQLiteWAL, const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
: cfg(cfg)
, _state(std::make_unique<Sync<State>>())
, symbols(symbols)
Expand All @@ -75,7 +75,7 @@ struct AttrDb

auto dbPath = cacheDir / (fingerprint.to_string(HashFormat::Base16, false) + ".sqlite");

state->db = SQLite(dbPath);
state->db = SQLite(dbPath, {.useWAL = useSQLiteWAL});
state->db.isCache();
state->db.exec(schema);

Expand Down Expand Up @@ -287,10 +287,11 @@ struct AttrDb
}
};

static std::shared_ptr<AttrDb> makeAttrDb(const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
static std::shared_ptr<AttrDb>
makeAttrDb(bool useSQLiteWAL, const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
{
try {
return std::make_shared<AttrDb>(cfg, fingerprint, symbols);
return std::make_shared<AttrDb>(useSQLiteWAL, cfg, fingerprint, symbols);
} catch (SQLiteError &) {
ignoreExceptionExceptInterrupt();
return nullptr;
Expand All @@ -299,7 +300,8 @@ static std::shared_ptr<AttrDb> makeAttrDb(const StoreDirConfig & cfg, const Hash

EvalCache::EvalCache(
std::optional<std::reference_wrapper<const Hash>> useCache, EvalState & state, RootLoader rootLoader)
: db(useCache ? makeAttrDb(*state.store, *useCache, state.symbols) : nullptr)
: db(useCache ? makeAttrDb(state.store->config.settings.useSQLiteWAL, *state.store, *useCache, state.symbols)
: nullptr)
, state(state)
, rootLoader(rootLoader)
{
Expand Down Expand Up @@ -707,7 +709,7 @@ StorePath AttrCursor::forceDerivation()
auto aDrvPath = getAttr(root->state.s.drvPath);
auto drvPath = root->state.store->parseStorePath(aDrvPath->getString());
drvPath.requireDerivation();
if (!root->state.store->isValidPath(drvPath) && !settings.readOnlyMode) {
if (!root->state.store->isValidPath(drvPath) && !root->state.store->config.settings.readOnlyMode) {
/* The eval cache contains 'drvPath', but the actual path has
been garbage-collected. So force it to be regenerated. */
aDrvPath->forceValue();
Expand Down
14 changes: 7 additions & 7 deletions src/libexpr/eval-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ Strings EvalSettings::parseNixPath(const std::string & s)
return res;
}

EvalSettings::EvalSettings(bool & readOnlyMode, EvalSettings::LookupPathHooks lookupPathHooks)
: readOnlyMode{readOnlyMode}
EvalSettings::EvalSettings(nix::Settings & settings, EvalSettings::LookupPathHooks lookupPathHooks)
: settings{settings}
, lookupPathHooks{lookupPathHooks}
{
auto var = getEnv("NIX_ABORT_ON_WARN");
if (var && (var == "1" || var == "yes" || var == "true"))
builtinsAbortOnWarn = true;
}

Strings EvalSettings::getDefaultNixPath()
Strings EvalSettings::getDefaultNixPath(nix::Settings & settings)
{
Strings res;
auto add = [&](const std::filesystem::path & p, const std::string & s = std::string()) {
Expand All @@ -70,9 +70,9 @@ Strings EvalSettings::getDefaultNixPath()
}
};

add(std::filesystem::path{getNixDefExpr()} / "channels");
add(rootChannelsDir() / "nixpkgs", "nixpkgs");
add(rootChannelsDir());
add(std::filesystem::path{getNixDefExpr(settings)} / "channels");
add(rootChannelsDir(settings) / "nixpkgs", "nixpkgs");
add(rootChannelsDir(settings));

return res;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ const std::string & EvalSettings::getCurrentSystem() const
return evalSystem != "" ? evalSystem : settings.thisSystem.get();
}

Path getNixDefExpr()
Path getNixDefExpr(const Settings & settings)
{
return settings.useXDGBaseDirectories ? getStateDir() + "/defexpr" : getHome() + "/.nix-defexpr";
}
Expand Down
5 changes: 3 additions & 2 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "nix/store/filetransfer.hh"
#include "nix/expr/function-trace.hh"
#include "nix/store/profiles.hh"
#include "nix/store/globals.hh"
#include "nix/expr/print.hh"
#include "nix/fetchers/filtering-source-accessor.hh"
#include "nix/util/memory-source-accessor.hh"
Expand Down Expand Up @@ -331,7 +332,7 @@ EvalState::EvalState(
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
}
if (!settings.restrictEval) {
for (auto & i : EvalSettings::getDefaultNixPath()) {
for (auto & i : EvalSettings::getDefaultNixPath(store->config.settings)) {
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
}
}
Expand Down Expand Up @@ -2502,7 +2503,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
fetchSettings,
*store,
path.resolveSymlinks(SymlinkResolution::Ancestors),
settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
settings.settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
path.baseName(),
ContentAddressMethod::Raw::NixArchive,
nullptr,
Expand Down
14 changes: 9 additions & 5 deletions src/libexpr/include/nix/expr/eval-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ namespace nix {

class EvalState;
struct PrimOp;
class Settings;

struct EvalSettings : Config
{
/**
* Reference to the "parent" store-layer settings.
*/
nix::Settings & settings;

/**
* Function used to interpret look path entries of a given scheme.
*
Expand All @@ -38,11 +44,9 @@ struct EvalSettings : Config
*/
using LookupPathHooks = std::map<std::string, std::function<LookupPathHook>>;

EvalSettings(bool & readOnlyMode, LookupPathHooks lookupPathHooks = {});

bool & readOnlyMode;
EvalSettings(nix::Settings & settings, LookupPathHooks lookupPathHooks = {});

static Strings getDefaultNixPath();
static Strings getDefaultNixPath(nix::Settings & settings);

static bool isPseudoUrl(std::string_view s);

Expand Down Expand Up @@ -366,6 +370,6 @@ struct EvalSettings : Config
/**
* Conventionally part of the default nix path in impure mode.
*/
Path getNixDefExpr();
Path getNixDefExpr(const Settings & settings);

} // namespace nix
Loading
Loading