mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-19 17:46:46 +02:00
Merge pull request #10149 from edolstra/use-flake-fingerprint
LockedFlake::getFingerprint(): Use Input::getFingerprint()
This commit is contained in:
commit
38b79da100
4 changed files with 24 additions and 11 deletions
|
@ -443,10 +443,10 @@ ref<eval_cache::EvalCache> openEvalCache(
|
||||||
EvalState & state,
|
EvalState & state,
|
||||||
std::shared_ptr<flake::LockedFlake> lockedFlake)
|
std::shared_ptr<flake::LockedFlake> lockedFlake)
|
||||||
{
|
{
|
||||||
auto fingerprint = lockedFlake->getFingerprint();
|
auto fingerprint = lockedFlake->getFingerprint(state.store);
|
||||||
return make_ref<nix::eval_cache::EvalCache>(
|
return make_ref<nix::eval_cache::EvalCache>(
|
||||||
evalSettings.useEvalCache && evalSettings.pureEval
|
evalSettings.useEvalCache && evalSettings.pureEval
|
||||||
? std::optional { std::cref(fingerprint) }
|
? fingerprint
|
||||||
: std::nullopt,
|
: std::nullopt,
|
||||||
state,
|
state,
|
||||||
[&state, lockedFlake]()
|
[&state, lockedFlake]()
|
||||||
|
|
|
@ -926,18 +926,17 @@ static RegisterPrimOp r4({
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Fingerprint LockedFlake::getFingerprint() const
|
std::optional<Fingerprint> LockedFlake::getFingerprint(ref<Store> store) const
|
||||||
{
|
{
|
||||||
|
if (lockFile.isUnlocked()) return std::nullopt;
|
||||||
|
|
||||||
|
auto fingerprint = flake.lockedRef.input.getFingerprint(store);
|
||||||
|
if (!fingerprint) return std::nullopt;
|
||||||
|
|
||||||
// FIXME: as an optimization, if the flake contains a lock file
|
// FIXME: as an optimization, if the flake contains a lock file
|
||||||
// and we haven't changed it, then it's sufficient to use
|
// and we haven't changed it, then it's sufficient to use
|
||||||
// flake.sourceInfo.storePath for the fingerprint.
|
// flake.sourceInfo.storePath for the fingerprint.
|
||||||
return hashString(HashAlgorithm::SHA256,
|
return hashString(HashAlgorithm::SHA256, fmt("%s;%s;%s", *fingerprint, flake.lockedRef.subdir, lockFile));
|
||||||
fmt("%s;%s;%d;%d;%s",
|
|
||||||
flake.path.to_string(),
|
|
||||||
flake.lockedRef.subdir,
|
|
||||||
flake.lockedRef.input.getRevCount().value_or(0),
|
|
||||||
flake.lockedRef.input.getLastModified().value_or(0),
|
|
||||||
lockFile));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Flake::~Flake() { }
|
Flake::~Flake() { }
|
||||||
|
|
|
@ -119,7 +119,7 @@ struct LockedFlake
|
||||||
*/
|
*/
|
||||||
std::map<ref<Node>, SourcePath> nodePaths;
|
std::map<ref<Node>, SourcePath> nodePaths;
|
||||||
|
|
||||||
Fingerprint getFingerprint() const;
|
std::optional<Fingerprint> getFingerprint(ref<Store> store) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LockFlags
|
struct LockFlags
|
||||||
|
|
|
@ -147,6 +147,20 @@ struct PathInputScheme : InputScheme
|
||||||
return {std::move(*storePath), input};
|
return {std::move(*storePath), input};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
|
||||||
|
{
|
||||||
|
/* If this path is in the Nix store, use the hash of the
|
||||||
|
store object and the subpath. */
|
||||||
|
auto path = getAbsPath(input);
|
||||||
|
try {
|
||||||
|
auto [storePath, subPath] = store->toStorePath(path.abs());
|
||||||
|
auto info = store->queryPathInfo(storePath);
|
||||||
|
return fmt("path:%s:%s", info->narHash.to_string(HashFormat::Base16, false), subPath);
|
||||||
|
} catch (Error &) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<ExperimentalFeature> experimentalFeature() const override
|
std::optional<ExperimentalFeature> experimentalFeature() const override
|
||||||
{
|
{
|
||||||
return Xp::Flakes;
|
return Xp::Flakes;
|
||||||
|
|
Loading…
Reference in a new issue