aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-04-16 16:18:47 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-04-16 16:18:47 +0200
commit260527a90ccc23461cdc4ad73970dd4e0b2e5239 (patch)
treed42a19cf9e536d82f773c1c994e56d6668407a9d /src/libexpr
parent3c28cb1b8ff586421ed9e37cef383af0486445cb (diff)
Use the lock file
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops/flake.cc20
-rw-r--r--src/libexpr/primops/flake.hh5
2 files changed, 15 insertions, 10 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index 23406327e..193b521a3 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -106,7 +106,7 @@ nlohmann::json flakeEntryToJson(const LockFile::FlakeEntry & entry)
for (auto & x : entry.nonFlakeEntries)
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
for (auto & x : entry.flakeEntries)
- json["requires"][x.first] = flakeEntryToJson(x.second);
+ json["requires"][x.first.to_string()] = flakeEntryToJson(x.second);
return json;
}
@@ -119,7 +119,7 @@ void writeLockFile(const LockFile & lockFile, const Path & path)
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
json["requires"] = nlohmann::json::object();
for (auto & x : lockFile.flakeEntries)
- json["requires"][x.first] = flakeEntryToJson(x.second);
+ json["requires"][x.first.to_string()] = flakeEntryToJson(x.second);
createDirs(dirOf(path));
writeFile(path, json.dump(4)); // '4' = indentation in json file
}
@@ -312,10 +312,6 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
} else
throw Error("flake lacks attribute 'provides'");
- Path lockFile = sourceInfo.storePath + "/flake.lock"; // FIXME: symlink attack
-
- flake.lockFile = readLockFile(lockFile);
-
return flake;
}
@@ -355,13 +351,23 @@ Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef,
{
Flake flake = getFlake(state, topRef,
registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake));
+
+ LockFile lockFile;
+
+ if (isTopFlake)
+ lockFile = readLockFile(flake.sourceInfo.storePath + "/flake.lock"); // FIXME: symlink attack
+
Dependencies deps(flake);
for (auto & nonFlakeInfo : flake.nonFlakeRequires)
deps.nonFlakeDeps.push_back(getNonFlake(state, nonFlakeInfo.second, nonFlakeInfo.first));
- for (auto & newFlakeRef : flake.requires)
+ for (auto newFlakeRef : flake.requires) {
+ auto i = lockFile.flakeEntries.find(newFlakeRef);
+ if (i != lockFile.flakeEntries.end()) newFlakeRef = i->second.ref;
+ // FIXME: propagate lockFile downwards
deps.flakeDeps.push_back(resolveFlake(state, newFlakeRef, registryAccess, false));
+ }
return deps;
}
diff --git a/src/libexpr/primops/flake.hh b/src/libexpr/primops/flake.hh
index f93796660..85f4fdf9f 100644
--- a/src/libexpr/primops/flake.hh
+++ b/src/libexpr/primops/flake.hh
@@ -18,12 +18,12 @@ struct LockFile
struct FlakeEntry
{
FlakeRef ref;
- std::map<FlakeId, FlakeEntry> flakeEntries;
+ std::map<FlakeRef, FlakeEntry> flakeEntries;
std::map<FlakeId, FlakeRef> nonFlakeEntries;
FlakeEntry(const FlakeRef & flakeRef) : ref(flakeRef) {};
};
- std::map<FlakeId, FlakeEntry> flakeEntries;
+ std::map<FlakeRef, FlakeEntry> flakeEntries;
std::map<FlakeId, FlakeRef> nonFlakeEntries;
};
@@ -54,7 +54,6 @@ struct Flake
std::string description;
FlakeSourceInfo sourceInfo;
std::vector<FlakeRef> requires;
- LockFile lockFile;
std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
Value * vProvides; // FIXME: gc
Flake(const FlakeRef & flakeRef, FlakeSourceInfo && sourceInfo)