Skip to content

Commit f0a2037

Browse files
committed
WIP get rid of global Settings in libstore
This is analogous to 52bfccf for `EvalSettings`, and 3fc77f2 for `FlakeSettings` and `fetchers::Settings`.
1 parent 152e7e4 commit f0a2037

File tree

140 files changed

+949
-629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+949
-629
lines changed

src/libcmd/command.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "nix/cmd/command.hh"
55
#include "nix/cmd/legacy.hh"
66
#include "nix/cmd/markdown.hh"
7+
#include "nix/main/shared.hh"
78
#include "nix/store/store-open.hh"
89
#include "nix/store/local-fs-store.hh"
910
#include "nix/store/derivations.hh"
@@ -74,7 +75,7 @@ ref<Store> StoreCommand::getStore()
7475

7576
ref<Store> StoreCommand::createStore()
7677
{
77-
return openStore();
78+
return openStore(settings);
7879
}
7980

8081
void StoreCommand::run()
@@ -101,15 +102,15 @@ CopyCommand::CopyCommand()
101102

102103
ref<Store> CopyCommand::createStore()
103104
{
104-
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
105+
return srcUri.empty() ? StoreCommand::createStore() : openStore(settings, srcUri);
105106
}
106107

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

112-
return dstUri.empty() ? openStore() : openStore(dstUri);
113+
return dstUri.empty() ? openStore(settings) : openStore(settings, dstUri);
113114
}
114115

115116
EvalCommand::EvalCommand()
@@ -131,7 +132,7 @@ EvalCommand::~EvalCommand()
131132
ref<Store> EvalCommand::getEvalStore()
132133
{
133134
if (!evalStore)
134-
evalStore = evalStoreUrl ? openStore(*evalStoreUrl) : getStore();
135+
evalStore = evalStoreUrl ? openStore(settings, *evalStoreUrl) : getStore();
135136
return ref<Store>(evalStore);
136137
}
137138

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

298299
MixDefaultProfile::MixDefaultProfile()
299300
{
300-
profile = getDefaultProfile();
301+
profile = getDefaultProfile(settings);
301302
}
302303

303304
MixEnvironment::MixEnvironment()

src/libcmd/common-eval-args.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
namespace nix {
2121

22-
fetchers::Settings fetchSettings;
22+
fetchers::Settings fetchSettings{settings};
2323

2424
static GlobalConfig::Register rFetchSettings(&fetchSettings);
2525

2626
EvalSettings evalSettings{
27-
settings.readOnlyMode,
27+
settings,
2828
{
2929
{
3030
"flake",
@@ -135,7 +135,7 @@ MixEvalArgs::MixEvalArgs()
135135
fetchers::overrideRegistry(from.input, to.input, extraAttrs);
136136
}},
137137
.completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
138-
completeFlakeRef(completions, openStore(), prefix);
138+
completeFlakeRef(completions, openStore(settings), prefix);
139139
}},
140140
});
141141

src/libcmd/include/nix/cmd/installable-attr-path.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22
///@file
33

4-
#include "nix/store/globals.hh"
54
#include "nix/cmd/installable-value.hh"
65
#include "nix/store/outputs-spec.hh"
76
#include "nix/cmd/command.hh"

