WIP: still need to adapt flakeref parsing
This commit is contained in:
parent
4588a6ff3c
commit
eba85e2367
|
@ -194,11 +194,8 @@ static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const
|
||||||
return flakeRef;
|
return flakeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bool impureIsAllowed = false)
|
static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef fRef, bool impureIsAllowed = false)
|
||||||
{
|
{
|
||||||
FlakeRef fRef = lookupFlake(state, flakeRef,
|
|
||||||
impureIsAllowed ? state.getFlakeRegistries() : std::vector<std::shared_ptr<FlakeRegistry>>());
|
|
||||||
|
|
||||||
if (evalSettings.pureEval && !impureIsAllowed && !fRef.isImmutable())
|
if (evalSettings.pureEval && !impureIsAllowed && !fRef.isImmutable())
|
||||||
throw Error("requested to fetch mutable flake '%s' in pure mode", fRef);
|
throw Error("requested to fetch mutable flake '%s' in pure mode", fRef);
|
||||||
|
|
||||||
|
@ -266,26 +263,31 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
|
||||||
// This will return the flake which corresponds to a given FlakeRef. The lookupFlake is done within this function.
|
// This will return the flake which corresponds to a given FlakeRef. The lookupFlake is done within this function.
|
||||||
Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowed = false)
|
Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowed = false)
|
||||||
{
|
{
|
||||||
FlakeSourceInfo sourceInfo = fetchFlake(state, flakeRef, impureIsAllowed);
|
FlakeRef resolvedRef = lookupFlake(state, flakeRef,
|
||||||
|
impureIsAllowed ? state.getFlakeRegistries() : std::vector<std::shared_ptr<FlakeRegistry>>());
|
||||||
|
|
||||||
|
FlakeSourceInfo sourceInfo = fetchFlake(state, resolvedRef, impureIsAllowed);
|
||||||
debug("got flake source '%s' with revision %s",
|
debug("got flake source '%s' with revision %s",
|
||||||
sourceInfo.storePath, sourceInfo.rev.value_or(Hash(htSHA1)).to_string(Base16, false));
|
sourceInfo.storePath, sourceInfo.rev.value_or(Hash(htSHA1)).to_string(Base16, false));
|
||||||
|
|
||||||
|
resolvedRef = sourceInfo.flakeRef; // `resolvedRef` is now immutable
|
||||||
|
|
||||||
state.store->assertStorePath(sourceInfo.storePath);
|
state.store->assertStorePath(sourceInfo.storePath);
|
||||||
|
|
||||||
if (state.allowedPaths)
|
if (state.allowedPaths)
|
||||||
state.allowedPaths->insert(sourceInfo.storePath);
|
state.allowedPaths->insert(sourceInfo.storePath);
|
||||||
|
|
||||||
Flake flake(flakeRef, std::move(sourceInfo));
|
Flake flake(resolvedRef, std::move(sourceInfo));
|
||||||
if (std::get_if<FlakeRef::IsGitHub>(&flakeRef.data)) {
|
if (std::get_if<FlakeRef::IsGitHub>(&resolvedRef.data)) {
|
||||||
// FIXME: ehm?
|
// FIXME: ehm?
|
||||||
if (flake.sourceInfo.rev)
|
if (flake.sourceInfo.rev)
|
||||||
flake.ref = FlakeRef(flakeRef.baseRef().to_string()
|
flake.ref = FlakeRef(resolvedRef.baseRef().to_string()
|
||||||
+ "/" + flake.sourceInfo.rev->to_string(Base16, false));
|
+ "/" + flake.sourceInfo.rev->to_string(Base16, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
Path flakeFile = sourceInfo.storePath + "/flake.nix";
|
Path flakeFile = sourceInfo.storePath + resolvedRef.subdir + "/flake.nix";
|
||||||
if (!pathExists(flakeFile))
|
if (!pathExists(flakeFile))
|
||||||
throw Error("source tree referenced by '%s' does not contain a 'flake.nix' file", flakeRef);
|
throw Error("source tree referenced by '%s' does not contain a 'flake.nix' file", resolvedRef);
|
||||||
|
|
||||||
Value vInfo;
|
Value vInfo;
|
||||||
state.evalFile(flakeFile, vInfo); // FIXME: symlink attack
|
state.evalFile(flakeFile, vInfo); // FIXME: symlink attack
|
||||||
|
|
|
@ -139,6 +139,7 @@ std::string FlakeRef::to_string() const
|
||||||
|
|
||||||
string += (ref ? "/" + *ref : "") +
|
string += (ref ? "/" + *ref : "") +
|
||||||
(rev ? "/" + rev->to_string(Base16, false) : "");
|
(rev ? "/" + rev->to_string(Base16, false) : "");
|
||||||
|
if (subdir != "") string += "?dir=" + subdir;
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace nix {
|
||||||
https://example.org/my/repo.git
|
https://example.org/my/repo.git
|
||||||
https://example.org/my/repo.git?ref=release-1.2.3
|
https://example.org/my/repo.git?ref=release-1.2.3
|
||||||
https://example.org/my/repo.git?rev=e72daba8250068216d79d2aeef40d4d95aff6666
|
https://example.org/my/repo.git?rev=e72daba8250068216d79d2aeef40d4d95aff6666
|
||||||
git://github.com/edolstra/dwarffs.git\?ref=flake\&rev=2efca4bc9da70fb001b26c3dc858c6397d3c4817
|
git://github.com/edolstra/dwarffs.git?ref=flake&rev=2efca4bc9da70fb001b26c3dc858c6397d3c4817
|
||||||
|
|
||||||
* /path.git(\?attr(&attr)*)?
|
* /path.git(\?attr(&attr)*)?
|
||||||
|
|
||||||
|
@ -144,17 +144,18 @@ struct FlakeRef
|
||||||
|
|
||||||
std::optional<std::string> ref;
|
std::optional<std::string> ref;
|
||||||
std::optional<Hash> rev;
|
std::optional<Hash> rev;
|
||||||
|
Path subdir = ""; // This is a relative path pointing at the flake.nix file's directory, relative to the git root.
|
||||||
|
|
||||||
bool operator<(const FlakeRef & flakeRef) const
|
bool operator<(const FlakeRef & flakeRef) const
|
||||||
{
|
{
|
||||||
return std::make_tuple(this->data, ref, rev) <
|
return std::make_tuple(data, ref, rev, subdir) <
|
||||||
std::make_tuple(flakeRef.data, flakeRef.ref, flakeRef.rev);
|
std::make_tuple(flakeRef.data, flakeRef.ref, flakeRef.rev, subdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const FlakeRef & flakeRef) const
|
bool operator==(const FlakeRef & flakeRef) const
|
||||||
{
|
{
|
||||||
return std::make_tuple(this->data, ref, rev) ==
|
return std::make_tuple(data, ref, rev, subdir) ==
|
||||||
std::make_tuple(flakeRef.data, flakeRef.ref, flakeRef.rev);
|
std::make_tuple(flakeRef.data, flakeRef.ref, flakeRef.rev, flakeRef.subdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a flake URI.
|
// Parse a flake URI.
|
||||||
|
|
Loading…
Reference in a new issue