aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-04-08 23:47:29 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-04-08 23:52:09 +0200
commitc996e04aca2db1755ded4864465338afab677ff5 (patch)
tree5c368d72cc2031f68d24385c1c6bee4313ad8f01
parent507da65900ccb3c6356673e93ad2271c58e43b07 (diff)
Allow relative paths in flakerefs
Also allow "." as an installable to refer to the flake in the current directory. E.g. $ nix build . will build 'provides.defaultPackage' in the flake in the current directory.
-rw-r--r--flake.nix1
-rw-r--r--src/libexpr/primops/flakeref.cc6
-rw-r--r--src/libexpr/primops/flakeref.hh2
-rw-r--r--src/nix/installables.cc14
4 files changed, 15 insertions, 8 deletions
diff --git a/flake.nix b/flake.nix
index b119f0324..695f67fa4 100644
--- a/flake.nix
+++ b/flake.nix
@@ -14,5 +14,6 @@
packages.nix = hydraJobs.build.x86_64-linux;
+ defaultPackage = packages.nix;
};
}
diff --git a/src/libexpr/primops/flakeref.cc b/src/libexpr/primops/flakeref.cc
index 5f9a29260..1df53bfb8 100644
--- a/src/libexpr/primops/flakeref.cc
+++ b/src/libexpr/primops/flakeref.cc
@@ -32,7 +32,7 @@ const static std::string segmentRegex = "[a-zA-Z0-9._~-]+";
const static std::string pathRegex = "/?" + segmentRegex + "(?:/" + segmentRegex + ")*";
const static std::string paramRegex = "[a-z]+=[a-zA-Z0-9._-]*";
-FlakeRef::FlakeRef(const std::string & uri)
+FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
{
// FIXME: could combine this into one regex.
@@ -106,9 +106,9 @@ FlakeRef::FlakeRef(const std::string & uri)
data = d;
}
- else if (hasPrefix(uri, "/")) {
+ else if (hasPrefix(uri, "/") || (allowRelative && (hasPrefix(uri, "./") || uri == "."))) {
IsPath d;
- d.path = canonPath(uri);
+ d.path = allowRelative ? absPath(uri) : canonPath(uri);
data = d;
}
diff --git a/src/libexpr/primops/flakeref.hh b/src/libexpr/primops/flakeref.hh
index 832d7dd03..fa14f7c25 100644
--- a/src/libexpr/primops/flakeref.hh
+++ b/src/libexpr/primops/flakeref.hh
@@ -132,7 +132,7 @@ struct FlakeRef
std::variant<IsFlakeId, IsGitHub, IsGit, IsPath> data;
// Parse a flake URI.
- FlakeRef(const std::string & uri);
+ FlakeRef(const std::string & uri, bool allowRelative = false);
// Default constructor
FlakeRef(const FlakeRef & flakeRef) : data(flakeRef.data) {};
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 631a849cd..f3be7b628 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -219,12 +219,18 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
else if ((colon = s.rfind(':')) != std::string::npos) {
auto flakeRef = std::string(s, 0, colon);
auto attrPath = std::string(s, colon + 1);
- result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(flakeRef), attrPath));
+ result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(flakeRef, true), attrPath));
}
- else if (s.find('/') != std::string::npos) {
- auto path = store->toStorePath(store->followLinksToStore(s));
- result.push_back(std::make_shared<InstallableStorePath>(path));
+ else if (s.find('/') != std::string::npos || s == ".") {
+ Path storePath;
+ try {
+ storePath = store->toStorePath(store->followLinksToStore(s));
+ } catch (Error) { }
+ if (storePath != "")
+ result.push_back(std::make_shared<InstallableStorePath>(storePath));
+ else
+ result.push_back(std::make_shared<InstallableFlake>(*this, FlakeRef(s, true), "defaultPackage"));
}
else