daemon: Implement ‘substitute-urls’ RPC.

* nix/libstore/worker-protocol.hh (PROTOCOL_VERSION): Bump.
(WorkerOp): Add ‘wopSubstituteURLs’.
* nix/nix-daemon/nix-daemon.cc (performOp): Implement it.
* guix/store.scm (%protocol-version): Bump.
(operation-id): Add ‘substitute-urls’.
(substitute-urls): New procedure.
* tests/store.scm ("substitute-urls, default")
("substitute-urls, client-specified URLs")
("substitute-urls, disabled"): New tests.

Change-Id: I2c0119500c3a1eecfa5ebf32463ffb0f173161de
This commit is contained in:
Ludovic Courtès 2023-11-10 21:37:28 +01:00
parent b650dcabf1
commit 1e47148f46
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
4 changed files with 58 additions and 7 deletions

View File

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2012-2023 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Jan Nieuwenhuizen <janneke@gnu.org> ;;; Copyright © 2018 Jan Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2019, 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2019, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
@ -145,6 +145,7 @@
path-info-nar-size path-info-nar-size
built-in-builders built-in-builders
substitute-urls
references references
references/cached references/cached
references* references*
@ -199,7 +200,7 @@
derivation-log-file derivation-log-file
log-file)) log-file))
(define %protocol-version #x163) (define %protocol-version #x164)
(define %worker-magic-1 #x6e697863) ; "nixc" (define %worker-magic-1 #x6e697863) ; "nixc"
(define %worker-magic-2 #x6478696f) ; "dxio" (define %worker-magic-2 #x6478696f) ; "dxio"
@ -253,7 +254,8 @@
(query-valid-derivers 33) (query-valid-derivers 33)
(optimize-store 34) (optimize-store 34)
(verify-store 35) (verify-store 35)
(built-in-builders 80)) (built-in-builders 80)
(substitute-urls 81))
(define-enumerate-type hash-algo (define-enumerate-type hash-algo
;; hash.hh ;; hash.hh
@ -1780,6 +1782,16 @@ The result is always the empty list unless the daemon was started with
This makes sense only when the daemon was started with '--cache-failures'." This makes sense only when the daemon was started with '--cache-failures'."
boolean) boolean)
(define substitute-urls
(let ((urls (operation (substitute-urls)
#f
string-list)))
(lambda (store)
"Return the list of currently configured substitutes URLs for STORE, or
#f if the daemon is too old and does not implement this RPC."
(and (>= (store-connection-version store) #x164)
(urls store)))))
;;; ;;;
;;; Per-connection caches. ;;; Per-connection caches.

View File

@ -6,7 +6,7 @@ namespace nix {
#define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_1 0x6e697863
#define WORKER_MAGIC_2 0x6478696f #define WORKER_MAGIC_2 0x6478696f
#define PROTOCOL_VERSION 0x163 #define PROTOCOL_VERSION 0x164
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
@ -44,7 +44,8 @@ typedef enum {
wopQueryValidDerivers = 33, wopQueryValidDerivers = 33,
wopOptimiseStore = 34, wopOptimiseStore = 34,
wopVerifyStore = 35, wopVerifyStore = 35,
wopBuiltinBuilders = 80 wopBuiltinBuilders = 80,
wopSubstituteURLs = 81
} WorkerOp; } WorkerOp;

View File

@ -736,6 +736,23 @@ static void performOp(bool trusted, unsigned int clientVersion,
break; break;
} }
case wopSubstituteURLs: {
startWork();
Strings urls;
if (settings.get("build-use-substitutes", std::string("false")) == "true") {
/* First check the client-provided substitute URLs, then those
passed to the daemon. */
auto str = settings.get("untrusted-substitute-urls", std::string(""));
if (str.empty()) {
str = settings.get("substitute-urls", std::string(""));
}
urls = tokenizeString<Strings>(str);
}
stopWork();
writeStrings(urls, to);
break;
}
default: default:
throw Error(format("invalid operation %1%") % op); throw Error(format("invalid operation %1%") % op);
} }

View File

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2012-2021, 2023 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -105,7 +105,28 @@
"/283gqy39v3g9dxjy26rynl0zls82fmcg-guile-2.0.7/bin/guile"))) "/283gqy39v3g9dxjy26rynl0zls82fmcg-guile-2.0.7/bin/guile")))
(not (direct-store-path? (%store-prefix))))) (not (direct-store-path? (%store-prefix)))))
(test-skip (if %store 0 15)) (test-skip (if %store 0 18))
(test-equal "substitute-urls, default"
(list (getenv "GUIX_BINARY_SUBSTITUTE_URL"))
(with-store store
(set-build-options store #:use-substitutes? #t)
(substitute-urls store)))
(test-equal "substitute-urls, client-specified URLs"
'("http://substitutes.example.org"
"http://other.example.org")
(with-store store
(set-build-options store #:use-substitutes? #t
#:substitute-urls '("http://substitutes.example.org"
"http://other.example.org"))
(substitute-urls store)))
(test-equal "substitute-urls, disabled"
'()
(with-store store
(set-build-options store #:use-substitutes? #f)
(substitute-urls store)))
(test-equal "profiles/per-user exists and is not writable" (test-equal "profiles/per-user exists and is not writable"
#o755 #o755