From b9f93e73869fcbf6e4b2170c824cef7abc465670 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Jan 2020 00:13:37 +0100 Subject: [PATCH] Check LockedInput::computeStorePath() --- src/libexpr/flake/flake.cc | 4 ++++ src/libexpr/flake/lockfile.cc | 4 ++-- src/libexpr/flake/lockfile.hh | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index a8f05efb6..21d98089f 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -584,6 +584,8 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V throw Error("the content hash of flake '%s' doesn't match the hash recorded in the referring lockfile", lazyInput->lockedInput.ref); + assert(flake.sourceInfo->storePath == lazyInput->lockedInput.computeStorePath(*state.store)); + callFlake(state, flake, lazyInput->lockedInput, v); } else { FlakeCache flakeCache; @@ -593,6 +595,8 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V throw Error("the content hash of repository '%s' doesn't match the hash recorded in the referring lockfile", lazyInput->lockedInput.ref); + assert(sourceInfo.storePath == lazyInput->lockedInput.computeStorePath(*state.store)); + state.mkAttrs(v, 8); assert(state.store->isValidPath(sourceInfo.storePath)); diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index edb7628fd..2696d4710 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -25,9 +25,9 @@ nlohmann::json LockedInput::toJson() const return json; } -Path LockedInput::computeStorePath(Store & store) const +StorePath LockedInput::computeStorePath(Store & store) const { - return store.printStorePath(store.makeFixedOutputPath(true, narHash, "source")); + return store.makeFixedOutputPath(true, narHash, "source"); } LockedInputs::LockedInputs(const nlohmann::json & json) diff --git a/src/libexpr/flake/lockfile.hh b/src/libexpr/flake/lockfile.hh index ff1181d13..a9710524b 100644 --- a/src/libexpr/flake/lockfile.hh +++ b/src/libexpr/flake/lockfile.hh @@ -6,6 +6,7 @@ namespace nix { class Store; +struct StorePath; } namespace nix::flake { @@ -53,7 +54,7 @@ struct LockedInput : LockedInputs nlohmann::json toJson() const; - Path computeStorePath(Store & store) const; + StorePath computeStorePath(Store & store) const; }; /* An entire lock file. Note that this cannot be a FlakeInput for the