summaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-05-14 17:37:47 +0200
committerLudovic Courtès <ludo@gnu.org>2016-05-14 17:37:47 +0200
commitcd436bf05a8344acf4462f3602e7d360821a902a (patch)
tree0a3f473f4e2c4f9a6fb007637cf2d340ebe55370 /guix/build
parentc22a475725b99463de6e163a212c9398116c8aa0 (diff)
download: Support content-addressed mirrors.
* guix/download.scm (%content-addressed-mirrors) (%content-addressed-mirror-file): New variables. * guix/download.scm (url-fetch)[builder]: Define 'value-from-environment. Pass #:hashes and #:content-addressed-mirrors to 'url-fetch'. Define "guix download hashes" environment variable. * guix/build/download.scm (url-fetch): Add #:content-addressed-mirrors and #:hashes. [content-addressed-urls]: New variable. Use it.
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/download.scm26
1 files changed, 23 insertions, 3 deletions
diff --git a/guix/build/download.scm b/guix/build/download.scm
index fec4cec3e8..824e1c354a 100644
--- a/guix/build/download.scm
+++ b/guix/build/download.scm
@@ -605,10 +605,22 @@ Return a list of URIs."
(else
(list uri))))
-(define* (url-fetch url file #:key (mirrors '()))
+(define* (url-fetch url file
+ #:key
+ (mirrors '()) (content-addressed-mirrors '())
+ (hashes '()))
"Fetch FILE from URL; URL may be either a single string, or a list of
string denoting alternate URLs for FILE. Return #f on failure, and FILE
-on success."
+on success.
+
+When MIRRORS is defined, it must be an alist of mirrors; it is used to resolve
+'mirror://' URIs.
+
+HASHES must be a list of algorithm/hash pairs, where each algorithm is a
+symbol such as 'sha256 and each hash is a bytevector.
+CONTENT-ADDRESSED-MIRRORS must be a list of procedures that, given a hash
+algorithm and a hash, return a URL where the specified data can be retrieved
+or #f."
(define uri
(append-map (cut maybe-expand-mirrors <> mirrors)
(match url
@@ -628,13 +640,21 @@ on success."
uri)
#f)))
+ (define content-addressed-urls
+ (append-map (lambda (make-url)
+ (filter-map (match-lambda
+ ((hash-algo . hash)
+ (make-url hash-algo hash)))
+ hashes))
+ content-addressed-mirrors))
+
;; Make this unbuffered so 'progress-proc' works as expected. _IOLBF means
;; '\n', not '\r', so it's not appropriate here.
(setvbuf (current-output-port) _IONBF)
(setvbuf (current-error-port) _IOLBF)
- (let try ((uri uri))
+ (let try ((uri (append uri content-addressed-urls)))
(match uri
((uri tail ...)
(or (fetch uri file)