src/libcmd/repl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
565565
} else if (command == ":log") {
566566
settings.readOnlyMode = true;
567567
Finally roModeReset([&]() { settings.readOnlyMode = false; });
568-
auto subs = getDefaultSubstituters();
568+
auto subs = getDefaultSubstituters(settings);
569569

570570
subs.push_front(state->store);
571571

@@ -918,7 +918,7 @@ ReplExitStatus AbstractNixRepl::runSimple(ref<EvalState> evalState, const ValMap
918918
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete)
919919
auto repl = std::make_unique<NixRepl>(
920920
lookupPath,
921-
openStore(),
921+
openStore(settings),
922922
evalState,
923923
getValues,
924924
/*runNix=*/nullptr);

src/libexpr-c/nix_api_expr.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Sto
126126
return unsafe_new_with_self<nix_eval_state_builder>([&](auto * self) {
127127
return nix_eval_state_builder{
128128
.store = nix::ref<nix::Store>(store->ptr),
129-
.settings = nix::EvalSettings{/* &bool */ self->readOnlyMode},
130-
.fetchSettings = nix::fetchers::Settings{},
131-
.readOnlyMode = true,
129+
.settings = nix::EvalSettings{cStoreSettings},
130+
.fetchSettings = nix::fetchers::Settings{cStoreSettings},
132131
};
133132
});
134133
}
@@ -147,8 +146,7 @@ nix_err nix_eval_state_builder_load(nix_c_context * context, nix_eval_state_buil
147146
if (context)
148147
context->last_err_code = NIX_OK;
149148
try {
150-
// TODO: load in one go?
151-
builder->settings.readOnlyMode = nix::settings.readOnlyMode;
149+
loadConfFile(cStoreSettings);
152150
loadConfFile(builder->settings);
153151
loadConfFile(builder->fetchSettings);
154152
}

src/libexpr-c/nix_api_expr_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ struct nix_eval_state_builder
1616
nix::EvalSettings settings;
1717
nix::fetchers::Settings fetchSettings;
1818
nix::LookupPath lookupPath;
19-
// TODO: make an EvalSettings setting own this instead?
20-
bool readOnlyMode;
2119
};
2220

2321
struct EvalState

src/libexpr-test-support/include/nix/expr/tests/libexpr.hh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ public:
2626
}
2727

2828
protected:
29-
LibExprTest(ref<Store> store, auto && makeEvalSettings)
30-
: LibStoreTest()
31-
, evalSettings(makeEvalSettings(readOnlyMode))
29+
LibExprTest(auto && makeEvalSettings, auto &&... args)
30+
: LibStoreTest(args...)
31+
, evalSettings(makeEvalSettings(settings))
3232
, state({}, store, fetchSettings, evalSettings, nullptr)
3333
{
3434
}
3535

3636
LibExprTest()
37-
: LibExprTest(openStore("dummy://"), [](bool & readOnlyMode) {
38-
EvalSettings settings{readOnlyMode};
39-
settings.nixPath = {};
40-
return settings;
37+
: LibExprTest([](Settings & settings) {
38+
EvalSettings evalSettings{settings};
39+
evalSettings.nixPath = {};
40+
return evalSettings;
4141
})
4242
{
4343
}
@@ -66,8 +66,8 @@ protected:
6666
}
6767

6868
bool readOnlyMode = true;
69-
fetchers::Settings fetchSettings{};
70-
EvalSettings evalSettings{readOnlyMode};
69+
fetchers::Settings fetchSettings{settings};
70+
EvalSettings evalSettings{settings};
7171
EvalState state;
7272
};
7373

src/libexpr-tests/eval.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,15 @@ class PureEvalTest : public LibExprTest
179179
{
180180
public:
181181
PureEvalTest()
182-
: LibExprTest(openStore("dummy://", {{"read-only", "false"}}), [](bool & readOnlyMode) {
183-
EvalSettings settings{readOnlyMode};
184-
settings.pureEval = true;
185-
settings.restrictEval = true;
186-
return settings;
187-
})
182+
: LibExprTest{
183+
[](auto & settings) {
184+
EvalSettings evalSettings{settings};
185+
evalSettings.pureEval = true;
186+
evalSettings.restrictEval = true;
187+
return evalSettings;
188+
},
189+
[](auto & settings) { return openStore(settings, "dummy://", {{"read-only", "false"}}); },
190+
}
188191
{
189192
}
190193
};

src/libexpr/eval-cache.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct AttrDb
6363

6464
SymbolTable & symbols;
6565

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

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

78-
state->db = SQLite(dbPath);
78+
state->db = SQLite(dbPath, {.useWAL = useSQLiteWAL});
7979
state->db.isCache();
8080
state->db.exec(schema);
8181

@@ -287,10 +287,11 @@ struct AttrDb
287287
}
288288
};
289289

