1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-11 19:41:04 +01:00

Make storeDir a part of UnkeyedValidPathInfo

The previous commit hacked it into the output of `nix path-info --json`,
this cleans that up my making it an actual field of that data type, and
part of the canonical JSON serializers for it (and `ValidPathInfo` and
`NarInfo`).

Beyond cleaning up the JSON code, this also opens the doors to things
like:

- Binary caches that contain store objects that don't all belong in the
  same store directory

- Relocatable store objects which carefully don't mention any store
  directory by absolute path, and instead use relative paths for
  anything. (#9549)
This commit is contained in:
John Ericson 2025-12-03 20:20:21 -05:00
parent 1ad13a1423
commit f9089deb20
36 changed files with 111 additions and 29 deletions

View file

@ -20,10 +20,16 @@ PathInfoJsonFormat parsePathInfoJsonFormat(uint64_t version)
}
}
UnkeyedValidPathInfo::UnkeyedValidPathInfo(const StoreDirConfig & store, Hash narHash)
: UnkeyedValidPathInfo{store.storeDir, narHash}
{
}
GENERATE_CMP_EXT(
,
std::weak_ordering,
UnkeyedValidPathInfo,
me->storeDir,
me->deriver,
me->narHash,
me->references,
@ -141,7 +147,7 @@ ValidPathInfo ValidPathInfo::makeFromCA(
{
ValidPathInfo res{
store.makeFixedOutputPathFromCA(name, ca),
narHash,
UnkeyedValidPathInfo(store, narHash),
};
res.ca = ContentAddress{
.method = ca.getMethod(),
@ -173,6 +179,8 @@ UnkeyedValidPathInfo::toJSON(const StoreDirConfig * store, bool includeImpureInf
jsonObject["version"] = format;
jsonObject["storeDir"] = storeDir;
jsonObject["narHash"] = format == PathInfoJsonFormat::V1
? static_cast<json>(narHash.to_string(HashFormat::SRI, true))
: static_cast<json>(narHash);
@ -213,10 +221,6 @@ UnkeyedValidPathInfo::toJSON(const StoreDirConfig * store, bool includeImpureInf
UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig * store, const nlohmann::json & _json)
{
UnkeyedValidPathInfo res{
Hash(Hash::dummy),
};
auto & json = getObject(_json);
PathInfoJsonFormat format = PathInfoJsonFormat::V1;
@ -226,10 +230,20 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig * store
if (format == PathInfoJsonFormat::V1)
assert(store);
if (format == PathInfoJsonFormat::V1)
res.narHash = Hash::parseSRI(getString(valueAt(json, "narHash")));
else
res.narHash = valueAt(json, "narHash");
UnkeyedValidPathInfo res{
[&] {
if (auto * rawStoreDir = optionalValueAt(json, "storeDir"))
return getString(*rawStoreDir);
else if (format == PathInfoJsonFormat::V1)
return store->storeDir;
else
throw Error("'storeDir' field is required in path info JSON format version 2");
}(),
[&] {
return format == PathInfoJsonFormat::V1 ? Hash::parseSRI(getString(valueAt(json, "narHash")))
: Hash(valueAt(json, "narHash"));
}(),
};
res.narSize = getUnsigned(valueAt(json, "narSize"));