forked from lix-project/lix
Use the lock file
This commit is contained in:
parent
3c28cb1b8f
commit
260527a90c
|
@ -106,7 +106,7 @@ nlohmann::json flakeEntryToJson(const LockFile::FlakeEntry & entry)
|
||||||
for (auto & x : entry.nonFlakeEntries)
|
for (auto & x : entry.nonFlakeEntries)
|
||||||
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
|
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
|
||||||
for (auto & x : entry.flakeEntries)
|
for (auto & x : entry.flakeEntries)
|
||||||
json["requires"][x.first] = flakeEntryToJson(x.second);
|
json["requires"][x.first.to_string()] = flakeEntryToJson(x.second);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ void writeLockFile(const LockFile & lockFile, const Path & path)
|
||||||
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
|
json["nonFlakeRequires"][x.first]["uri"] = x.second.to_string();
|
||||||
json["requires"] = nlohmann::json::object();
|
json["requires"] = nlohmann::json::object();
|
||||||
for (auto & x : lockFile.flakeEntries)
|
for (auto & x : lockFile.flakeEntries)
|
||||||
json["requires"][x.first] = flakeEntryToJson(x.second);
|
json["requires"][x.first.to_string()] = flakeEntryToJson(x.second);
|
||||||
createDirs(dirOf(path));
|
createDirs(dirOf(path));
|
||||||
writeFile(path, json.dump(4)); // '4' = indentation in json file
|
writeFile(path, json.dump(4)); // '4' = indentation in json file
|
||||||
}
|
}
|
||||||
|
@ -312,10 +312,6 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
|
||||||
} else
|
} else
|
||||||
throw Error("flake lacks attribute 'provides'");
|
throw Error("flake lacks attribute 'provides'");
|
||||||
|
|
||||||
Path lockFile = sourceInfo.storePath + "/flake.lock"; // FIXME: symlink attack
|
|
||||||
|
|
||||||
flake.lockFile = readLockFile(lockFile);
|
|
||||||
|
|
||||||
return flake;
|
return flake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,13 +351,23 @@ Dependencies resolveFlake(EvalState & state, const FlakeRef & topRef,
|
||||||
{
|
{
|
||||||
Flake flake = getFlake(state, topRef,
|
Flake flake = getFlake(state, topRef,
|
||||||
registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake));
|
registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake));
|
||||||
|
|
||||||
|
LockFile lockFile;
|
||||||
|
|
||||||
|
if (isTopFlake)
|
||||||
|
lockFile = readLockFile(flake.sourceInfo.storePath + "/flake.lock"); // FIXME: symlink attack
|
||||||
|
|
||||||
Dependencies deps(flake);
|
Dependencies deps(flake);
|
||||||
|
|
||||||
for (auto & nonFlakeInfo : flake.nonFlakeRequires)
|
for (auto & nonFlakeInfo : flake.nonFlakeRequires)
|
||||||
deps.nonFlakeDeps.push_back(getNonFlake(state, nonFlakeInfo.second, nonFlakeInfo.first));
|
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));
|
deps.flakeDeps.push_back(resolveFlake(state, newFlakeRef, registryAccess, false));
|
||||||
|
}
|
||||||
|
|
||||||
return deps;
|
return deps;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ struct LockFile
|
||||||
struct FlakeEntry
|
struct FlakeEntry
|
||||||
{
|
{
|
||||||
FlakeRef ref;
|
FlakeRef ref;
|
||||||
std::map<FlakeId, FlakeEntry> flakeEntries;
|
std::map<FlakeRef, FlakeEntry> flakeEntries;
|
||||||
std::map<FlakeId, FlakeRef> nonFlakeEntries;
|
std::map<FlakeId, FlakeRef> nonFlakeEntries;
|
||||||
FlakeEntry(const FlakeRef & flakeRef) : ref(flakeRef) {};
|
FlakeEntry(const FlakeRef & flakeRef) : ref(flakeRef) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<FlakeId, FlakeEntry> flakeEntries;
|
std::map<FlakeRef, FlakeEntry> flakeEntries;
|
||||||
std::map<FlakeId, FlakeRef> nonFlakeEntries;
|
std::map<FlakeId, FlakeRef> nonFlakeEntries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ struct Flake
|
||||||
std::string description;
|
std::string description;
|
||||||
FlakeSourceInfo sourceInfo;
|
FlakeSourceInfo sourceInfo;
|
||||||
std::vector<FlakeRef> requires;
|
std::vector<FlakeRef> requires;
|
||||||
LockFile lockFile;
|
|
||||||
std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
|
std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
|
||||||
Value * vProvides; // FIXME: gc
|
Value * vProvides; // FIXME: gc
|
||||||
Flake(const FlakeRef & flakeRef, FlakeSourceInfo && sourceInfo)
|
Flake(const FlakeRef & flakeRef, FlakeSourceInfo && sourceInfo)
|
||||||
|
|
Loading…
Reference in a new issue