aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-11-30 16:11:15 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-02-11 12:05:13 +0100
commitef4cf4e681bfe30b15b8c2940b51b322bce5b6d8 (patch)
tree0d574a3e9a6e3f4dc51cf87b14b21c03ec503d4e /src/libexpr
parent7a5cf31060289de61370643937277b5d0d5d178c (diff)
Introduce flake URIs
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops/flake.cc46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index 457c30948..9dc6fa1f1 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -4,6 +4,7 @@
#include "download.hh"
#include <queue>
+#include <regex>
#include <nlohmann/json.hpp>
namespace nix {
@@ -67,16 +68,39 @@ struct Flake
Value * vProvides; // FIXME: gc
};
-static Flake fetchFlake(EvalState & state, const std::string & flakeUri)
+std::regex flakeRegex("^flake:([a-zA-Z][a-zA-Z0-9_-]+)$");
+
+static Path fetchFlake(EvalState & state, const std::string & flakeUri)
{
- Flake flake;
+ std::smatch match;
+
+ if (std::regex_match(flakeUri, match, flakeRegex)) {
+ auto flakeName = match[1];
+ auto registry = state.getFlakeRegistry();
+ auto i = registry.entries.find(flakeName);
+ if (i == registry.entries.end())
+ throw Error("unknown flake '%s'", flakeName);
+ return fetchFlake(state, i->second.uri);
+ }
- auto gitInfo = exportGit(state.store, flakeUri, {}, "", "source");
+ else if (hasPrefix(flakeUri, "/") || hasPrefix(flakeUri, "git://")) {
+ auto gitInfo = exportGit(state.store, flakeUri, {}, "", "source");
+ return gitInfo.storePath;
+ }
- state.store->assertStorePath(gitInfo.storePath);
+ else
+ throw Error("unsupported flake URI '%s'", flakeUri);
+}
+
+static Flake getFlake(EvalState & state, const std::string & flakeUri)
+{
+ auto flakePath = fetchFlake(state, flakeUri);
+ state.store->assertStorePath(flakePath);
+
+ Flake flake;
Value vInfo;
- state.evalFile(gitInfo.storePath + "/flake.nix", vInfo);
+ state.evalFile(flakePath + "/flake.nix", vInfo);
state.forceAttrs(vInfo);
@@ -106,8 +130,6 @@ static Flake fetchFlake(EvalState & state, const std::string & flakeUri)
static std::map<std::string, Flake> resolveFlakes(EvalState & state, const StringSet & flakeUris)
{
- auto registry = state.getFlakeRegistry();
-
std::map<std::string, Flake> done;
std::queue<std::string> todo;
for (auto & i : flakeUris) todo.push(i);
@@ -117,14 +139,10 @@ static std::map<std::string, Flake> resolveFlakes(EvalState & state, const Strin
todo.pop();
if (done.count(flakeUri)) continue;
- auto flake = fetchFlake(state, flakeUri);
+ auto flake = getFlake(state, flakeUri);
- for (auto & require : flake.requires) {
- auto i = registry.entries.find(require);
- if (i == registry.entries.end())
- throw Error("unknown flake '%s'", require);
- todo.push(i->second.uri);
- }
+ for (auto & require : flake.requires)
+ todo.push(require);
done.emplace(flake.name, flake);
}