290-
static std::shared_ptr<AttrDb> makeAttrDb(const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
290+
static std::shared_ptr<AttrDb>
291+
makeAttrDb(bool useSQLiteWAL, const StoreDirConfig & cfg, const Hash & fingerprint, SymbolTable & symbols)
291292
{
292293
try {
293-
return std::make_shared<AttrDb>(cfg, fingerprint, symbols);
294+
return std::make_shared<AttrDb>(useSQLiteWAL, cfg, fingerprint, symbols);
294295
} catch (SQLiteError &) {
295296
ignoreExceptionExceptInterrupt();
296297
return nullptr;
@@ -299,7 +300,8 @@ static std::shared_ptr<AttrDb> makeAttrDb(const StoreDirConfig & cfg, const Hash
299300

300301
EvalCache::EvalCache(
301302
std::optional<std::reference_wrapper<const Hash>> useCache, EvalState & state, RootLoader rootLoader)
302-
: db(useCache ? makeAttrDb(*state.store, *useCache, state.symbols) : nullptr)
303+
: db(useCache ? makeAttrDb(state.store->config.settings.useSQLiteWAL, *state.store, *useCache, state.symbols)
304+
: nullptr)
303305
, state(state)
304306
, rootLoader(rootLoader)
305307
{
@@ -707,7 +709,7 @@ StorePath AttrCursor::forceDerivation()
707709
auto aDrvPath = getAttr(root->state.s.drvPath);
708710
auto drvPath = root->state.store->parseStorePath(aDrvPath->getString());
709711
drvPath.requireDerivation();
710-
if (!root->state.store->isValidPath(drvPath) && !settings.readOnlyMode) {
712+
if (!root->state.store->isValidPath(drvPath) && !root->state.store->config.settings.readOnlyMode) {
711713
/* The eval cache contains 'drvPath', but the actual path has
712714
been garbage-collected. So force it to be regenerated. */
713715
aDrvPath->forceValue();

src/libexpr/eval-settings.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ Strings EvalSettings::parseNixPath(const std::string & s)
4848
return res;
4949
}
5050

51-
EvalSettings::EvalSettings(bool & readOnlyMode, EvalSettings::LookupPathHooks lookupPathHooks)
52-
: readOnlyMode{readOnlyMode}
51+
EvalSettings::EvalSettings(nix::Settings & settings, EvalSettings::LookupPathHooks lookupPathHooks)
52+
: settings{settings}
5353
, lookupPathHooks{lookupPathHooks}
5454
{
5555
auto var = getEnv("NIX_ABORT_ON_WARN");
5656
if (var && (var == "1" || var == "yes" || var == "true"))
5757
builtinsAbortOnWarn = true;
5858
}
5959

60-
Strings EvalSettings::getDefaultNixPath()
60+
Strings EvalSettings::getDefaultNixPath(nix::Settings & settings)
6161
{
6262
Strings res;
6363
auto add = [&](const Path & p, const std::string & s = std::string()) {
@@ -70,9 +70,9 @@ Strings EvalSettings::getDefaultNixPath()
7070
}
7171
};
7272

73-
add(getNixDefExpr() + "/channels");
74-
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
75-
add(rootChannelsDir());
73+
add(getNixDefExpr(settings) + "/channels");
74+
add(rootChannelsDir(settings) + "/nixpkgs", "nixpkgs");
75+
add(rootChannelsDir(settings));
7676

7777
return res;
7878
}
@@ -103,9 +103,9 @@ const std::string & EvalSettings::getCurrentSystem() const
103103
return evalSystem != "" ? evalSystem : settings.thisSystem.get();
104104
}
105105

106-
Path getNixDefExpr()
106+
Path getNixDefExpr(const Settings & settings)
107107
{
108108
return settings.useXDGBaseDirectories ? getStateDir() + "/defexpr" : getHome() + "/.nix-defexpr";
109109
}
110110

111-
} // namespace nix
111+
} // namespace nix

0 commit comments

Comments
 (0)