Automatically determine subdir for path flakes

This means that in a flake in a subdirectory of a Git repo, you can
now do

  $ nix build

rather than the inconvenient

  $ nix build ../..?dir=foo/bar
This commit is contained in:
Eelco Dolstra 2019-05-31 21:52:02 +02:00
parent ccb1bad612
commit 8abb8647a3
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -140,7 +140,17 @@ FlakeRef::FlakeRef(const std::string & uri_, bool allowRelative)
&& uri.find(':') == std::string::npos) && uri.find(':') == std::string::npos)
{ {
IsPath d; IsPath d;
d.path = allowRelative ? absPath(uri) : canonPath(uri); if (allowRelative) {
d.path = absPath(uri);
while (true) {
if (pathExists(d.path + "/.git")) break;
subdir = baseNameOf(d.path) + (subdir.empty() ? "" : "/" + subdir);
d.path = dirOf(d.path);
if (d.path == "/")
throw BadFlakeRef("path '%s' does not reference a Git repository", uri);
}
} else
d.path = canonPath(uri);
data = d; data = d;
for (auto & param : params) { for (auto & param : params) {
if (handleGitParams(param.first, param.second)) if (handleGitParams(param.first, param.second))