aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-18 21:17:27 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-09-18 21:57:57 +0200
commitc67407172d8383394f4962ad177c84bf04529e5e (patch)
tree6dab718a9dbda0e13c2ceab07521449edd02f98c /src/libexpr/flake
parent092ee246277c76cd80f34088911419058e8b0f2f (diff)
Record original flakerefs in the lock file again
If 'input.<name>.uri' changes, then the entry in the lockfile for input <name> should be considered stale. Also print some messages when lock file entries are added/updated.
Diffstat (limited to 'src/libexpr/flake')
-rw-r--r--src/libexpr/flake/flake.cc43
-rw-r--r--src/libexpr/flake/flake.hh2
-rw-r--r--src/libexpr/flake/lockfile.cc6
-rw-r--r--src/libexpr/flake/lockfile.hh6
4 files changed, 38 insertions, 19 deletions
diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc
index 050e65259..accdb4194 100644
--- a/src/libexpr/flake/flake.cc
+++ b/src/libexpr/flake/flake.cc
@@ -205,8 +205,10 @@ static void expectType(EvalState & state, ValueType type,
showType(type), showType(value.type), pos);
}
-Flake getFlake(EvalState & state, const FlakeRef & flakeRef)
+Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup)
{
+ auto flakeRef = maybeLookupFlake(state, originalRef, allowLookup);
+
SourceInfo sourceInfo = fetchFlake(state, flakeRef);
debug("got flake source '%s' with flakeref %s", sourceInfo.storePath, sourceInfo.resolvedRef.to_string());
@@ -223,7 +225,7 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef)
if (!isInDir(realFlakeFile, state.store->toRealPath(sourceInfo.storePath)))
throw Error("'flake.nix' file of flake '%s' escapes from '%s'", resolvedRef, sourceInfo.storePath);
- Flake flake(flakeRef, sourceInfo);
+ Flake flake(originalRef, sourceInfo);
if (!pathExists(realFlakeFile))
throw Error("source tree referenced by '%s' does not contain a '%s/flake.nix' file", resolvedRef, resolvedRef.subdir);
@@ -358,6 +360,7 @@ bool allowedToUseRegistries(HandleLockFile handle, bool isTopRef)
Note that this is lazy: we only recursively fetch inputs that are
not in the lockfile yet. */
static std::pair<Flake, LockedInput> updateLocks(
+ const std::string & inputPath,
EvalState & state,
const Flake & flake,
HandleLockFile handleLockFile,
@@ -366,23 +369,36 @@ static std::pair<Flake, LockedInput> updateLocks(
{
LockedInput newEntry(
flake.sourceInfo.resolvedRef,
+ flake.originalRef,
flake.sourceInfo.narHash);
for (auto & [id, input] : flake.inputs) {
+ auto inputPath2 = (inputPath.empty() ? "" : inputPath + "/") + id;
auto i = oldEntry.inputs.find(id);
- if (i != oldEntry.inputs.end()) {
+ if (i != oldEntry.inputs.end() && i->second.originalRef == input.ref) {
newEntry.inputs.insert_or_assign(id, i->second);
} else {
if (handleLockFile == AllPure || handleLockFile == TopRefUsesRegistries)
throw Error("cannot update flake input '%s' in pure mode", id);
- if (input.isFlake)
+ if (input.isFlake) {
+ auto actualInput = getFlake(state, input.ref,
+ allowedToUseRegistries(handleLockFile, false));
+ if (i == oldEntry.inputs.end())
+ printMsg(lvlWarn, "mapped flake input '%s' to '%s'",
+ inputPath2, actualInput.sourceInfo.resolvedRef);
+ else
+ printMsg(lvlWarn, "updated flake input '%s' from '%s' to '%s'",
+ inputPath2, i->second.originalRef, actualInput.sourceInfo.resolvedRef);
+ newEntry.inputs.insert_or_assign(id,
+ updateLocks(inputPath2, state, actualInput, handleLockFile, {}, false).second);
+ } else {
+ auto sourceInfo = getNonFlake(state,
+ maybeLookupFlake(state, input.ref,
+ allowedToUseRegistries(handleLockFile, false)));
+ printMsg(lvlWarn, "mapped flake input '%s' to '%s'",
+ inputPath2, sourceInfo.resolvedRef);
newEntry.inputs.insert_or_assign(id,
- updateLocks(state,
- getFlake(state, maybeLookupFlake(state, input.ref, allowedToUseRegistries(handleLockFile, false))),
- handleLockFile, {}, false).second);
- else {
- auto sourceInfo = getNonFlake(state, maybeLookupFlake(state, input.ref, allowedToUseRegistries(handleLockFile, false)));
- newEntry.inputs.insert_or_assign(id, LockedInput(sourceInfo.resolvedRef, sourceInfo.narHash));
+ LockedInput(sourceInfo.resolvedRef, input.ref, sourceInfo.narHash));
}
}
}
@@ -394,7 +410,8 @@ static std::pair<Flake, LockedInput> updateLocks(
and optionally write it to file, it the flake is writable. */
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLockFile handleLockFile)
{
- auto flake = getFlake(state, maybeLookupFlake(state, topRef, allowedToUseRegistries(handleLockFile, true)));
+ auto flake = getFlake(state, topRef,
+ allowedToUseRegistries(handleLockFile, true));
LockFile oldLockFile;
@@ -407,7 +424,7 @@ ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLoc
}
LockFile lockFile(updateLocks(
- state, flake, handleLockFile, oldLockFile, true).second);
+ "", state, flake, handleLockFile, oldLockFile, true).second);
if (!(lockFile == oldLockFile)) {
if (allowedToWrite(handleLockFile)) {
@@ -476,7 +493,7 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V
assert(lazyInput->lockedInput.ref.isImmutable());
if (lazyInput->isFlake) {
- auto flake = getFlake(state, lazyInput->lockedInput.ref);
+ auto flake = getFlake(state, lazyInput->lockedInput.ref, false);
if (flake.sourceInfo.narHash != lazyInput->lockedInput.narHash)
throw Error("the content hash of flake '%s' doesn't match the hash recorded in the referring lockfile", flake.sourceInfo.resolvedRef);
diff --git a/src/libexpr/flake/flake.hh b/src/libexpr/flake/flake.hh
index 8f05e9799..b366e650b 100644
--- a/src/libexpr/flake/flake.hh
+++ b/src/libexpr/flake/flake.hh
@@ -78,7 +78,7 @@ struct Flake
: originalRef(origRef), sourceInfo(sourceInfo) {};
};
-Flake getFlake(EvalState &, const FlakeRef &);
+Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool allowLookup);
/* If 'allowLookup' is true, then resolve 'flakeRef' using the
registries. */
diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc
index f32d752f9..039b7a7c1 100644
--- a/src/libexpr/flake/lockfile.cc
+++ b/src/libexpr/flake/lockfile.cc
@@ -6,6 +6,7 @@ namespace nix::flake {
LockedInput::LockedInput(const nlohmann::json & json)
: LockedInputs(json)
, ref(json["uri"])
+ , originalRef(json["originalUri"])
, narHash(Hash((std::string) json["narHash"]))
{
if (!ref.isImmutable())
@@ -16,6 +17,7 @@ nlohmann::json LockedInput::toJson() const
{
auto json = LockedInputs::toJson();
json["uri"] = ref.to_string();
+ json["originalUri"] = originalRef.to_string();
json["narHash"] = narHash.to_string(SRI);
return json;
}
@@ -54,7 +56,7 @@ bool LockedInputs::isDirty() const
nlohmann::json LockFile::toJson() const
{
auto json = LockedInputs::toJson();
- json["version"] = 2;
+ json["version"] = 3;
return json;
}
@@ -64,7 +66,7 @@ LockFile LockFile::read(const Path & path)
auto json = nlohmann::json::parse(readFile(path));
auto version = json.value("version", 0);
- if (version != 2)
+ if (version != 3)
throw Error("lock file '%s' has unsupported version %d", path, version);
return LockFile(json);
diff --git a/src/libexpr/flake/lockfile.hh b/src/libexpr/flake/lockfile.hh
index 084eabc1a..ab81eac8b 100644
--- a/src/libexpr/flake/lockfile.hh
+++ b/src/libexpr/flake/lockfile.hh
@@ -30,11 +30,11 @@ struct LockedInputs
/* Lock file information about a flake input. */
struct LockedInput : LockedInputs
{
- FlakeRef ref;
+ FlakeRef ref, originalRef;
Hash narHash;
- LockedInput(const FlakeRef & ref, const Hash & narHash)
- : ref(ref), narHash(narHash)
+ LockedInput(const FlakeRef & ref, const FlakeRef & originalRef, const Hash & narHash)
+ : ref(ref), originalRef(originalRef), narHash(narHash)
{
assert(ref.isImmutable());
};