mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Make a few more things use StoreDirConfig instead of Store
This commit is contained in:
parent
316fef35dc
commit
79fb9b0d3c
11 changed files with 45 additions and 38 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
template<class Proto, const char * protocolDir>
|
template<class Proto, const char * protocolDir>
|
||||||
class ProtoTest : public CharacterizationTest, public LibStoreTest
|
class ProtoTest : public CharacterizationTest
|
||||||
{
|
{
|
||||||
std::filesystem::path unitTestData = getUnitTestData() / protocolDir;
|
std::filesystem::path unitTestData = getUnitTestData() / protocolDir;
|
||||||
|
|
||||||
|
|
@ -18,6 +18,10 @@ class ProtoTest : public CharacterizationTest, public LibStoreTest
|
||||||
{
|
{
|
||||||
return unitTestData / (std::string{testStem + ".bin"});
|
return unitTestData / (std::string{testStem + ".bin"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
Path storeDir = "/nix/store";
|
||||||
|
StoreDirConfig store{storeDir};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Proto, const char * protocolDir>
|
template<class Proto, const char * protocolDir>
|
||||||
|
|
@ -34,7 +38,7 @@ public:
|
||||||
T got = ({
|
T got = ({
|
||||||
StringSource from{encoded};
|
StringSource from{encoded};
|
||||||
Proto::template Serialise<T>::read(
|
Proto::template Serialise<T>::read(
|
||||||
*LibStoreTest::store,
|
this->store,
|
||||||
typename Proto::ReadConn{
|
typename Proto::ReadConn{
|
||||||
.from = from,
|
.from = from,
|
||||||
.version = version,
|
.version = version,
|
||||||
|
|
@ -54,7 +58,7 @@ public:
|
||||||
CharacterizationTest::writeTest(testStem, [&]() {
|
CharacterizationTest::writeTest(testStem, [&]() {
|
||||||
StringSink to;
|
StringSink to;
|
||||||
Proto::template Serialise<T>::write(
|
Proto::template Serialise<T>::write(
|
||||||
*LibStoreTest::store,
|
this->store,
|
||||||
typename Proto::WriteConn{
|
typename Proto::WriteConn{
|
||||||
.to = to,
|
.to = to,
|
||||||
.version = version,
|
.version = version,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public:
|
||||||
CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
|
CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
|
||||||
T got = ({
|
T got = ({
|
||||||
StringSource from{encoded};
|
StringSource from{encoded};
|
||||||
CommonProto::Serialise<T>::read(*store, CommonProto::ReadConn{.from = from});
|
CommonProto::Serialise<T>::read(store, CommonProto::ReadConn{.from = from});
|
||||||
});
|
});
|
||||||
|
|
||||||
ASSERT_EQ(got, expected);
|
ASSERT_EQ(got, expected);
|
||||||
|
|
@ -40,7 +40,7 @@ public:
|
||||||
{
|
{
|
||||||
CharacterizationTest::writeTest(testStem, [&]() -> std::string {
|
CharacterizationTest::writeTest(testStem, [&]() -> std::string {
|
||||||
StringSink to;
|
StringSink to;
|
||||||
CommonProto::Serialise<T>::write(*store, CommonProto::WriteConn{.to = to}, decoded);
|
CommonProto::Serialise<T>::write(store, CommonProto::WriteConn{.to = to}, decoded);
|
||||||
return to.s;
|
return to.s;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
}),
|
}),
|
||||||
({
|
({
|
||||||
ValidPathInfo info{
|
ValidPathInfo info{
|
||||||
*LibStoreTest::store,
|
store,
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
.method = FileIngestionMethod::NixArchive,
|
.method = FileIngestionMethod::NixArchive,
|
||||||
|
|
|
||||||
|
|
@ -516,7 +516,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
}),
|
}),
|
||||||
({
|
({
|
||||||
ValidPathInfo info{
|
ValidPathInfo info{
|
||||||
*LibStoreTest::store,
|
store,
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
.method = FileIngestionMethod::NixArchive,
|
.method = FileIngestionMethod::NixArchive,
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ struct value_comparison
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string showKnownOutputs(Store & store, const Derivation & drv)
|
std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv)
|
||||||
{
|
{
|
||||||
std::string msg;
|
std::string msg;
|
||||||
StorePathSet expectedOutputPaths;
|
StorePathSet expectedOutputPaths;
|
||||||
|
|
@ -743,7 +743,8 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths)
|
void runPostBuildHook(
|
||||||
|
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths)
|
||||||
{
|
{
|
||||||
auto hook = settings.postBuildHook;
|
auto hook = settings.postBuildHook;
|
||||||
if (hook == "")
|
if (hook == "")
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@ struct DerivationBuilder;
|
||||||
|
|
||||||
typedef enum { rpAccept, rpDecline, rpPostpone } HookReply;
|
typedef enum { rpAccept, rpDecline, rpPostpone } HookReply;
|
||||||
|
|
||||||
/** Used internally */
|
|
||||||
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A goal for building a derivation. Substitution, (or any other method of
|
* A goal for building a derivation. Substitution, (or any other method of
|
||||||
* obtaining the outputs) will not be attempted, so it is the calling goal's
|
* obtaining the outputs) will not be attempted, so it is the calling goal's
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,12 @@ struct InitialOutput
|
||||||
std::optional<InitialOutputStatus> known;
|
std::optional<InitialOutputStatus> known;
|
||||||
};
|
};
|
||||||
|
|
||||||
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
|
void runPostBuildHook(
|
||||||
|
const StoreDirConfig & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the known outputs of a derivation for use in error messages.
|
* Format the known outputs of a derivation for use in error messages.
|
||||||
*/
|
*/
|
||||||
std::string showKnownOutputs(Store & store, const Derivation & drv);
|
std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv);
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class Store;
|
struct StoreDirConfig;
|
||||||
|
|
||||||
struct NarInfo : ValidPathInfo
|
struct NarInfo : ValidPathInfo
|
||||||
{
|
{
|
||||||
|
|
@ -18,7 +18,7 @@ struct NarInfo : ValidPathInfo
|
||||||
|
|
||||||
NarInfo() = delete;
|
NarInfo() = delete;
|
||||||
|
|
||||||
NarInfo(const Store & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
|
NarInfo(const StoreDirConfig & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
|
||||||
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
|
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -33,16 +33,16 @@ struct NarInfo : ValidPathInfo
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NarInfo(const Store & store, const std::string & s, const std::string & whence);
|
NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence);
|
||||||
|
|
||||||
bool operator==(const NarInfo &) const = default;
|
bool operator==(const NarInfo &) const = default;
|
||||||
// TODO libc++ 16 (used by darwin) missing `std::optional::operator <=>`, can't do yet
|
// TODO libc++ 16 (used by darwin) missing `std::optional::operator <=>`, can't do yet
|
||||||
// auto operator <=>(const NarInfo &) const = default;
|
// auto operator <=>(const NarInfo &) const = default;
|
||||||
|
|
||||||
std::string to_string(const Store & store) const;
|
std::string to_string(const StoreDirConfig & store) const;
|
||||||
|
|
||||||
nlohmann::json toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const override;
|
nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const override;
|
||||||
static NarInfo fromJSON(const Store & store, const StorePath & path, const nlohmann::json & json);
|
static NarInfo fromJSON(const StoreDirConfig & store, const StorePath & path, const nlohmann::json & json);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class Store;
|
class Store;
|
||||||
|
struct StoreDirConfig;
|
||||||
|
|
||||||
struct SubstitutablePathInfo
|
struct SubstitutablePathInfo
|
||||||
{
|
{
|
||||||
|
|
@ -116,8 +117,8 @@ struct UnkeyedValidPathInfo
|
||||||
* @param includeImpureInfo If true, variable elements such as the
|
* @param includeImpureInfo If true, variable elements such as the
|
||||||
* registration time are included.
|
* registration time are included.
|
||||||
*/
|
*/
|
||||||
virtual nlohmann::json toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const;
|
virtual nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const;
|
||||||
static UnkeyedValidPathInfo fromJSON(const Store & store, const nlohmann::json & json);
|
static UnkeyedValidPathInfo fromJSON(const StoreDirConfig & store, const nlohmann::json & json);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ValidPathInfo : UnkeyedValidPathInfo
|
struct ValidPathInfo : UnkeyedValidPathInfo
|
||||||
|
|
@ -135,7 +136,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo
|
||||||
* speaking superfluous, but might prevent endless/excessive data
|
* speaking superfluous, but might prevent endless/excessive data
|
||||||
* attacks.
|
* attacks.
|
||||||
*/
|
*/
|
||||||
std::string fingerprint(const Store & store) const;
|
std::string fingerprint(const StoreDirConfig & store) const;
|
||||||
|
|
||||||
void sign(const Store & store, const Signer & signer);
|
void sign(const Store & store, const Signer & signer);
|
||||||
void sign(const Store & store, const std::vector<std::unique_ptr<Signer>> & signers);
|
void sign(const Store & store, const std::vector<std::unique_ptr<Signer>> & signers);
|
||||||
|
|
@ -150,7 +151,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo
|
||||||
/**
|
/**
|
||||||
* @return true iff the path is verifiably content-addressed.
|
* @return true iff the path is verifiably content-addressed.
|
||||||
*/
|
*/
|
||||||
bool isContentAddressed(const Store & store) const;
|
bool isContentAddressed(const StoreDirConfig & store) const;
|
||||||
|
|
||||||
static const size_t maxSigs = std::numeric_limits<size_t>::max();
|
static const size_t maxSigs = std::numeric_limits<size_t>::max();
|
||||||
|
|
||||||
|
|
@ -159,12 +160,12 @@ struct ValidPathInfo : UnkeyedValidPathInfo
|
||||||
* produced by one of the specified keys, or maxSigs if the path
|
* produced by one of the specified keys, or maxSigs if the path
|
||||||
* is content-addressed.
|
* is content-addressed.
|
||||||
*/
|
*/
|
||||||
size_t checkSignatures(const Store & store, const PublicKeys & publicKeys) const;
|
size_t checkSignatures(const StoreDirConfig & store, const PublicKeys & publicKeys) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify a single signature.
|
* Verify a single signature.
|
||||||
*/
|
*/
|
||||||
bool checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const;
|
bool checkSignature(const StoreDirConfig & store, const PublicKeys & publicKeys, const std::string & sig) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* References as store path basenames, including a self reference if it has one.
|
* References as store path basenames, including a self reference if it has one.
|
||||||
|
|
@ -178,7 +179,8 @@ struct ValidPathInfo : UnkeyedValidPathInfo
|
||||||
: UnkeyedValidPathInfo(info)
|
: UnkeyedValidPathInfo(info)
|
||||||
, path(path) {};
|
, path(path) {};
|
||||||
|
|
||||||
ValidPathInfo(const Store & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
|
ValidPathInfo(
|
||||||
|
const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash);
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::is_move_assignable_v<ValidPathInfo>);
|
static_assert(std::is_move_assignable_v<ValidPathInfo>);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
NarInfo::NarInfo(const Store & store, const std::string & s, const std::string & whence)
|
NarInfo::NarInfo(const StoreDirConfig & store, const std::string & s, const std::string & whence)
|
||||||
: ValidPathInfo(StorePath(StorePath::dummy), Hash(Hash::dummy)) // FIXME: hack
|
: ValidPathInfo(StorePath(StorePath::dummy), Hash(Hash::dummy)) // FIXME: hack
|
||||||
{
|
{
|
||||||
unsigned line = 1;
|
unsigned line = 1;
|
||||||
|
|
@ -102,7 +102,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NarInfo::to_string(const Store & store) const
|
std::string NarInfo::to_string(const StoreDirConfig & store) const
|
||||||
{
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
res += "StorePath: " + store.printStorePath(path) + "\n";
|
res += "StorePath: " + store.printStorePath(path) + "\n";
|
||||||
|
|
@ -130,7 +130,7 @@ std::string NarInfo::to_string(const Store & store) const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json NarInfo::toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const
|
nlohmann::json NarInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const
|
||||||
{
|
{
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ nlohmann::json NarInfo::toJSON(const Store & store, bool includeImpureInfo, Hash
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
NarInfo NarInfo::fromJSON(const Store & store, const StorePath & path, const nlohmann::json & json)
|
NarInfo NarInfo::fromJSON(const StoreDirConfig & store, const StorePath & path, const nlohmann::json & json)
|
||||||
{
|
{
|
||||||
using nlohmann::detail::value_t;
|
using nlohmann::detail::value_t;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ GENERATE_CMP_EXT(
|
||||||
me->sigs,
|
me->sigs,
|
||||||
me->ca);
|
me->ca);
|
||||||
|
|
||||||
std::string ValidPathInfo::fingerprint(const Store & store) const
|
std::string ValidPathInfo::fingerprint(const StoreDirConfig & store) const
|
||||||
{
|
{
|
||||||
if (narSize == 0)
|
if (narSize == 0)
|
||||||
throw Error(
|
throw Error(
|
||||||
|
|
@ -81,7 +81,7 @@ std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithRef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ValidPathInfo::isContentAddressed(const Store & store) const
|
bool ValidPathInfo::isContentAddressed(const StoreDirConfig & store) const
|
||||||
{
|
{
|
||||||
auto fullCaOpt = contentAddressWithReferences();
|
auto fullCaOpt = contentAddressWithReferences();
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ bool ValidPathInfo::isContentAddressed(const Store & store) const
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ValidPathInfo::checkSignatures(const Store & store, const PublicKeys & publicKeys) const
|
size_t ValidPathInfo::checkSignatures(const StoreDirConfig & store, const PublicKeys & publicKeys) const
|
||||||
{
|
{
|
||||||
if (isContentAddressed(store))
|
if (isContentAddressed(store))
|
||||||
return maxSigs;
|
return maxSigs;
|
||||||
|
|
@ -110,7 +110,8 @@ size_t ValidPathInfo::checkSignatures(const Store & store, const PublicKeys & pu
|
||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ValidPathInfo::checkSignature(const Store & store, const PublicKeys & publicKeys, const std::string & sig) const
|
bool ValidPathInfo::checkSignature(
|
||||||
|
const StoreDirConfig & store, const PublicKeys & publicKeys, const std::string & sig) const
|
||||||
{
|
{
|
||||||
return verifyDetached(fingerprint(store), sig, publicKeys);
|
return verifyDetached(fingerprint(store), sig, publicKeys);
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +125,7 @@ Strings ValidPathInfo::shortRefs() const
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidPathInfo::ValidPathInfo(
|
ValidPathInfo::ValidPathInfo(
|
||||||
const Store & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash)
|
const StoreDirConfig & store, std::string_view name, ContentAddressWithReferences && ca, Hash narHash)
|
||||||
: UnkeyedValidPathInfo(narHash)
|
: UnkeyedValidPathInfo(narHash)
|
||||||
, path(store.makeFixedOutputPathFromCA(name, ca))
|
, path(store.makeFixedOutputPathFromCA(name, ca))
|
||||||
{
|
{
|
||||||
|
|
@ -144,7 +145,8 @@ ValidPathInfo::ValidPathInfo(
|
||||||
std::move(ca).raw);
|
std::move(ca).raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json UnkeyedValidPathInfo::toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const
|
nlohmann::json
|
||||||
|
UnkeyedValidPathInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const
|
||||||
{
|
{
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
|
@ -176,7 +178,7 @@ nlohmann::json UnkeyedValidPathInfo::toJSON(const Store & store, bool includeImp
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const Store & store, const nlohmann::json & _json)
|
UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store, const nlohmann::json & _json)
|
||||||
{
|
{
|
||||||
UnkeyedValidPathInfo res{
|
UnkeyedValidPathInfo res{
|
||||||
Hash(Hash::dummy),
|
Hash(Hash::dummy),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue