aboutsummaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-02-23 14:42:43 +0100
committerLudovic Courtès <ludo@gnu.org>2024-03-09 18:55:50 +0100
commit2f441fc738976175d438f7942211b1894e2eb416 (patch)
tree02ab7e0a8854370938bec5ee2aaa6c6b0406d223 /guix/build
parentabd0cca2a9ccba4e57fd2cc318139658559979cf (diff)
downloadguix-2f441fc738976175d438f7942211b1894e2eb416.tar
guix-2f441fc738976175d438f7942211b1894e2eb416.tar.gz
download: Honor ‘GUIX_DOWNLOAD_METHODS’ environment variable.
This replaces ‘GUIX_DOWNLOAD_FALLBACK_TEST’ and allows you to test various download methods, like so: GUIX_DOWNLOAD_METHODS=nar guix build guile-gcrypt -S --check GUIX_DOWNLOAD_METHODS=disarchive guix build hello -S --check * guix/build/download.scm (%download-methods): New variable. (download-method-enabled?): New procedure. (url-fetch): Define ‘initial-uris’; honor ‘download-method-enabled?’. Call ‘disarchive-fetch/any’ only when the 'disarchive method is enabled. * guix/build/git.scm (git-fetch-with-fallback): Honor ‘download-method-enabled?’. * guix/download.scm (%download-methods): New variable. (%download-fallback-test): Remove. (built-in-download): Add #:download-methods parameter and honor it. (url-fetch*): Pass #:content-addressed-mirrors and #:disarchive-mirrors unconditionally. * guix/git-download.scm (git-fetch/in-band*): Pass “git url” unconditionally. (git-fetch/built-in): Likewise. Pass “download-methods”. * guix/bzr-download.scm (bzr-fetch)[build]: Honor ‘download-method-enabled?’. Pass ‘GUIX_DOWNLOAD_METHODS’ to #:env-vars. * guix/cvs-download.scm (cvs-fetch)[build]: Honor ‘download-method-enabled?’. Pass ‘GUIX_DOWNLOAD_METHODS’ to #:env-vars. * guix/hg-download.scm (hg-fetch): Honor ‘download-method-enabled?’. Pass #:env-vars to ‘gexp->derivation’. * guix/scripts/perform-download.scm (perform-download): Honor “download-methods” from DRV. Parameterize ‘%download-methods’ before calling ‘url-fetch’. (perform-git-download): Likewise. * guix/svn-download.scm (svn-fetch): Honor ‘download-method-enabled?’. Pass ‘GUIX_DOWNLOAD_METHODS’ to #:env-vars. (svn-multi-fetch): Likewise. Change-Id: Ia3402e17f0303dfa964bdc761265efe8a1dd69ab
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/download.scm50
-rw-r--r--guix/build/git.scm15
2 files changed, 49 insertions, 16 deletions
diff --git a/guix/build/download.scm b/guix/build/download.scm
index db0a39084b..74b7486b7b 100644
--- a/guix/build/download.scm
+++ b/guix/build/download.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012-2022, 2024 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2021 Timothy Sample <samplet@ngyro.com>
@@ -40,7 +40,10 @@
#:autoload (guix swh) (swh-download-directory %verify-swh-certificate?)
#:use-module (ice-9 match)
#:use-module (ice-9 format)
- #:export (open-socket-for-uri
+ #:export (%download-methods
+ download-method-enabled?
+
+ open-socket-for-uri
open-connection-for-uri
http-fetch
%x509-certificate-directory
@@ -622,6 +625,20 @@ true, verify HTTPS certificates; otherwise simply ignore them."
(lambda (key . args)
(print-exception (current-error-port) #f key args))))
+(define %download-methods
+ ;; Either #f (the default) or a list of symbols denoting the sequence of
+ ;; download methods to be used--e.g., '(swh nar upstream).
+ (make-parameter
+ (and=> (getenv "GUIX_DOWNLOAD_METHODS")
+ (lambda (str)
+ (map string->symbol (string-tokenize str))))))
+
+(define (download-method-enabled? method)
+ "Return true if METHOD (a symbol such as 'swh) is enabled as part of the
+download fallback sequence."
+ (or (not (%download-methods))
+ (memq method (%download-methods))))
+
(define (uri-vicinity dir file)
"Concatenate DIR, slash, and FILE, keeping only one slash in between.
This is required by some HTTP servers."
@@ -788,18 +805,28 @@ otherwise simply ignore them."
hashes)))
disarchive-mirrors))
+ (define initial-uris
+ (append (if (download-method-enabled? 'upstream)
+ uri
+ '())
+ (if (download-method-enabled? 'content-addressed-mirrors)
+ content-addressed-uris
+ '())
+ (if (download-method-enabled? 'internet-archive)
+ (match uri
+ ((first . _)
+ (or (and=> (internet-archive-uri first) list)
+ '()))
+ (() '()))
+ '())))
+
;; Make this unbuffered so 'progress-report/file' works as expected. 'line
;; means '\n', not '\r', so it's not appropriate here.
(setvbuf (current-output-port) 'none)
(setvbuf (current-error-port) 'line)
- (let try ((uri (append uri content-addressed-uris
- (match uri
- ((first . _)
- (or (and=> (internet-archive-uri first) list)
- '()))
- (() '())))))
+ (let try ((uri initial-uris))
(match uri
((uri tail ...)
(or (fetch uri file)
@@ -807,9 +834,10 @@ otherwise simply ignore them."
(()
;; If we are looking for a software archive, one last thing we
;; can try is to use Disarchive to assemble it.
- (or (disarchive-fetch/any disarchive-uris file
- #:verify-certificate? verify-certificate?
- #:timeout timeout)
+ (or (and (download-method-enabled? 'disarchive)
+ (disarchive-fetch/any disarchive-uris file
+ #:verify-certificate? verify-certificate?
+ #:timeout timeout))
(begin
(format (current-error-port) "failed to download ~s from ~s~%"
file url)
diff --git a/guix/build/git.scm b/guix/build/git.scm
index a135026fae..62877394bb 100644
--- a/guix/build/git.scm
+++ b/guix/build/git.scm
@@ -19,6 +19,8 @@
(define-module (guix build git)
#:use-module (guix build utils)
+ #:use-module ((guix build download)
+ #:select (download-method-enabled?))
#:autoload (guix build download-nar) (download-nar)
#:autoload (guix swh) (%verify-swh-certificate?
swh-download
@@ -102,17 +104,20 @@ for ITEM, and if that also fails, download from the Software Heritage archive.
When HASH and HASH-ALGORITHM are provided, they are interpreted as the nar
hash of the directory of interested and are used as its content address at
SWH."
- (or (git-fetch url commit directory
- #:lfs? lfs?
- #:recursive? recursive?
- #:git-command git-command)
- (download-nar item directory)
+ (or (and (download-method-enabled? 'upstream)
+ (git-fetch url commit directory
+ #:lfs? lfs?
+ #:recursive? recursive?
+ #:git-command git-command))
+ (and (download-method-enabled? 'nar)
+ (download-nar item directory))
;; As a last resort, attempt to download from Software Heritage.
;; Disable X.509 certificate verification to avoid depending
;; on nss-certs--we're authenticating the checkout anyway.
;; XXX: Currently recursive checkouts are not supported.
(and (not recursive?)
+ (download-method-enabled? 'swh)
(parameterize ((%verify-swh-certificate? #f))
(format (current-error-port)
"Trying to download from Software Heritage...~%")