Skip to content

Commit e088ab3

Browse files
authored
Merge pull request #13154 from obsidiansystems/split-store-config
Stores no longer inherit from their configs
2 parents addb9f8 + 934918b commit e088ab3

Some content is hidden

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

48 files changed

+746
-596
lines changed

doc/manual/generate-store-info.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let
3333
{
3434
settings,
3535
doc,
36+
uri-schemes,
3637
experimentalFeature,
3738
}:
3839
let

src/build-remote/build-remote.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)
4444

4545
static bool allSupportedLocally(Store & store, const StringSet& requiredFeatures) {
4646
for (auto & feature : requiredFeatures)
47-
if (!store.systemFeatures.get().count(feature)) return false;
47+
if (!store.config.systemFeatures.get().count(feature)) return false;
4848
return true;
4949
}
5050

@@ -85,7 +85,7 @@ static int main_build_remote(int argc, char * * argv)
8585
that gets cleared on reboot, but it wouldn't work on macOS. */
8686
auto currentLoadName = "/current-load";
8787
if (auto localStore = store.dynamic_pointer_cast<LocalFSStore>())
88-
currentLoad = std::string { localStore->stateDir } + currentLoadName;
88+
currentLoad = std::string { localStore->config.stateDir } + currentLoadName;
8989
else
9090
currentLoad = settings.nixStateDir + currentLoadName;
9191

src/libcmd/include/nix/cmd/command.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern char ** savedArgv;
1818
class EvalState;
1919
struct Pos;
2020
class Store;
21-
class LocalFSStore;
21+
struct LocalFSStore;
2222

2323
static constexpr Command::Category catHelp = -1;
2424
static constexpr Command::Category catSecondary = 100;

