Skip to content
Merged
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
10 changes: 7 additions & 3 deletions src/libstore-test-support/include/nix/store/tests/protocol.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
namespace nix {

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 goldenMaster(std::string_view testStem) const override
{
return unitTestData / (std::string{testStem + ".bin"});
}

public:
Path storeDir = "/nix/store";
StoreDirConfig store{storeDir};
};

template<class Proto, const char * protocolDir>
Expand All @@ -34,7 +38,7 @@ public:
T got = ({
StringSource from{encoded};
Proto::template Serialise<T>::read(
*LibStoreTest::store,
this->store,
typename Proto::ReadConn{
.from = from,
.version = version,
Expand All @@ -54,7 +58,7 @@ public:
CharacterizationTest::writeTest(testStem, [&]() {
StringSink to;
Proto::template Serialise<T>::write(
*LibStoreTest::store,
this->store,
typename Proto::WriteConn{
.to = to,
.version = version,
Expand Down
4 changes: 2 additions & 2 deletions src/libstore-tests/common-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CommonProtoTest : public ProtoTest<CommonProto, commonProtoDir>
CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
T got = ({
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);
Expand All @@ -40,7 +40,7 @@ class CommonProtoTest : public ProtoTest<CommonProto, commonProtoDir>
{
CharacterizationTest::writeTest(testStem, [&]() -> std::string {
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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstore-tests/serve-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ VERSIONED_CHARACTERIZATION_TEST(
}),
({
ValidPathInfo info{
*LibStoreTest::store,
store,
"foo",
FixedOutputInfo{
.method = FileIngestionMethod::NixArchive,
Expand Down
2 changes: 1 addition & 1 deletion src/libstore-tests/worker-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ VERSIONED_CHARACTERIZATION_TEST(
}),
({
ValidPathInfo info{
*LibStoreTest::store,
store,
"foo",
FixedOutputInfo{
.method = FileIngestionMethod::NixArchive,
Expand Down
5 changes: 3 additions & 2 deletions src/libstore/build/derivation-building-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
StorePathSet expectedOutputPaths;
Expand Down Expand Up @@ -743,7 +743,8 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
#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;
if (hook == "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ struct DerivationBuilder;

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
* obtaining the outputs) will not be attempted, so it is the calling goal's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ struct InitialOutput
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.
*/
std::string showKnownOutputs(Store & store, const Derivation & drv);
std::string showKnownOutputs(const StoreDirConfig & store, const Derivation & drv);

} // namespace nix
12 changes: 6 additions & 6 deletions src/libstore/include/nix/store/nar-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace nix {

class Store;
struct StoreDirConfig;

struct NarInfo : ValidPathInfo
{
Expand All @@ -18,7 +18,7 @@ struct NarInfo : ValidPathInfo

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)
{
}
Expand All @@ -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;
// TODO libc++ 16 (used by darwin) missing `std::optional::operator <=>`, can't do yet
// 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;
static NarInfo fromJSON(const Store & store, const StorePath & path, const nlohmann::json & json);
nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const override;
static NarInfo fromJSON(const StoreDirConfig & store, const StorePath & path, const nlohmann::json & json);
};

} // namespace nix
16 changes: 9 additions & 7 deletions src/libstore/include/nix/store/path-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace nix {

class Store;
struct StoreDirConfig;

struct SubstitutablePathInfo
{
Expand Down Expand Up @@ -116,8 +117,8 @@ struct UnkeyedValidPathInfo
* @param includeImpureInfo If true, variable elements such as the
* registration time are included.
*/
virtual nlohmann::json toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const;
static UnkeyedValidPathInfo fromJSON(const Store & store, const nlohmann::json & json);
virtual nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const;
static UnkeyedValidPathInfo fromJSON(const StoreDirConfig & store, const nlohmann::json & json);
};

struct ValidPathInfo : UnkeyedValidPathInfo
Expand All @@ -135,7 +136,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo
* speaking superfluous, but might prevent endless/excessive data
* 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 std::vector<std::unique_ptr<Signer>> & signers);
Expand All @@ -150,7 +151,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo
/**
* @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();

Expand All @@ -159,12 +160,12 @@ struct ValidPathInfo : UnkeyedValidPathInfo
* produced by one of the specified keys, or maxSigs if the path
* 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.
*/
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.
Expand All @@ -178,7 +179,8 @@ struct ValidPathInfo : UnkeyedValidPathInfo
: UnkeyedValidPathInfo(info)
, 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>);
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/nar-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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
{
unsigned line = 1;
Expand Down Expand Up @@ -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;
res += "StorePath: " + store.printStorePath(path) + "\n";
Expand Down Expand Up @@ -130,7 +130,7 @@ std::string NarInfo::to_string(const Store & store) const
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;

Expand All @@ -150,7 +150,7 @@ nlohmann::json NarInfo::toJSON(const Store & store, bool includeImpureInfo, Hash
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;

Expand Down
16 changes: 9 additions & 7 deletions src/libstore/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GENERATE_CMP_EXT(
me->sigs,
me->ca);

std::string ValidPathInfo::fingerprint(const Store & store) const
std::string ValidPathInfo::fingerprint(const StoreDirConfig & store) const
{
if (narSize == 0)
throw Error(
Expand Down Expand Up @@ -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();

Expand All @@ -98,7 +98,7 @@ bool ValidPathInfo::isContentAddressed(const Store & store) const
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))
return maxSigs;
Expand All @@ -110,7 +110,8 @@ size_t ValidPathInfo::checkSignatures(const Store & store, const PublicKeys & pu
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);
}
Expand All @@ -124,7 +125,7 @@ Strings ValidPathInfo::shortRefs() const
}

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)
, path(store.makeFixedOutputPathFromCA(name, ca))
{
Expand All @@ -144,7 +145,8 @@ ValidPathInfo::ValidPathInfo(
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;

Expand Down Expand Up @@ -176,7 +178,7 @@ nlohmann::json UnkeyedValidPathInfo::toJSON(const Store & store, bool includeImp
return jsonObject;
}

UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const Store & store, const nlohmann::json & _json)
UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store, const nlohmann::json & _json)
{
UnkeyedValidPathInfo res{
Hash(Hash::dummy),
Expand Down
Loading