summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/guix.texi13
-rwxr-xr-xguix/scripts/substitute-binary.scm44
-rw-r--r--nix/nix-daemon/guix-daemon.cc15
3 files changed, 64 insertions, 8 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index c9760f5f60..5881adb221 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -453,6 +453,14 @@ When the daemon runs with @code{--no-substitutes}, clients can still
 explicitly enable substitution @i{via} the @code{set-build-options}
 remote procedure call (@pxref{The Store}).
 
+@item --substitute-urls=@var{urls}
+Consider @var{urls} the default whitespace-separated list of substitute
+source URLs.  When this option is omitted, @code{http://hydra.gnu.org}
+is used.
+
+This means that substitutes may be downloaded from @var{urls}, as long
+as they are signed by a trusted signature (@pxref{Substitutes}).
+
 @cindex build hook
 @item --no-build-hook
 Do not use the @dfn{build hook}.
@@ -981,7 +989,10 @@ also result from derivation builds, can be available as substitutes.
 
 The @code{hydra.gnu.org} server is a front-end to a build farm that
 builds packages from the GNU distribution continuously for some
-architectures, and makes them available as substitutes.
+architectures, and makes them available as substitutes.  This is the
+default source of substitutes; it can be overridden by passing
+@command{guix-daemon} the @code{--substitute-urls} option
+(@pxref{Invoking guix-daemon}).
 
 @cindex security
 @cindex digital signatures
diff --git a/guix/scripts/substitute-binary.scm b/guix/scripts/substitute-binary.scm
index ec7596efb6..7a286426a1 100755
--- a/guix/scripts/substitute-binary.scm
+++ b/guix/scripts/substitute-binary.scm
@@ -528,10 +528,6 @@ PORT.  REPORT-PROGRESS is a two-argument procedure such as that returned by
                 (_ "(Please consider upgrading Guile to get proper progress report.)~%"))
         port)))
 
-(define %cache-url
-  (or (getenv "GUIX_BINARY_SUBSTITUTE_URL")
-      "http://hydra.gnu.org"))
-
 (define-syntax with-networking
   (syntax-rules ()
     "Catch DNS lookup errors and gracefully exit."
@@ -604,6 +600,46 @@ Internal tool to substitute a pre-built binary to a local build.\n"))
       (warning (_ "ACL for archive imports seems to be uninitialized, \
 substitutes may be unavailable\n")))))
 
+(define (daemon-options)
+  "Return a list of name/value pairs denoting build daemon options."
+  (define %not-newline
+    (char-set-complement (char-set #\newline)))
+
+  (match (getenv "_NIX_OPTIONS")
+    (#f                           ;should not happen when called by the daemon
+     '())
+    (newline-separated
+     ;; Here we get something of the form "OPTION1=VALUE1\nOPTION2=VALUE2\n".
+     (filter-map (lambda (option=value)
+                   (match (string-index option=value #\=)
+                     (#f                          ;invalid option setting
+                      #f)
+                     (equal-sign
+                      (cons (string-take option=value equal-sign)
+                            (string-drop option=value (+ 1 equal-sign))))))
+                 (string-tokenize newline-separated %not-newline)))))
+
+(define (find-daemon-option option)
+  "Return the value of build daemon option OPTION, or #f if it could not be
+found."
+  (assoc-ref (daemon-options) option))
+
+(define %cache-url
+  (or (getenv "GUIX_BINARY_SUBSTITUTE_URL")
+      (match (and=> (find-daemon-option "substitute-urls")
+                    string-tokenize)
+        ((url)
+         url)
+        ((head tail ..1)
+         ;; Currently we don't handle multiple substitute URLs.
+         (warning (_ "these substitute URLs will not be used:~{ ~a~}~%")
+                  tail)
+         head)
+        (#f
+         ;; This can only happen when this script is not invoked by the
+         ;; daemon.
+         "http://hydra.gnu.org"))))
+
 (define (guix-substitute-binary . args)
   "Implement the build daemon's substituter protocol."
   (mkdir-p %narinfo-cache-directory)
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index 8c63bed0bf..d1d4541971 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -68,9 +68,10 @@ builds derivations on behalf of its clients.";
 #define GUIX_OPT_CHROOT_DIR 10
 #define GUIX_OPT_LISTEN 11
 #define GUIX_OPT_NO_SUBSTITUTES 12
-#define GUIX_OPT_NO_BUILD_HOOK 13
-#define GUIX_OPT_GC_KEEP_OUTPUTS 14
-#define GUIX_OPT_GC_KEEP_DERIVATIONS 15
+#define GUIX_OPT_SUBSTITUTE_URLS 13
+#define GUIX_OPT_NO_BUILD_HOOK 14
+#define GUIX_OPT_GC_KEEP_OUTPUTS 15
+#define GUIX_OPT_GC_KEEP_DERIVATIONS 16
 
 static const struct argp_option options[] =
   {
@@ -98,6 +99,8 @@ static const struct argp_option options[] =
       "Perform builds as a user of GROUP" },
     { "no-substitutes", GUIX_OPT_NO_SUBSTITUTES, 0, 0,
       "Do not use substitutes" },
+    { "substitute-urls", GUIX_OPT_SUBSTITUTE_URLS, "URLS", 0,
+      "Use URLS as the default list of substitute providers" },
     { "no-build-hook", GUIX_OPT_NO_BUILD_HOOK, 0, 0,
       "Do not use the 'build hook'" },
     { "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0,
@@ -192,6 +195,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	  exit (EXIT_FAILURE);
 	}
       break;
+    case GUIX_OPT_SUBSTITUTE_URLS:
+      settings.set ("substitute-urls", arg);
+      break;
     case GUIX_OPT_NO_SUBSTITUTES:
       settings.set ("build-use-substitutes", "false");
       break;
@@ -280,6 +286,9 @@ main (int argc, char *argv[])
       settings.substituters.clear ();
       settings.set ("build-use-substitutes", "true");
 
+      /* Use our substitute server by default.  */
+      settings.set ("substitute-urls", "http://hydra.gnu.org");
+
 #ifdef HAVE_DAEMON_OFFLOAD_HOOK
       /* Use our build hook for distributed builds by default.  */
       settings.useBuildHook = true;