mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Make reading and writing derivations store methods
This allows for different representations.
This commit is contained in:
parent
234f029940
commit
28b73cabcc
3 changed files with 31 additions and 7 deletions
|
|
@ -105,7 +105,7 @@ bool BasicDerivation::isBuiltin() const
|
|||
return builder.substr(0, 8) == "builtin:";
|
||||
}
|
||||
|
||||
StorePath writeDerivation(Store & store, const Derivation & drv, RepairFlag repair, bool readOnly)
|
||||
static auto infoForDerivation(Store & store, const Derivation & drv)
|
||||
{
|
||||
auto references = drv.inputSrcs;
|
||||
for (auto & i : drv.inputDrvs.map)
|
||||
|
|
@ -117,13 +117,32 @@ StorePath writeDerivation(Store & store, const Derivation & drv, RepairFlag repa
|
|||
auto contents = drv.unparse(store, false);
|
||||
auto hash = hashString(HashAlgorithm::SHA256, contents);
|
||||
auto ca = TextInfo{.hash = hash, .references = references};
|
||||
auto path = store.makeFixedOutputPathFromCA(suffix, ca);
|
||||
return std::tuple{
|
||||
suffix,
|
||||
contents,
|
||||
references,
|
||||
store.makeFixedOutputPathFromCA(suffix, ca),
|
||||
};
|
||||
}
|
||||
|
||||
if (readOnly || settings.readOnlyMode || (store.isValidPath(path) && !repair))
|
||||
StorePath writeDerivation(Store & store, const Derivation & drv, RepairFlag repair, bool readOnly)
|
||||
{
|
||||
if (readOnly || settings.readOnlyMode) {
|
||||
auto [_x, _y, _z, path] = infoForDerivation(store, drv);
|
||||
return path;
|
||||
} else
|
||||
return store.writeDerivation(drv, repair);
|
||||
}
|
||||
|
||||
StorePath Store::writeDerivation(const Derivation & drv, RepairFlag repair)
|
||||
{
|
||||
auto [suffix, contents, references, path] = infoForDerivation(*this, drv);
|
||||
|
||||
if (isValidPath(path) && !repair)
|
||||
return path;
|
||||
|
||||
StringSource s{contents};
|
||||
auto path2 = store.addToStoreFromDump(
|
||||
auto path2 = addToStoreFromDump(
|
||||
s,
|
||||
suffix,
|
||||
FileSerialisationMethod::Flat,
|
||||
|
|
|
|||
|
|
@ -778,15 +778,20 @@ public:
|
|||
*/
|
||||
Derivation derivationFromPath(const StorePath & drvPath);
|
||||
|
||||
/**
|
||||
* Write a derivation to the Nix store, and return its path.
|
||||
*/
|
||||
virtual StorePath writeDerivation(const Derivation & drv, RepairFlag repair = NoRepair);
|
||||
|
||||
/**
|
||||
* Read a derivation (which must already be valid).
|
||||
*/
|
||||
Derivation readDerivation(const StorePath & drvPath);
|
||||
virtual Derivation readDerivation(const StorePath & drvPath);
|
||||
|
||||
/**
|
||||
* Read a derivation from a potentially invalid path.
|
||||
*/
|
||||
Derivation readInvalidDerivation(const StorePath & drvPath);
|
||||
virtual Derivation readInvalidDerivation(const StorePath & drvPath);
|
||||
|
||||
/**
|
||||
* @param [out] out Place in here the set of all store paths in the
|
||||
|
|
|
|||
|
|
@ -1170,7 +1170,7 @@ std::optional<StorePath> Store::getBuildDerivationPath(const StorePath & path)
|
|||
// resolved derivation, so we need to get it first
|
||||
auto resolvedDrv = drv.tryResolve(*this);
|
||||
if (resolvedDrv)
|
||||
return writeDerivation(*this, *resolvedDrv, NoRepair, true);
|
||||
return ::nix::writeDerivation(*this, *resolvedDrv, NoRepair, true);
|
||||
}
|
||||
|
||||
return path;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue