aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-04-19 11:43:56 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-04-19 11:43:56 +0200
commit160ce18a0e9f569f94e6b0cb8e47bd4008a9fea2 (patch)
tree994016383b276f0ebb4369b46f4a5bddcadcfe4f /src/libexpr
parent6960ee929dcf95c24e0db761fd4bc46c3749abb2 (diff)
Improve missing flake.nix error message
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops/flake.cc18
-rw-r--r--src/libexpr/primops/flakeref.cc6
-rw-r--r--src/libexpr/primops/flakeref.hh5
3 files changed, 22 insertions, 7 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index c5e646412..720e157c6 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -48,7 +48,7 @@ LockFile::FlakeEntry readFlakeEntry(nlohmann::json json)
{
FlakeRef flakeRef(json["uri"]);
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);
@@ -57,7 +57,7 @@ LockFile::FlakeEntry readFlakeEntry(nlohmann::json json)
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
FlakeRef flakeRef(i->value("uri", ""));
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);
}
@@ -87,7 +87,7 @@ LockFile readLockFile(const Path & path)
for (auto i = nonFlakeRequires.begin(); i != nonFlakeRequires.end(); ++i) {
FlakeRef flakeRef(i->value("uri", ""));
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);
}
@@ -160,7 +160,7 @@ static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
std::vector<FlakeRef> pastSearches = {})
{
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) {
auto i = registry->entries.find(flakeRef);
@@ -183,7 +183,7 @@ static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
}
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;
}
@@ -194,7 +194,7 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
impureIsAllowed ? state.getFlakeRegistries() : std::vector<std::shared_ptr<FlakeRegistry>>());
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.
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));
}
+ 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;
- state.evalFile(sourceInfo.storePath + "/flake.nix", vInfo); // FIXME: symlink attack
+ state.evalFile(flakeFile, vInfo); // FIXME: symlink attack
state.forceAttrs(vInfo);
diff --git a/src/libexpr/primops/flakeref.cc b/src/libexpr/primops/flakeref.cc
index 97f31377a..b91bbee2a 100644
--- a/src/libexpr/primops/flakeref.cc
+++ b/src/libexpr/primops/flakeref.cc
@@ -142,6 +142,12 @@ std::string FlakeRef::to_string() const
return string;
}
+std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef)
+{
+ str << flakeRef.to_string();
+ return str;
+}
+
bool FlakeRef::isImmutable() const
{
return (bool) rev;
diff --git a/src/libexpr/primops/flakeref.hh b/src/libexpr/primops/flakeref.hh
index d789a6f70..e599e2feb 100644
--- a/src/libexpr/primops/flakeref.hh
+++ b/src/libexpr/primops/flakeref.hh
@@ -1,3 +1,5 @@
+#pragma once
+
#include "types.hh"
#include "hash.hh"
@@ -173,4 +175,7 @@ struct FlakeRef
FlakeRef baseRef() const;
};
+
+std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
+
}