aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers/attrs.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-04-02 14:56:20 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-04-02 14:56:20 +0200
commit12f9379123eba828f2ae06f7978a37b7045c2b23 (patch)
tree265b408a4f1a84357e17e512511d127af07fd6e2 /src/libfetchers/attrs.cc
parent00e1400eb741d4f5329a6bcfdc8946617967dcb1 (diff)
Add 'path' fetcher
This fetchers copies a plain directory (i.e. not a Git/Mercurial repository) to the store (or does nothing if the path is already a store path). One use case is to pin the 'nixpkgs' flake used to build the current NixOS system, and prevent it from being garbage-collected, via a system registry entry like this: { "from": { "id": "nixpkgs", "type": "indirect" }, "to": { "type": "path", "path": "/nix/store/rralhl3wj4rdwzjn16g7d93mibvlr521-source", "lastModified": 1585388205, "rev": "b0c285807d6a9f1b7562ec417c24fa1a30ecc31a" }, "exact": true } Note the fake "lastModified" and "rev" attributes that ensure that the flake gives the same evaluation results as the corresponding Git/GitHub inputs.
Diffstat (limited to 'src/libfetchers/attrs.cc')
-rw-r--r--src/libfetchers/attrs.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libfetchers/attrs.cc b/src/libfetchers/attrs.cc
index 40c02de42..feb0a6085 100644
--- a/src/libfetchers/attrs.cc
+++ b/src/libfetchers/attrs.cc
@@ -89,4 +89,19 @@ bool getBoolAttr(const Attrs & attrs, const std::string & name)
return *s;
}
+std::map<std::string, std::string> attrsToQuery(const Attrs & attrs)
+{
+ std::map<std::string, std::string> query;
+ for (auto & attr : attrs) {
+ if (auto v = std::get_if<int64_t>(&attr.second)) {
+ query.insert_or_assign(attr.first, fmt("%d", *v));
+ } else if (auto v = std::get_if<std::string>(&attr.second)) {
+ query.insert_or_assign(attr.first, *v);
+ } else if (auto v = std::get_if<Explicit<bool>>(&attr.second)) {
+ query.insert_or_assign(attr.first, v->t ? "1" : "0");
+ } else abort();
+ }
+ return query;
+}
+
}