aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-04-27 22:53:11 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-04-27 22:53:11 +0200
commit6521c92ce8289a5f9e959c6789ab24dacdad082e (patch)
tree659c7ce34b0cb970aa7d99bcda991de50e8d27ac /src/libfetchers
parent829dcb35d52443636d7c6df0d54270b9995bc71a (diff)
Improve path:// handling
In particular, doing 'nix build /path/to/dir' now works if /path/to/dir is not a Git tree (it only has to contain a flake.nix file). Also, 'nix flake init' no longer requires a Git tree (but it will do a 'git add flake.nix' if it's a Git tree)
Diffstat (limited to 'src/libfetchers')
-rw-r--r--src/libfetchers/path.cc24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc
index ba2cc192e..77fe87d59 100644
--- a/src/libfetchers/path.cc
+++ b/src/libfetchers/path.cc
@@ -32,7 +32,7 @@ struct PathInput : Input
bool isImmutable() const override
{
- return (bool) narHash;
+ return narHash || rev;
}
ParsedURL toURL() const override
@@ -56,9 +56,20 @@ struct PathInput : Input
attrs.emplace("revCount", *revCount);
if (lastModified)
attrs.emplace("lastModified", *lastModified);
+ if (!rev && narHash)
+ attrs.emplace("narHash", narHash->to_string(SRI));
return attrs;
}
+ std::optional<Path> getSourcePath() const override
+ {
+ return path;
+ }
+
+ void markChangedFile(std::string_view file, std::optional<std::string> commitMsg) const override
+ {
+ }
+
std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override
{
auto input = std::make_shared<PathInput>(*this);
@@ -74,6 +85,8 @@ struct PathInput : Input
// FIXME: try to substitute storePath.
storePath = store->addToStore("source", path);
+ input->narHash = store->queryPathInfo(*storePath)->narHash;
+
return
{
Tree {
@@ -99,6 +112,9 @@ struct PathInputScheme : InputScheme
auto input = std::make_unique<PathInput>();
input->path = url.path;
+ if (url.authority && *url.authority != "")
+ throw Error("path URL '%s' should not have an authority ('%s')", url.url, *url.authority);
+
for (auto & [name, value] : url.query)
if (name == "rev")
input->rev = Hash(value, htSHA1);
@@ -114,6 +130,9 @@ struct PathInputScheme : InputScheme
throw Error("path URL '%s' has invalid parameter '%s'", url.to_string(), name);
input->lastModified = lastModified;
}
+ else if (name == "narHash")
+ // FIXME: require SRI hash.
+ input->narHash = Hash(value);
else
throw Error("path URL '%s' has unsupported parameter '%s'", url.to_string(), name);
@@ -134,6 +153,9 @@ struct PathInputScheme : InputScheme
input->revCount = getIntAttr(attrs, "revCount");
else if (name == "lastModified")
input->lastModified = getIntAttr(attrs, "lastModified");
+ else if (name == "narHash")
+ // FIXME: require SRI hash.
+ input->narHash = Hash(getStrAttr(attrs, "narHash"));
else if (name == "type" || name == "path")
;
else