src/libstore-c/nix_api_store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Store * nix_store_open(nix_c_context * context, const char * uri, const char ***
4242
if (!params)
4343
return new Store{nix::openStore(uri_str)};
4444

45-
nix::Store::Params params_map;
45+
nix::Store::Config::Params params_map;
4646
for (size_t i = 0; params[i] != nullptr; i++) {
4747
params_map[params[i][0]] = params[i][1];
4848
}

src/libstore/binary-cache-store.cc

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@
2424

2525
namespace nix {
2626

27-
BinaryCacheStore::BinaryCacheStore(const Params & params)
28-
: BinaryCacheStoreConfig(params)
29-
, Store(params)
27+
BinaryCacheStore::BinaryCacheStore(Config & config)
28+
: config{config}
3029
{
31-
if (secretKeyFile != "")
30+
if (config.secretKeyFile != "")
3231
signers.push_back(std::make_unique<LocalSigner>(
33-
SecretKey { readFile(secretKeyFile) }));
32+
SecretKey { readFile(config.secretKeyFile) }));
3433

35-
if (secretKeyFiles != "") {
36-
std::stringstream ss(secretKeyFiles);
34+
if (config.secretKeyFiles != "") {
35+
std::stringstream ss(config.secretKeyFiles);
3736
Path keyPath;
3837
while (std::getline(ss, keyPath, ',')) {
3938
signers.push_back(std::make_unique<LocalSigner>(
@@ -62,9 +61,9 @@ void BinaryCacheStore::init()
6261
throw Error("binary cache '%s' is for Nix stores with prefix '%s', not '%s'",
6362
getUri(), value, storeDir);
6463
} else if (name == "WantMassQuery") {
65-
wantMassQuery.setDefault(value == "1");
64+
config.wantMassQuery.setDefault(value == "1");
6665
} else if (name == "Priority") {
67-
priority.setDefault(std::stoi(value));
66+
config.priority.setDefault(std::stoi(value));
6867
}
6968
}
7069
}
@@ -156,7 +155,11 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
156155
{
157156
FdSink fileSink(fdTemp.get());
158157
TeeSink teeSinkCompressed { fileSink, fileHashSink };
159-
auto compressionSink = makeCompressionSink(compression, teeSinkCompressed, parallelCompression, compressionLevel);
158+
auto compressionSink = makeCompressionSink(
159+
config.compression,
160+
teeSinkCompressed,
161+
config.parallelCompression,
162+
config.compressionLevel);
160163
TeeSink teeSinkUncompressed { *compressionSink, narHashSink };
161164
TeeSource teeSource { narSource, teeSinkUncompressed };
162165
narAccessor = makeNarAccessor(teeSource);
@@ -168,17 +171,17 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
168171

169172
auto info = mkInfo(narHashSink.finish());
170173
auto narInfo = make_ref<NarInfo>(info);
171-
narInfo->compression = compression;
174+
narInfo->compression = config.compression;
172175
auto [fileHash, fileSize] = fileHashSink.finish();
173176
narInfo->fileHash = fileHash;
174177
narInfo->fileSize = fileSize;
175178
narInfo->url = "nar/" + narInfo->fileHash->to_string(HashFormat::Nix32, false) + ".nar"
176-
+ (compression == "xz" ? ".xz" :
177-
compression == "bzip2" ? ".bz2" :
178-
compression == "zstd" ? ".zst" :
179-
compression == "lzip" ? ".lzip" :
180-
compression == "lz4" ? ".lz4" :
181-
compression == "br" ? ".br" :
179+
+ (config.compression == "xz" ? ".xz" :
180+
config.compression == "bzip2" ? ".bz2" :
181+
config.compression == "zstd" ? ".zst" :
182+
config.compression == "lzip" ? ".lzip" :
183+
config.compression == "lz4" ? ".lz4" :
184+
config.compression == "br" ? ".br" :
182185
"");
183186

184187
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1).count();
@@ -200,7 +203,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
200203

201204
/* Optionally write a JSON file containing a listing of the
202205
contents of the NAR. */
203-
if (writeNARListing) {
206+
if (config.writeNARListing) {
204207
nlohmann::json j = {
205208
{"version", 1},
206209
{"root", listNar(ref<SourceAccessor>(narAccessor), CanonPath::root, true)},
@@ -212,7 +215,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
212215
/* Optionally maintain an index of DWARF debug info files
213216
consisting of JSON files named 'debuginfo/<build-id>' that
214217
specify the NAR file and member containing the debug info. */
215-
if (writeDebugInfo) {
218+
if (config.writeDebugInfo) {
216219

217220
CanonPath buildIdDir("lib/debug/.build-id");
218221

@@ -524,7 +527,7 @@ void BinaryCacheStore::registerDrvOutput(const Realisation& info) {
524527

525528
ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
526529
{
527-
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath, localNarCache);
530+
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath, config.localNarCache);
528531
}
529532

530533
void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSet & sigs)

src/libstore/build/derivation-goal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ Path DerivationGoal::openLogFile()
12841284
/* Create a log file. */
12851285
Path logDir;
12861286
if (auto localStore = dynamic_cast<LocalStore *>(&worker.store))
1287-
logDir = localStore->logDir;
1287+
logDir = localStore->config->logDir;
12881288
else
12891289
logDir = settings.nixLogDir;
12901290
Path dir = fmt("%s/%s/%s/", logDir, LocalFSStore::drvsLogDir, baseName.substr(0, 2));

src/libstore/build/substitution-goal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Goal::Co PathSubstitutionGoal::init()
121121
/* Bail out early if this substituter lacks a valid
122122
signature. LocalStore::addToStore() also checks for this, but
123123
only after we've downloaded the path. */
124-
if (!sub->isTrusted && worker.store.pathInfoIsUntrusted(*info))
124+
if (!sub->config.isTrusted && worker.store.pathInfoIsUntrusted(*info))
125125
{
126126
warn("ignoring substitute for '%s' from '%s', as it's not signed by any of the keys in 'trusted-public-keys'",
127127
worker.store.printStorePath(storePath), sub->getUri());
@@ -215,7 +215,7 @@ Goal::Co PathSubstitutionGoal::tryToRun(StorePath subPath, nix::ref<Store> sub,
215215
PushActivity pact(act.id);
216216

217217
copyStorePath(*sub, worker.store,
218-
subPath, repair, sub->isTrusted ? NoCheckSigs : CheckSigs);
218+
subPath, repair, sub->config.isTrusted ? NoCheckSigs : CheckSigs);
219219

220220
promise.set_value();
221221
} catch (...) {

src/libstore/common-ssh-store-config.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CommonSSHStoreConfig::CommonSSHStoreConfig(std::string_view scheme, std::string_
2828
{
2929
}
3030

31-
SSHMaster CommonSSHStoreConfig::createSSHMaster(bool useMaster, Descriptor logFD)
31+
SSHMaster CommonSSHStoreConfig::createSSHMaster(bool useMaster, Descriptor logFD) const
3232
{
3333
return {
3434
host,

src/libstore/derivation-options.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ bool DerivationOptions::canBuildLocally(Store & localStore, const BasicDerivatio
265265
return false;
266266

267267
for (auto & feature : getRequiredSystemFeatures(drv))
268-
if (!localStore.systemFeatures.get().count(feature))
268+
if (!localStore.config.systemFeatures.get().count(feature))
269269
return false;
270270

271271
return true;

src/libstore/dummy-store.cc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace nix {
55

6-
struct DummyStoreConfig : virtual StoreConfig {
6+
struct DummyStoreConfig : public std::enable_shared_from_this<DummyStoreConfig>, virtual StoreConfig {
77
using StoreConfig::StoreConfig;
88

99
DummyStoreConfig(std::string_view scheme, std::string_view authority, const Params & params)
@@ -13,9 +13,9 @@ struct DummyStoreConfig : virtual StoreConfig {
1313
throw UsageError("`%s` store URIs must not contain an authority part %s", scheme, authority);
1414
}
1515

16-
const std::string name() override { return "Dummy Store"; }
16+
static const std::string name() { return "Dummy Store"; }
1717

18-
std::string doc() override
18+
static std::string doc()
1919
{
2020
return
2121
#include "dummy-store.md"
@@ -25,23 +25,24 @@ struct DummyStoreConfig : virtual StoreConfig {
2525
static StringSet uriSchemes() {
2626
return {"dummy"};
2727
}
28+
29+
ref<Store> openStore() const override;
2830
};
2931

30-
struct DummyStore : public virtual DummyStoreConfig, public virtual Store
32+
struct DummyStore : virtual Store
3133
{
32-
DummyStore(std::string_view scheme, std::string_view authority, const Params & params)
33-
: StoreConfig(params)
34-
, DummyStoreConfig(scheme, authority, params)
35-
, Store(params)
36-
{ }
34+
using Config = DummyStoreConfig;
35+
36+
ref<const Config> config;
3737

38-
DummyStore(const Params & params)
39-
: DummyStore("dummy", "", params)
38+
DummyStore(ref<const Config> config)
39+
: Store{*config}
40+
, config(config)
4041
{ }
4142

4243
std::string getUri() override
4344
{
44-
return *uriSchemes().begin();
45+
return *Config::uriSchemes().begin();
4546
}
4647

4748
void queryPathInfoUncached(const StorePath & path,
@@ -88,6 +89,11 @@ struct DummyStore : public virtual DummyStoreConfig, public virtual Store
8889
}
8990
};
9091

91-
static RegisterStoreImplementation<DummyStore, DummyStoreConfig> regDummyStore;
92+
ref<Store> DummyStore::Config::openStore() const
93+
{
94+
return make_ref<DummyStore>(ref{shared_from_this()});
95+
}
96+
97+
static RegisterStoreImplementation<DummyStore::Config> regDummyStore;
9298

9399
}

0 commit comments

Comments
 (0)