Skip to content

Commit 3b03872

Browse files
authored
Merge pull request #13766 from obsidiansystems/more-store-dir
Make a few more things use `StoreDirConfig` instead of `Store`
2 parents 97c966c + 79fb9b0 commit 3b03872

File tree

11 files changed

+45
-38
lines changed

11 files changed

+45
-38
lines changed

src/libstore-test-support/include/nix/store/tests/protocol.hh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
namespace nix {
1111

1212
template<class Proto, const char * protocolDir>
13-
class ProtoTest : public CharacterizationTest, public LibStoreTest
13+
class ProtoTest : public CharacterizationTest
1414
{
1515
std::filesystem::path unitTestData = getUnitTestData() / protocolDir;
1616

1717
std::filesystem::path goldenMaster(std::string_view testStem) const override
1818
{
1919
return unitTestData / (std::string{testStem + ".bin"});
2020
}
21+
22+
public:
23+
Path storeDir = "/nix/store";
24+
StoreDirConfig store{storeDir};
2125
};
2226

2327
template<class Proto, const char * protocolDir>
@@ -34,7 +38,7 @@ public:
3438
T got = ({
3539
StringSource from{encoded};
3640
Proto::template Serialise<T>::read(
37-
*LibStoreTest::store,
41+
this->store,
3842
typename Proto::ReadConn{
3943
.from = from,
4044
.version = version,
@@ -54,7 +58,7 @@ public:
5458
CharacterizationTest::writeTest(testStem, [&]() {
5559
StringSink to;
5660
Proto::template Serialise<T>::write(
57-
*LibStoreTest::store,
61+
this->store,
5862
typename Proto::WriteConn{
5963
.to = to,
6064
.version = version,

src/libstore-tests/common-protocol.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CommonProtoTest : public ProtoTest<CommonProto, commonProtoDir>
2525
CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
2626
T got = ({
2727
StringSource from{encoded};
28-
CommonProto::Serialise<T>::read(*store, CommonProto::ReadConn{.from = from});
28+
CommonProto::Serialise<T>::read(store, CommonProto::ReadConn{.from = from});
2929
});
3030

3131
ASSERT_EQ(got, expected);
@@ -40,7 +40,7 @@ class CommonProtoTest : public ProtoTest<CommonProto, commonProtoDir>
4040
{
4141
CharacterizationTest::writeTest(testStem, [&]() -> std::string {
4242
StringSink to;
43-
CommonProto::Serialise<T>::write(*store, CommonProto::WriteConn{.to = to}, decoded);
43+
CommonProto::Serialise<T>::write(store, CommonProto::WriteConn{.to = to}, decoded);
4444
return to.s;
4545
});
4646
}

src/libstore-tests/serve-protocol.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ VERSIONED_CHARACTERIZATION_TEST(
275275
}),
276276
({
277277
ValidPathInfo info{
278-
*LibStoreTest::store,
278+
store,
279279
"foo",
280280
FixedOutputInfo{
281281
.method = FileIngestionMethod::NixArchive,

src/libstore-tests/worker-protocol.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ VERSIONED_CHARACTERIZATION_TEST(
516516
}),
517517
({
518518
ValidPathInfo info{
519-
*LibStoreTest::store,
519+
store,
520520
"foo",
521521
FixedOutputInfo{
522522
.method = FileIngestionMethod::NixArchive,

src/libstore/build/derivation-building-goal.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct value_comparison
132132
}
133133
};
134134

135-
std::string showKnownOutputs(Store & store, const Derivation & drv)
135+
std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv)
136136
{
137137
std::string msg;
138138
StorePathSet expectedOutputPaths;
@@ -744,7 +744,8 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
744744
#endif
745745
}
746746

747-
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths)
747+
void runPostBuildHook(
748+
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths)
748749
{
749750
auto hook = settings.postBuildHook;
750751
if (hook == "")

src/libstore/include/nix/store/build/derivation-building-goal.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ struct DerivationBuilder;
2121

2222
typedef enum { rpAccept, rpDecline, rpPostpone } HookReply;
2323

24-
/** Used internally */
25-
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
26-
2724
/**
2825
* A goal for building a derivation. Substitution, (or any other method of
2926
* obtaining the outputs) will not be attempted, so it is the calling goal's

src/libstore/include/nix/store/build/derivation-building-misc.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ struct InitialOutput
4949
std::optional<InitialOutputStatus> known;
5050
};
5151

52-
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
52+
void runPostBuildHook(
53+
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
5354

5455
/**
5556
* Format the known outputs of a derivation for use in error messages.
5657
*/
57-
std::string showKnownOutputs(Store & store, const Derivation & drv);
58+
std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv);
5859

5960
} // namespace nix

src/libstore/include/nix/store/nar-info.hh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace nix {
99

10-
class Store;
10+
struct StoreDirConfig;
1111

1212
struct NarInfo : ValidPathInfo
1313
{
@@ -18,7 +18,7 @@ struct NarInfo : ValidPathInfo
1818

1919
NarInfo() = delete;
2020

21-
NarInfo(const Store & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
21+
NarInfo(const StoreDirConfig & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
2222
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
2323
{
2424
}
@@ -33,16 +33,16 @@ struct NarInfo : ValidPathInfo
3333
{
3434
}
3535

36-
NarInfo(const Store & store, const std::string & s, const std::string & whence);
36+
NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence);
3737

3838
bool operator==(const NarInfo &) const = default;
3939
// TODO libc++ 16 (used by darwin) missing `std::optional::operator <=>`, can't do yet
4040
// auto operator <=>(const NarInfo &) const = default;
4141

42-
std::string to_string(const Store & store) const;
42+
std::string to_string(const StoreDirConfig & store) const;
4343

44-
nlohmann::json toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const override;
45-
static NarInfo fromJSON(const Store & store, const StorePath & path, const nlohmann::json & json);
44+
nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const override;
45+
static NarInfo fromJSON(const StoreDirConfig & store, const StorePath & path, const nlohmann::json & json);
4646
};
4747

4848
} // namespace nix

src/libstore/include/nix/store/path-info.hh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace nix {
1313

1414
class Store;
15+
struct StoreDirConfig;
1516

1617
struct SubstitutablePathInfo
1718
{
@@ -116,8 +117,8 @@ struct UnkeyedValidPathInfo
116117
* @param includeImpureInfo If true, variable elements such as the
117118
* registration time are included.
118119
*/
119-
virtual nlohmann::json toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const;
120-
static UnkeyedValidPathInfo fromJSON(const Store & store, const nlohmann::json & json);
120+
virtual nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const;
121+
static UnkeyedValidPathInfo fromJSON(const StoreDirConfig & store, const nlohmann::json & json);
121122
};
122123

123124
struct ValidPathInfo : UnkeyedValidPathInfo
@@ -135,7 +136,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo
135136
* speaking superfluous, but might prevent endless/excessive data
136137
* attacks.
137138
*/
138-
std::string fingerprint(const Store & store) const;
139+
std::string fingerprint(const StoreDirConfig & store) const;
139140

140141
void sign(const Store & store, const Signer & signer);
141142
void sign(const Store & store, const std::vector<std::unique_ptr<Signer>> & signers);
@@ -150,7 +151,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo
150151
/**
151152
* @return true iff the path is verifiably content-addressed.
152153
*/
153-
bool isContentAddressed(const Store & store) const;
154+
bool isContentAddressed(const StoreDirConfig & store) const;
154155

155156
static const size_t maxSigs = std::numeric_limits<size_t>::max();
156157

@@ -159,12 +160,12 @@ struct ValidPathInfo : UnkeyedValidPathInfo
159160
* produced by one of the specified keys, or maxSigs if the path
160161
* is content-addressed.
161162
*/
162-
size_t checkSignatures(const Store & store, const PublicKeys & publicKeys) const;
163+
size_t checkSignatures(const StoreDirConfig & store, const PublicKeys & publicKeys) const;
163164

164165
/**
165166
* Verify a single signature.
166167
*/
167-
bool checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const;
168+
bool checkSignature(const StoreDirConfig & store, const PublicKeys & publicKeys, const std::string & sig) const;
168169

169170
/**
170171
* References as store path basenames, including a self reference if it has one.
@@ -178,7 +179,8 @@ struct ValidPathInfo : UnkeyedValidPathInfo
178179
: UnkeyedValidPathInfo(info)
179180
, path(path) {};
180181

181-
ValidPathInfo(const Store & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
182+
ValidPathInfo(
183+
const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
182184
};
183185

184186
static_assert(std::is_move_assignable_v<ValidPathInfo>);

src/libstore/nar-info.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace nix {
88

9-
NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & whence)
9+
NarInfo::NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence)
1010
: ValidPathInfo(StorePath(StorePath::dummy), Hash(Hash::dummy)) // FIXME: hack
1111
{
1212
unsigned line = 1;
@@ -102,7 +102,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
102102
}
103103
}
104104

105-
std::string NarInfo::to_string(const Store & store) const
105+
std::string NarInfo::to_string(const StoreDirConfig & store) const
106106
{
107107
std::string res;
108108
res += "StorePath: " + store.printStorePath(path) + "\n";
@@ -130,7 +130,7 @@ std::string NarInfo::to_string(const Store & store) const
130130
return res;
131131
}
132132

133-
nlohmann::json NarInfo::toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const
133+
nlohmann::json NarInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const
134134
{
135135
using nlohmann::json;
136136

@@ -150,7 +150,7 @@ nlohmann::json NarInfo::toJSON(const Store & store, bool includeImpureInfo, Hash
150150
return jsonObject;
151151
}
152152

153-
NarInfo NarInfo::fromJSON(const Store & store, const StorePath & path, const nlohmann::json & json)
153+
NarInfo NarInfo::fromJSON(const StoreDirConfig & store, const StorePath & path, const nlohmann::json & json)
154154
{
155155
using nlohmann::detail::value_t;
156156

0 commit comments

Comments
 (0)