forked from lix-project/lix
Improve missing flake.nix error message
This commit is contained in:
parent
6960ee929d
commit
160ce18a0e
|
@ -48,7 +48,7 @@ LockFile::FlakeEntry readFlakeEntry(nlohmann::json json)
|
||||||
{
|
{
|
||||||
FlakeRef flakeRef(json["uri"]);
|
FlakeRef flakeRef(json["uri"]);
|
||||||
if (!flakeRef.isImmutable())
|
if (!flakeRef.isImmutable())
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef.to_string());
|
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef);
|
||||||
|
|
||||||
LockFile::FlakeEntry entry(flakeRef);
|
LockFile::FlakeEntry entry(flakeRef);
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ LockFile::FlakeEntry readFlakeEntry(nlohmann::json json)
|
||||||
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
|
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
|
||||||
FlakeRef flakeRef(i->value("uri", ""));
|
FlakeRef flakeRef(i->value("uri", ""));
|
||||||
if (!flakeRef.isImmutable())
|
if (!flakeRef.isImmutable())
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef.to_string());
|
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef);
|
||||||
entry.nonFlakeEntries.insert_or_assign(i.key(), flakeRef);
|
entry.nonFlakeEntries.insert_or_assign(i.key(), flakeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ LockFile readLockFile(const Path & path)
|
||||||
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
|
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
|
||||||
FlakeRef flakeRef(i->value("uri", ""));
|
FlakeRef flakeRef(i->value("uri", ""));
|
||||||
if (!flakeRef.isImmutable())
|
if (!flakeRef.isImmutable())
|
||||||
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef.to_string());
|
throw Error("requested to fetch FlakeRef '%s' purely, which is mutable", flakeRef);
|
||||||
lockFile.nonFlakeEntries.insert_or_assign(i.key(), flakeRef);
|
lockFile.nonFlakeEntries.insert_or_assign(i.key(), flakeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
|
||||||
std::vector<FlakeRef> pastSearches = {})
|
std::vector<FlakeRef> pastSearches = {})
|
||||||
{
|
{
|
||||||
if (registries.empty() && !flakeRef.isDirect())
|
if (registries.empty() && !flakeRef.isDirect())
|
||||||
throw Error("indirect flake reference '%s' is not allowed", flakeRef.to_string());
|
throw Error("indirect flake reference '%s' is not allowed", flakeRef);
|
||||||
|
|
||||||
for (std::shared_ptr<FlakeRegistry> registry : registries) {
|
for (std::shared_ptr<FlakeRegistry> registry : registries) {
|
||||||
auto i = registry->entries.find(flakeRef);
|
auto i = registry->entries.find(flakeRef);
|
||||||
|
@ -183,7 +183,7 @@ static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!flakeRef.isDirect())
|
if (!flakeRef.isDirect())
|
||||||
throw Error("could not resolve flake reference '%s'", flakeRef.to_string());
|
throw Error("could not resolve flake reference '%s'", flakeRef);
|
||||||
|
|
||||||
return flakeRef;
|
return flakeRef;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
|
||||||
impureIsAllowed ? state.getFlakeRegistries() : std::vector<std::shared_ptr<FlakeRegistry>>());
|
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.to_string());
|
throw Error("requested to fetch mutable flake '%s' in pure mode", fRef);
|
||||||
|
|
||||||
// This only downloads only one revision of the repo, not the entire history.
|
// This only downloads only one revision of the repo, not the entire history.
|
||||||
if (auto refData = std::get_if<FlakeRef::IsGitHub>(&fRef.data)) {
|
if (auto refData = std::get_if<FlakeRef::IsGitHub>(&fRef.data)) {
|
||||||
|
@ -277,8 +277,12 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
|
||||||
+ "/" + flake.sourceInfo.rev->to_string(Base16, false));
|
+ "/" + flake.sourceInfo.rev->to_string(Base16, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path flakeFile = sourceInfo.storePath + "/flake.nix";
|
||||||
|
if (!pathExists(flakeFile))
|
||||||
|
throw Error("source tree referenced by '%s' does not contain a 'flake.nix' file", flakeRef);
|
||||||
|
|
||||||
Value vInfo;
|
Value vInfo;
|
||||||
state.evalFile(sourceInfo.storePath + "/flake.nix", vInfo); // FIXME: symlink attack
|
state.evalFile(flakeFile, vInfo); // FIXME: symlink attack
|
||||||
|
|
||||||
state.forceAttrs(vInfo);
|
state.forceAttrs(vInfo);
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,12 @@ std::string FlakeRef::to_string() const
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef)
|
||||||
|
{
|
||||||
|
str << flakeRef.to_string();
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
bool FlakeRef::isImmutable() const
|
bool FlakeRef::isImmutable() const
|
||||||
{
|
{
|
||||||
return (bool) rev;
|
return (bool) rev;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
|
|
||||||
|
@ -173,4 +175,7 @@ struct FlakeRef
|
||||||
|
|
||||||
FlakeRef baseRef() const;
|
FlakeRef baseRef() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct CmdFlakeList : StoreCommand, MixEvalArgs
|
||||||
|
|
||||||
for (auto & registry : registries)
|
for (auto & registry : registries)
|
||||||
for (auto & entry : registry->entries)
|
for (auto & entry : registry->entries)
|
||||||
std::cout << entry.first.to_string() << " " << entry.second.to_string() << "\n";
|
std::cout << entry.first << " " << entry.second << "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ void printFlakeInfo(Flake & flake, bool json) {
|
||||||
std::cout << j.dump(4) << std::endl;
|
std::cout << j.dump(4) << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "ID: " << flake.id << "\n";
|
std::cout << "ID: " << flake.id << "\n";
|
||||||
std::cout << "URI: " << flake.sourceInfo.flakeRef.to_string() << "\n";
|
std::cout << "URI: " << flake.sourceInfo.flakeRef << "\n";
|
||||||
std::cout << "Description: " << flake.description << "\n";
|
std::cout << "Description: " << flake.description << "\n";
|
||||||
if (flake.sourceInfo.rev)
|
if (flake.sourceInfo.rev)
|
||||||
std::cout << "Revision: " << flake.sourceInfo.rev->to_string(Base16, false) << "\n";
|
std::cout << "Revision: " << flake.sourceInfo.rev->to_string(Base16, false) << "\n";
|
||||||
|
|
Loading…
Reference in a new issue