aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-04-24 12:47:35 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-04-24 12:47:35 +0200
commit21d5abfc146bdc69d631d47de2cdcfdd18cc228c (patch)
tree463eae782d2e2378b47624ffa1d859716143f67c /src/libexpr/primops
parentcc51e37ad09a1dac0a58c543ffe275ddc18819aa (diff)
parentb42ba08fc8a291c549c1f9f92457d72639fac995 (diff)
Merge remote-tracking branch 'tweag/flake-clone' into flakes
Diffstat (limited to 'src/libexpr/primops')
-rw-r--r--src/libexpr/primops/flake.cc43
-rw-r--r--src/libexpr/primops/flake.hh3
-rw-r--r--src/libexpr/primops/flakeref.hh1
3 files changed, 42 insertions, 5 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index c098168de..d898da1e9 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -146,17 +146,19 @@ std::shared_ptr<FlakeRegistry> getFlagRegistry()
return std::make_shared<FlakeRegistry>();
}
-const std::vector<std::shared_ptr<FlakeRegistry>> EvalState::getFlakeRegistries()
+// This always returns a vector with globalReg, userReg, localReg, flakeReg.
+// If one of them doesn't exist, the registry is left empty but does exist.
+const Registries EvalState::getFlakeRegistries()
{
- std::vector<std::shared_ptr<FlakeRegistry>> registries;
- registries.push_back(getGlobalRegistry());
+ Registries registries;
+ registries.push_back(getGlobalRegistry()); // TODO (Nick): Doesn't this break immutability?
registries.push_back(getUserRegistry());
+ registries.push_back(std::make_shared<FlakeRegistry>()); // local
registries.push_back(getFlagRegistry());
return registries;
}
-static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef,
- const std::vector<std::shared_ptr<FlakeRegistry>> & registries,
+static FlakeRef lookupFlake(EvalState & state, const FlakeRef & flakeRef, const Registries & registries,
std::vector<FlakeRef> pastSearches = {})
{
if (registries.empty() && !flakeRef.isDirect())
@@ -467,4 +469,35 @@ static void prim_getFlake(EvalState & state, const Pos & pos, Value * * args, Va
static RegisterPrimOp r2("getFlake", 1, prim_getFlake);
+void gitCloneFlake (std::string flakeUri, EvalState & state, Registries registries,
+ Path endDirectory)
+{
+ FlakeRef flakeRef(flakeUri);
+ flakeRef = lookupFlake(state, flakeRef, registries);
+
+ std::string uri;
+
+ Strings args = {"clone"};
+
+ if (auto refData = std::get_if<FlakeRef::IsGitHub>(&flakeRef.data)) {
+ uri = "git@github.com:" + refData->owner + "/" + refData->repo + ".git";
+ args.push_back(uri);
+ if (flakeRef.ref) {
+ args.push_back("--branch");
+ args.push_back(*flakeRef.ref);
+ }
+ } else if (auto refData = std::get_if<FlakeRef::IsGit>(&flakeRef.data)) {
+ args.push_back(refData->uri);
+ if (flakeRef.ref) {
+ args.push_back("--branch");
+ args.push_back(*flakeRef.ref);
+ }
+ }
+
+ if (endDirectory != "")
+ args.push_back(endDirectory);
+
+ runProgram("git", true, args);
+}
+
}
diff --git a/src/libexpr/primops/flake.hh b/src/libexpr/primops/flake.hh
index 0b70088cc..4e0d3b646 100644
--- a/src/libexpr/primops/flake.hh
+++ b/src/libexpr/primops/flake.hh
@@ -27,6 +27,8 @@ struct LockFile
std::map<FlakeId, FlakeRef> nonFlakeEntries;
};
+typedef std::vector<std::shared_ptr<FlakeRegistry>> Registries;
+
Path getUserRegistryPath();
enum RegistryAccess { DisallowRegistry, AllowRegistry, AllowRegistryAtTop };
@@ -86,4 +88,5 @@ ResolvedFlake resolveFlake(EvalState &, const FlakeRef &, RegistryAccess registr
void updateLockFile(EvalState &, const Path & path);
+void gitCloneFlake (std::string flakeUri, EvalState &, Registries, Path);
}
diff --git a/src/libexpr/primops/flakeref.hh b/src/libexpr/primops/flakeref.hh
index e599e2feb..51fdc3b70 100644
--- a/src/libexpr/primops/flakeref.hh
+++ b/src/libexpr/primops/flakeref.hh
@@ -69,6 +69,7 @@ namespace nix {
https://example.org/my/repo.git
https://example.org/my/repo.git?ref=release-1.2.3
https://example.org/my/repo.git?rev=e72daba8250068216d79d2aeef40d4d95aff6666
+ git://github.com/edolstra/dwarffs.git\?ref=flake\&rev=2efca4bc9da70fb001b26c3dc858c6397d3c4817
* /path.git(\?attr(&attr)*)?