2013-04-02 04:44:20 -04:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2021-01-13 09:45:24 -05:00
|
|
|
|
;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
2014-03-28 19:06:41 -04:00
|
|
|
|
;;; Copyright © 2014 Nikita Karetnikov <nikita@karetnikov.org>
|
2018-07-07 00:41:34 -04:00
|
|
|
|
;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
|
2020-12-24 11:01:25 -05:00
|
|
|
|
;;; Copyright © 2020 Christopher Baines <mail@cbaines.net>
|
2013-04-02 04:44:20 -04:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2015-03-25 05:34:27 -04:00
|
|
|
|
(define-module (guix scripts substitute)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (guix ui)
|
2020-09-01 16:13:11 -04:00
|
|
|
|
#:use-module (guix scripts)
|
2020-01-03 09:47:12 -05:00
|
|
|
|
#:use-module (guix store)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (guix utils)
|
utils: Move combinators to (guix combinators).
* guix/utils.scm (compile-time-value, memoize, fold2)
(fold-tree, fold-tree-leaves): Move to...
* guix/combinators: ... here. New file.
* tests/utils.scm ("fold2, 1 list", "fold2, 2 lists")
(fold-tree tests): Move to...
* tests/combinators.scm: ... here. New file.
* Makefile.am (MODULES, SCM_TESTS): Add them.
* gnu/packages.scm, gnu/packages/bootstrap.scm,
gnu/services/herd.scm, guix/build-system/gnu.scm,
guix/build-system/python.scm, guix/derivations.scm,
guix/gnu-maintenance.scm, guix/import/elpa.scm,
guix/scripts/archive.scm, guix/scripts/build.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/size.scm, guix/scripts/substitute.scm,
guix/serialization.scm, guix/store.scm, guix/ui.scm: Adjust imports
accordingly.
2016-05-04 11:35:47 -04:00
|
|
|
|
#:use-module (guix combinators)
|
2013-04-12 11:30:27 -04:00
|
|
|
|
#:use-module (guix config)
|
2013-05-12 09:46:16 -04:00
|
|
|
|
#:use-module (guix records)
|
daemon: Let 'guix substitute' perform hash checks.
This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon. Consequently, it should reduce latency between
subsequent substitute downloads.
This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.
* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it. Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ. When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'. Parse it and handle
"success" and "hash-mismatch" accordingly. Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
2020-12-13 16:46:03 -05:00
|
|
|
|
#:use-module (guix diagnostics)
|
|
|
|
|
#:use-module (guix i18n)
|
2020-12-14 11:59:32 -05:00
|
|
|
|
#:use-module ((guix serialization) #:select (restore-file dump-file))
|
|
|
|
|
#:autoload (guix store deduplication) (dump-file/deduplicate)
|
2020-11-29 12:05:11 -05:00
|
|
|
|
#:autoload (guix scripts discover) (read-substitute-urls)
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 11:07:07 -04:00
|
|
|
|
#:use-module (gcrypt hash)
|
2015-07-13 09:52:29 -04:00
|
|
|
|
#:use-module (guix base32)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
#:use-module (guix base64)
|
2017-04-18 16:07:49 -04:00
|
|
|
|
#:use-module (guix cache)
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 11:07:07 -04:00
|
|
|
|
#:use-module (gcrypt pk-crypto)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
#:use-module (guix pki)
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
#:use-module ((guix build utils) #:select (mkdir-p dump-port))
|
2013-06-20 17:41:11 -04:00
|
|
|
|
#:use-module ((guix build download)
|
Add (guix progress).
Among other things, this removes (guix utils), (guix ui), (guix config),
etc. from the closure of (guix build download), as was the case since
798648515b77507c242752457b4dc17c155bad6e.
* guix/utils.scm (<progress-reporter>, call-with-progress-reporter):
Move to...
* guix/progress.scm: ... here. New file.
* Makefile.am (MODULES): Add it.
* guix/build/download.scm (current-terminal-columns)
(nearest-exact-integer, duration->seconds, seconds->string)
(byte-count->string, progress-bar, string-pad-middle)
(rate-limited, progress-reporter/file, dump-port*)
(time-monotonic): Move to progress.scm.
* guix/scripts/download.scm: Adjust accordingly.
* guix/scripts/substitute.scm: Likewise.
2017-10-16 17:16:39 -04:00
|
|
|
|
#:select (uri-abbreviation nar-uri-abbreviation
|
2017-03-17 18:41:37 -04:00
|
|
|
|
(open-connection-for-uri
|
|
|
|
|
. guix:open-connection-for-uri)
|
2015-09-15 01:31:11 -04:00
|
|
|
|
store-path-abbreviation byte-count->string))
|
2021-01-04 05:05:58 -05:00
|
|
|
|
#:autoload (gnutls) (error/invalid-session)
|
Add (guix progress).
Among other things, this removes (guix utils), (guix ui), (guix config),
etc. from the closure of (guix build download), as was the case since
798648515b77507c242752457b4dc17c155bad6e.
* guix/utils.scm (<progress-reporter>, call-with-progress-reporter):
Move to...
* guix/progress.scm: ... here. New file.
* Makefile.am (MODULES): Add it.
* guix/build/download.scm (current-terminal-columns)
(nearest-exact-integer, duration->seconds, seconds->string)
(byte-count->string, progress-bar, string-pad-middle)
(rate-limited, progress-reporter/file, dump-port*)
(time-monotonic): Move to progress.scm.
* guix/scripts/download.scm: Adjust accordingly.
* guix/scripts/substitute.scm: Likewise.
2017-10-16 17:16:39 -04:00
|
|
|
|
#:use-module (guix progress)
|
2017-05-28 10:09:32 -04:00
|
|
|
|
#:use-module ((guix build syscalls)
|
|
|
|
|
#:select (set-thread-name))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (ice-9 rdelim)
|
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
|
#:use-module (ice-9 match)
|
2013-04-12 11:30:27 -04:00
|
|
|
|
#:use-module (ice-9 format)
|
2013-04-20 09:12:24 -04:00
|
|
|
|
#:use-module (ice-9 ftw)
|
2013-06-20 17:41:11 -04:00
|
|
|
|
#:use-module (ice-9 binary-ports)
|
2017-07-21 08:07:29 -04:00
|
|
|
|
#:use-module (ice-9 vlist)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
#:use-module (rnrs bytevectors)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-9)
|
|
|
|
|
#:use-module (srfi srfi-11)
|
2013-04-15 17:42:27 -04:00
|
|
|
|
#:use-module (srfi srfi-19)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (srfi srfi-26)
|
2014-03-01 09:38:11 -05:00
|
|
|
|
#:use-module (srfi srfi-34)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
#:use-module (srfi srfi-35)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (web uri)
|
2016-03-10 05:53:03 -05:00
|
|
|
|
#:use-module (web http)
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
#:use-module (web request)
|
|
|
|
|
#:use-module (web response)
|
2013-07-14 10:35:37 -04:00
|
|
|
|
#:use-module (guix http-client)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
#:export (narinfo-signature->canonical-sexp
|
2015-10-19 17:12:34 -04:00
|
|
|
|
|
|
|
|
|
narinfo?
|
|
|
|
|
narinfo-path
|
2019-05-31 10:26:08 -04:00
|
|
|
|
narinfo-uris
|
2015-10-19 17:12:34 -04:00
|
|
|
|
narinfo-uri-base
|
2019-05-31 10:26:08 -04:00
|
|
|
|
narinfo-compressions
|
|
|
|
|
narinfo-file-hashes
|
|
|
|
|
narinfo-file-sizes
|
2015-10-19 17:12:34 -04:00
|
|
|
|
narinfo-hash
|
|
|
|
|
narinfo-size
|
|
|
|
|
narinfo-references
|
|
|
|
|
narinfo-deriver
|
|
|
|
|
narinfo-system
|
|
|
|
|
narinfo-signature
|
|
|
|
|
|
|
|
|
|
narinfo-hash->sha256
|
2019-12-04 17:07:03 -05:00
|
|
|
|
narinfo-best-uri
|
2015-10-19 17:12:34 -04:00
|
|
|
|
|
|
|
|
|
lookup-narinfos
|
2015-10-28 05:11:43 -04:00
|
|
|
|
lookup-narinfos/diverse
|
2014-03-28 19:06:41 -04:00
|
|
|
|
read-narinfo
|
|
|
|
|
write-narinfo
|
2017-08-31 17:27:26 -04:00
|
|
|
|
|
2019-11-26 06:30:45 -05:00
|
|
|
|
%allow-unauthenticated-substitutes?
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
%error-to-file-descriptor-4?
|
2019-11-26 06:30:45 -05:00
|
|
|
|
|
2017-08-31 17:27:26 -04:00
|
|
|
|
substitute-urls
|
2015-03-25 05:34:27 -04:00
|
|
|
|
guix-substitute))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
|
|
|
|
;;; Comment:
|
|
|
|
|
;;;
|
|
|
|
|
;;; This is the "binary substituter". It is invoked by the daemon do check
|
|
|
|
|
;;; for the existence of available "substitutes" (pre-built binaries), and to
|
|
|
|
|
;;; actually use them as a substitute to building things locally.
|
|
|
|
|
;;;
|
|
|
|
|
;;; If possible, substitute a binary for the requested store path, using a Nix
|
|
|
|
|
;;; "binary cache". This program implements the Nix "substituter" protocol.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2013-04-15 17:42:27 -04:00
|
|
|
|
(define %narinfo-cache-directory
|
2016-06-22 17:46:32 -04:00
|
|
|
|
;; A local cache of narinfos, to avoid going to the network. Most of the
|
|
|
|
|
;; time, 'guix substitute' is called by guix-daemon as root and stores its
|
|
|
|
|
;; cached data in /var/guix/…. However, when invoked from 'guix challenge'
|
|
|
|
|
;; as a user, it stores its cache in ~/.cache.
|
|
|
|
|
(if (zero? (getuid))
|
|
|
|
|
(or (and=> (getenv "XDG_CACHE_HOME")
|
|
|
|
|
(cut string-append <> "/guix/substitute"))
|
|
|
|
|
(string-append %state-directory "/substitute/cache"))
|
2017-07-28 08:51:44 -04:00
|
|
|
|
(string-append (cache-directory #:ensure? #f) "/substitute")))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
2019-11-26 06:30:45 -05:00
|
|
|
|
(define (warn-about-missing-authentication)
|
|
|
|
|
(warning (G_ "authentication and authorization of substitutes \
|
|
|
|
|
disabled!~%"))
|
|
|
|
|
#t)
|
|
|
|
|
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(define %allow-unauthenticated-substitutes?
|
|
|
|
|
;; Whether to allow unchecked substitutes. This is useful for testing
|
|
|
|
|
;; purposes, and should be avoided otherwise.
|
2019-11-26 06:30:45 -05:00
|
|
|
|
(make-parameter
|
|
|
|
|
(and=> (getenv "GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES")
|
2020-12-01 09:01:40 -05:00
|
|
|
|
(cut string-ci=? <> "yes"))))
|
2014-03-28 19:06:41 -04:00
|
|
|
|
|
2013-04-15 17:42:27 -04:00
|
|
|
|
(define %narinfo-ttl
|
|
|
|
|
;; Number of seconds during which cached narinfo lookups are considered
|
2016-03-16 10:31:18 -04:00
|
|
|
|
;; valid for substitute servers that do not advertise a TTL via the
|
|
|
|
|
;; 'Cache-Control' response header.
|
2015-05-04 09:38:30 -04:00
|
|
|
|
(* 36 3600))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
|
|
|
|
(define %narinfo-negative-ttl
|
2016-03-17 16:49:05 -04:00
|
|
|
|
;; Likewise, but for negative lookups---i.e., cached lookup failures (404).
|
2020-10-12 11:30:35 -04:00
|
|
|
|
(* 1 3600))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
2016-03-17 16:49:05 -04:00
|
|
|
|
(define %narinfo-transient-error-ttl
|
|
|
|
|
;; Likewise, but for transient errors such as 504 ("Gateway timeout").
|
|
|
|
|
(* 10 60))
|
|
|
|
|
|
2013-04-20 09:12:24 -04:00
|
|
|
|
(define %narinfo-expired-cache-entry-removal-delay
|
|
|
|
|
;; How often we want to remove files corresponding to expired cache entries.
|
|
|
|
|
(* 7 24 3600))
|
|
|
|
|
|
2013-07-11 16:42:41 -04:00
|
|
|
|
(define fields->alist
|
|
|
|
|
;; The narinfo format is really just like recutils.
|
|
|
|
|
recutils->alist)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
2013-06-17 18:11:40 -04:00
|
|
|
|
(define %fetch-timeout
|
|
|
|
|
;; Number of seconds after which networking is considered "slow".
|
2013-07-11 16:22:22 -04:00
|
|
|
|
5)
|
2013-06-17 18:11:40 -04:00
|
|
|
|
|
2013-06-29 16:10:06 -04:00
|
|
|
|
(define %random-state
|
|
|
|
|
(seed->random-state (+ (ash (cdr (gettimeofday)) 32) (getpid))))
|
|
|
|
|
|
2013-06-17 18:11:40 -04:00
|
|
|
|
(define-syntax-rule (with-timeout duration handler body ...)
|
|
|
|
|
"Run BODY; when DURATION seconds have expired, call HANDLER, and run BODY
|
|
|
|
|
again."
|
|
|
|
|
(begin
|
|
|
|
|
(sigaction SIGALRM
|
|
|
|
|
(lambda (signum)
|
|
|
|
|
(sigaction SIGALRM SIG_DFL)
|
|
|
|
|
handler))
|
|
|
|
|
(alarm duration)
|
|
|
|
|
(call-with-values
|
|
|
|
|
(lambda ()
|
|
|
|
|
(let try ()
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
body ...)
|
|
|
|
|
(lambda args
|
2013-11-13 19:09:07 -05:00
|
|
|
|
;; Before Guile v2.0.9-39-gfe51c7b, the SIGALRM triggers EINTR
|
|
|
|
|
;; because of the bug at
|
2013-06-29 16:10:06 -04:00
|
|
|
|
;; <http://lists.gnu.org/archive/html/guile-devel/2013-06/msg00050.html>.
|
|
|
|
|
;; When that happens, try again. Note: SA_RESTART cannot be
|
|
|
|
|
;; used because of <http://bugs.gnu.org/14640>.
|
2013-06-17 18:11:40 -04:00
|
|
|
|
(if (= EINTR (system-error-errno args))
|
2013-06-29 16:10:06 -04:00
|
|
|
|
(begin
|
|
|
|
|
;; Wait a little to avoid bursts.
|
|
|
|
|
(usleep (random 3000000 %random-state))
|
|
|
|
|
(try))
|
2013-06-17 18:11:40 -04:00
|
|
|
|
(apply throw args))))))
|
|
|
|
|
(lambda result
|
|
|
|
|
(alarm 0)
|
|
|
|
|
(sigaction SIGALRM SIG_DFL)
|
|
|
|
|
(apply values result)))))
|
|
|
|
|
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(define* (fetch uri #:key (buffered? #t) (timeout? #t)
|
|
|
|
|
(keep-alive? #f) (port #f))
|
2013-04-12 11:30:27 -04:00
|
|
|
|
"Return a binary input port to URI and the number of bytes it's expected to
|
2020-12-02 16:49:39 -05:00
|
|
|
|
provide.
|
|
|
|
|
|
|
|
|
|
When PORT is true, use it as the underlying I/O port for HTTP transfers; when
|
|
|
|
|
PORT is false, open a new connection for URI. When KEEP-ALIVE? is true, the
|
|
|
|
|
connection (typically PORT) is kept open once data has been fetched from URI."
|
2013-04-02 04:44:20 -04:00
|
|
|
|
(case (uri-scheme uri)
|
|
|
|
|
((file)
|
2013-08-22 11:14:20 -04:00
|
|
|
|
(let ((port (open-file (uri-path uri)
|
|
|
|
|
(if buffered? "rb" "r0b"))))
|
2013-04-12 11:30:27 -04:00
|
|
|
|
(values port (stat:size (stat port)))))
|
2016-03-10 05:53:03 -05:00
|
|
|
|
((http https)
|
2014-03-01 09:38:11 -05:00
|
|
|
|
(guard (c ((http-get-error? c)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "download from '~a' failed: ~a, ~s~%")
|
2016-03-14 12:09:46 -04:00
|
|
|
|
(uri->string (http-get-error-uri c))
|
|
|
|
|
(http-get-error-code c)
|
|
|
|
|
(http-get-error-reason c))))
|
2014-03-01 09:38:11 -05:00
|
|
|
|
;; Test this with:
|
|
|
|
|
;; sudo tc qdisc add dev eth0 root netem delay 1500ms
|
|
|
|
|
;; and then cancel with:
|
|
|
|
|
;; sudo tc qdisc del dev eth0 root
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(let ((port port))
|
2015-05-07 15:51:30 -04:00
|
|
|
|
(with-timeout (if timeout?
|
2014-03-01 09:38:11 -05:00
|
|
|
|
%fetch-timeout
|
|
|
|
|
0)
|
|
|
|
|
(begin
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(warning (G_ "while fetching ~a: server is somewhat slow~%")
|
2014-03-01 09:38:11 -05:00
|
|
|
|
(uri->string uri))
|
2018-02-15 10:13:36 -05:00
|
|
|
|
(warning (G_ "try `--no-substitutes' if the problem persists~%")))
|
2014-03-01 09:38:11 -05:00
|
|
|
|
(begin
|
|
|
|
|
(when (or (not port) (port-closed? port))
|
2017-03-17 18:41:37 -04:00
|
|
|
|
(set! port (guix:open-connection-for-uri
|
2020-12-02 16:49:39 -05:00
|
|
|
|
uri #:verify-certificate? #f)))
|
|
|
|
|
(unless (or buffered? (not (file-port? port)))
|
|
|
|
|
(setvbuf port 'none))
|
2016-11-12 06:57:36 -05:00
|
|
|
|
(http-fetch uri #:text? #f #:port port
|
2020-12-02 16:49:39 -05:00
|
|
|
|
#:keep-alive? keep-alive?
|
2016-11-12 06:57:36 -05:00
|
|
|
|
#:verify-certificate? #f))))))
|
2016-03-09 12:34:04 -05:00
|
|
|
|
(else
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "unsupported substitute URI scheme: ~a~%")
|
2016-03-09 12:34:04 -05:00
|
|
|
|
(uri->string uri)))))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
2015-07-13 05:38:31 -04:00
|
|
|
|
|
2013-04-02 04:44:20 -04:00
|
|
|
|
(define-record-type <narinfo>
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(%make-narinfo path uri-base uris compressions file-sizes file-hashes
|
|
|
|
|
nar-hash nar-size references deriver system
|
|
|
|
|
signature contents)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
narinfo?
|
|
|
|
|
(path narinfo-path)
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(uri-base narinfo-uri-base) ;URI of the cache it originates from
|
|
|
|
|
(uris narinfo-uris) ;list of strings
|
|
|
|
|
(compressions narinfo-compressions) ;list of strings
|
|
|
|
|
(file-sizes narinfo-file-sizes) ;list of (integers | #f)
|
|
|
|
|
(file-hashes narinfo-file-hashes)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
(nar-hash narinfo-hash)
|
|
|
|
|
(nar-size narinfo-size)
|
|
|
|
|
(references narinfo-references)
|
|
|
|
|
(deriver narinfo-deriver)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(system narinfo-system)
|
|
|
|
|
(signature narinfo-signature) ; canonical sexp
|
|
|
|
|
;; The original contents of a narinfo file. This field is needed because we
|
|
|
|
|
;; want to preserve the exact textual representation for verification purposes.
|
|
|
|
|
;; See <https://lists.gnu.org/archive/html/guix-devel/2014-02/msg00340.html>
|
|
|
|
|
;; for more information.
|
|
|
|
|
(contents narinfo-contents))
|
|
|
|
|
|
daemon: Let 'guix substitute' perform hash checks.
This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon. Consequently, it should reduce latency between
subsequent substitute downloads.
This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.
* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it. Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ. When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'. Parse it and handle
"success" and "hash-mismatch" accordingly. Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
2020-12-13 16:46:03 -05:00
|
|
|
|
(define (narinfo-hash-algorithm+value narinfo)
|
|
|
|
|
"Return two values: the hash algorithm used by NARINFO and its value as a
|
|
|
|
|
bytevector."
|
|
|
|
|
(match (string-tokenize (narinfo-hash narinfo)
|
|
|
|
|
(char-set-complement (char-set #\:)))
|
|
|
|
|
((algorithm base32)
|
|
|
|
|
(values (lookup-hash-algorithm (string->symbol algorithm))
|
|
|
|
|
(nix-base32-string->bytevector base32)))
|
|
|
|
|
(_
|
|
|
|
|
(raise (formatted-message
|
|
|
|
|
(G_ "invalid narinfo hash: ~s") (narinfo-hash narinfo))))))
|
|
|
|
|
|
2015-10-19 17:12:34 -04:00
|
|
|
|
(define (narinfo-hash->sha256 hash)
|
|
|
|
|
"If the string HASH denotes a sha256 hash, return it as a bytevector.
|
|
|
|
|
Otherwise return #f."
|
|
|
|
|
(and (string-prefix? "sha256:" hash)
|
|
|
|
|
(nix-base32-string->bytevector (string-drop hash 7))))
|
|
|
|
|
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(define (narinfo-signature->canonical-sexp str)
|
|
|
|
|
"Return the value of a narinfo's 'Signature' field as a canonical sexp."
|
|
|
|
|
(match (string-split str #\;)
|
2016-09-20 04:51:39 -04:00
|
|
|
|
((version host-name sig)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(let ((maybe-number (string->number version)))
|
|
|
|
|
(cond ((not (number? maybe-number))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "signature version must be a number: ~s~%")
|
2014-03-28 19:06:41 -04:00
|
|
|
|
version))
|
|
|
|
|
;; Currently, there are no other versions.
|
|
|
|
|
((not (= 1 maybe-number))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "unsupported signature version: ~a~%")
|
2014-03-28 19:06:41 -04:00
|
|
|
|
maybe-number))
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(else
|
|
|
|
|
(let ((signature (utf8->string (base64-decode sig))))
|
|
|
|
|
(catch 'gcry-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(string->canonical-sexp signature))
|
2014-04-22 05:41:52 -04:00
|
|
|
|
(lambda (key proc err)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "signature is not a valid \
|
2014-03-31 17:47:02 -04:00
|
|
|
|
s-expression: ~s~%")
|
|
|
|
|
signature))))))))
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(x
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "invalid format of the signature field: ~a~%") x))))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(define (narinfo-maker str cache-url)
|
|
|
|
|
"Return a narinfo constructor for narinfos originating from CACHE-URL. STR
|
|
|
|
|
must contain the original contents of a narinfo file."
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(lambda (path urls compressions file-hashes file-sizes
|
|
|
|
|
nar-hash nar-size references deriver system
|
|
|
|
|
signature)
|
2013-04-12 11:30:27 -04:00
|
|
|
|
"Return a new <narinfo> object."
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(define len (length urls))
|
|
|
|
|
(%make-narinfo path cache-url
|
2013-04-12 11:30:27 -04:00
|
|
|
|
;; Handle the case where URL is a relative URL.
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(map (lambda (url)
|
|
|
|
|
(or (string->uri url)
|
|
|
|
|
(string->uri
|
|
|
|
|
(string-append cache-url "/" url))))
|
|
|
|
|
urls)
|
|
|
|
|
compressions
|
|
|
|
|
(match file-sizes
|
|
|
|
|
(() (make-list len #f))
|
|
|
|
|
((lst ...) (map string->number lst)))
|
|
|
|
|
(match file-hashes
|
|
|
|
|
(() (make-list len #f))
|
|
|
|
|
((lst ...) (map string->number lst)))
|
2013-04-12 11:30:27 -04:00
|
|
|
|
nar-hash
|
|
|
|
|
(and=> nar-size string->number)
|
|
|
|
|
(string-tokenize references)
|
|
|
|
|
(match deriver
|
|
|
|
|
((or #f "") #f)
|
|
|
|
|
(_ deriver))
|
2014-03-28 19:06:41 -04:00
|
|
|
|
system
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(false-if-exception
|
|
|
|
|
(and=> signature narinfo-signature->canonical-sexp))
|
2014-03-28 19:06:41 -04:00
|
|
|
|
str)))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
2015-01-05 16:31:34 -05:00
|
|
|
|
(define* (read-narinfo port #:optional url
|
|
|
|
|
#:key size)
|
2014-03-28 19:06:41 -04:00
|
|
|
|
"Read a narinfo from PORT. If URL is true, it must be a string used to
|
2015-01-05 16:31:34 -05:00
|
|
|
|
build full URIs from relative URIs found while reading PORT. When SIZE is
|
|
|
|
|
true, read at most SIZE bytes from PORT; otherwise, read as much as possible.
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
|
|
|
|
|
No authentication and authorization checks are performed here!"
|
2015-01-05 16:31:34 -05:00
|
|
|
|
(let ((str (utf8->string (if size
|
|
|
|
|
(get-bytevector-n port size)
|
|
|
|
|
(get-bytevector-all port)))))
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(alist->record (call-with-input-string str fields->alist)
|
|
|
|
|
(narinfo-maker str url)
|
|
|
|
|
'("StorePath" "URL" "Compression"
|
|
|
|
|
"FileHash" "FileSize" "NarHash" "NarSize"
|
|
|
|
|
"References" "Deriver" "System"
|
2019-05-31 10:26:08 -04:00
|
|
|
|
"Signature")
|
|
|
|
|
'("URL" "Compression" "FileSize" "FileHash"))))
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
|
2014-03-31 17:47:02 -04:00
|
|
|
|
(define (narinfo-sha256 narinfo)
|
|
|
|
|
"Return the sha256 hash of NARINFO as a bytevector, or #f if NARINFO lacks a
|
|
|
|
|
'Signature' field."
|
2018-12-13 13:45:47 -05:00
|
|
|
|
(define %mandatory-fields
|
|
|
|
|
;; List of fields that must be signed. If they are not signed, the
|
|
|
|
|
;; narinfo is considered unsigned.
|
|
|
|
|
'("StorePath" "NarHash" "References"))
|
|
|
|
|
|
2014-03-31 17:47:02 -04:00
|
|
|
|
(let ((contents (narinfo-contents narinfo)))
|
2015-01-08 19:10:31 -05:00
|
|
|
|
(match (string-contains contents "Signature:")
|
2014-03-31 17:47:02 -04:00
|
|
|
|
(#f #f)
|
2015-01-08 19:10:31 -05:00
|
|
|
|
(index
|
2018-12-13 13:45:47 -05:00
|
|
|
|
(let* ((above-signature (string-take contents index))
|
|
|
|
|
(signed-fields (match (call-with-input-string above-signature
|
|
|
|
|
fields->alist)
|
|
|
|
|
(((fields . values) ...) fields))))
|
|
|
|
|
(and (every (cut member <> signed-fields) %mandatory-fields)
|
|
|
|
|
(sha256 (string->utf8 above-signature))))))))
|
2014-03-31 17:47:02 -04:00
|
|
|
|
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(define* (valid-narinfo? narinfo #:optional (acl (current-acl))
|
|
|
|
|
#:key verbose?)
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
"Return #t if NARINFO's signature is not valid."
|
2020-12-24 11:01:25 -05:00
|
|
|
|
(let ((hash (narinfo-sha256 narinfo))
|
|
|
|
|
(signature (narinfo-signature narinfo))
|
|
|
|
|
(uri (uri->string (first (narinfo-uris narinfo)))))
|
|
|
|
|
(and hash signature
|
|
|
|
|
(signature-case (signature hash acl)
|
|
|
|
|
(valid-signature #t)
|
|
|
|
|
(invalid-signature
|
|
|
|
|
(when verbose?
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"invalid signature for substitute at '~a'~%"
|
|
|
|
|
uri))
|
|
|
|
|
#f)
|
|
|
|
|
(hash-mismatch
|
|
|
|
|
(when verbose?
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"hash mismatch for substitute at '~a'~%"
|
|
|
|
|
uri))
|
|
|
|
|
#f)
|
|
|
|
|
(unauthorized-key
|
|
|
|
|
(when verbose?
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"substitute at '~a' is signed by an \
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
unauthorized party~%"
|
2020-12-24 11:01:25 -05:00
|
|
|
|
uri))
|
|
|
|
|
#f)
|
|
|
|
|
(corrupt-signature
|
|
|
|
|
(when verbose?
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
"corrupt signature for substitute at '~a'~%"
|
|
|
|
|
uri))
|
|
|
|
|
#f)))))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
|
|
|
|
(define (write-narinfo narinfo port)
|
|
|
|
|
"Write NARINFO to PORT."
|
2014-03-28 19:06:41 -04:00
|
|
|
|
(put-bytevector port (string->utf8 (narinfo-contents narinfo))))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
|
|
|
|
(define (narinfo->string narinfo)
|
|
|
|
|
"Return the external representation of NARINFO."
|
|
|
|
|
(call-with-output-string (cut write-narinfo narinfo <>)))
|
|
|
|
|
|
2014-03-26 18:31:31 -04:00
|
|
|
|
(define (string->narinfo str cache-uri)
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
"Return the narinfo represented by STR. Assume CACHE-URI as the base URI of
|
|
|
|
|
the cache STR originates form."
|
2014-03-26 18:31:31 -04:00
|
|
|
|
(call-with-input-string str (cut read-narinfo <> cache-uri)))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
2015-07-13 09:52:29 -04:00
|
|
|
|
(define (narinfo-cache-file cache-url path)
|
|
|
|
|
"Return the name of the local file that contains an entry for PATH. The
|
|
|
|
|
entry is stored in a sub-directory specific to CACHE-URL."
|
2016-05-20 11:18:58 -04:00
|
|
|
|
;; The daemon does not sanitize its input, so PATH could be something like
|
|
|
|
|
;; "/gnu/store/foo". Gracefully handle that.
|
|
|
|
|
(match (store-path-hash-part path)
|
|
|
|
|
(#f
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "'~a' does not name a store item~%") path))
|
2016-05-20 11:18:58 -04:00
|
|
|
|
((? string? hash-part)
|
|
|
|
|
(string-append %narinfo-cache-directory "/"
|
|
|
|
|
(bytevector->base32-string (sha256 (string->utf8 cache-url)))
|
|
|
|
|
"/" hash-part))))
|
2015-07-13 09:52:29 -04:00
|
|
|
|
|
|
|
|
|
(define (cached-narinfo cache-url path)
|
|
|
|
|
"Check locally if we have valid info about PATH coming from CACHE-URL.
|
|
|
|
|
Return two values: a Boolean indicating whether we have valid cached info, and
|
|
|
|
|
that info, which may be either #f (when PATH is unavailable) or the narinfo
|
|
|
|
|
for PATH."
|
2013-04-15 17:42:27 -04:00
|
|
|
|
(define now
|
|
|
|
|
(current-time time-monotonic))
|
|
|
|
|
|
|
|
|
|
(define cache-file
|
2015-07-13 09:52:29 -04:00
|
|
|
|
(narinfo-cache-file cache-url path))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(call-with-input-file cache-file
|
|
|
|
|
(lambda (p)
|
|
|
|
|
(match (read p)
|
2016-03-16 09:51:37 -04:00
|
|
|
|
(('narinfo ('version 2)
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
('cache-uri cache-uri)
|
2017-05-11 04:24:49 -04:00
|
|
|
|
('date date) ('ttl ttl) ('value #f))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
;; A cached negative lookup.
|
2017-05-11 04:24:49 -04:00
|
|
|
|
(if (obsolete? date now ttl)
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(values #f #f)
|
|
|
|
|
(values #t #f)))
|
2016-03-16 09:51:37 -04:00
|
|
|
|
(('narinfo ('version 2)
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
('cache-uri cache-uri)
|
2016-03-16 09:51:37 -04:00
|
|
|
|
('date date) ('ttl ttl) ('value value))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
;; A cached positive lookup
|
2016-03-16 09:51:37 -04:00
|
|
|
|
(if (obsolete? date now ttl)
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(values #f #f)
|
|
|
|
|
(values #t (string->narinfo value cache-uri))))
|
|
|
|
|
(('narinfo ('version v) _ ...)
|
|
|
|
|
(values #f #f))))))
|
|
|
|
|
(lambda _
|
|
|
|
|
(values #f #f))))
|
|
|
|
|
|
2016-03-16 10:31:18 -04:00
|
|
|
|
(define (cache-narinfo! cache-url path narinfo ttl)
|
|
|
|
|
"Cache locally NARNIFO for PATH, which originates from CACHE-URL, with the
|
|
|
|
|
given TTL (a number of seconds or #f). NARINFO may be #f, in which case it
|
|
|
|
|
indicates that PATH is unavailable at CACHE-URL."
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(define now
|
|
|
|
|
(current-time time-monotonic))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(define (cache-entry cache-uri narinfo)
|
2016-03-16 09:51:37 -04:00
|
|
|
|
`(narinfo (version 2)
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(cache-uri ,cache-uri)
|
2013-04-15 17:42:27 -04:00
|
|
|
|
(date ,(time-second now))
|
2016-03-16 10:31:18 -04:00
|
|
|
|
(ttl ,(or ttl
|
|
|
|
|
(if narinfo %narinfo-ttl %narinfo-negative-ttl)))
|
2013-04-15 17:42:27 -04:00
|
|
|
|
(value ,(and=> narinfo narinfo->string))))
|
|
|
|
|
|
2015-07-13 09:52:29 -04:00
|
|
|
|
(let ((file (narinfo-cache-file cache-url path)))
|
2016-06-22 17:46:32 -04:00
|
|
|
|
(mkdir-p (dirname file))
|
|
|
|
|
(with-atomic-file-output file
|
|
|
|
|
(lambda (out)
|
|
|
|
|
(write (cache-entry cache-url narinfo) out))))
|
2015-07-13 09:52:29 -04:00
|
|
|
|
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
narinfo)
|
|
|
|
|
|
|
|
|
|
(define (narinfo-request cache-url path)
|
|
|
|
|
"Return an HTTP request for the narinfo of PATH at CACHE-URL."
|
|
|
|
|
(let ((url (string-append cache-url "/" (store-path-hash-part path)
|
2017-03-30 13:21:20 -04:00
|
|
|
|
".narinfo"))
|
|
|
|
|
(headers '((User-Agent . "GNU Guile"))))
|
|
|
|
|
(build-request (string->uri url) #:method 'GET #:headers headers)))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
2017-10-25 23:57:06 -04:00
|
|
|
|
(define (at-most max-length lst)
|
2020-12-02 16:49:39 -05:00
|
|
|
|
"If LST is shorter than MAX-LENGTH, return it and the empty list; otherwise
|
|
|
|
|
return its MAX-LENGTH first elements and its tail."
|
2017-10-25 23:57:06 -04:00
|
|
|
|
(let loop ((len 0)
|
|
|
|
|
(lst lst)
|
|
|
|
|
(result '()))
|
|
|
|
|
(match lst
|
|
|
|
|
(()
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(values (reverse result) '()))
|
2017-10-25 23:57:06 -04:00
|
|
|
|
((head . tail)
|
|
|
|
|
(if (>= len max-length)
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(values (reverse result) lst)
|
2017-10-25 23:57:06 -04:00
|
|
|
|
(loop (+ 1 len) tail (cons head result)))))))
|
|
|
|
|
|
2016-03-14 17:44:59 -04:00
|
|
|
|
(define* (http-multiple-get base-uri proc seed requests
|
2020-03-02 15:17:18 -05:00
|
|
|
|
#:key port (verify-certificate? #t)
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(open-connection guix:open-connection-for-uri)
|
|
|
|
|
(keep-alive? #t)
|
2020-03-02 15:17:18 -05:00
|
|
|
|
(batch-size 1000))
|
2016-03-10 05:53:03 -05:00
|
|
|
|
"Send all of REQUESTS to the server at BASE-URI. Call PROC for each
|
2015-10-28 06:45:27 -04:00
|
|
|
|
response, passing it the request object, the response, a port from which to
|
|
|
|
|
read the response body, and the previous result, starting with SEED, à la
|
2020-12-19 09:41:46 -05:00
|
|
|
|
'fold'. Return the final result.
|
|
|
|
|
|
|
|
|
|
When PORT is specified, use it as the initial connection on which HTTP
|
|
|
|
|
requests are sent; otherwise call OPEN-CONNECTION to open a new connection for
|
|
|
|
|
a URI. When KEEP-ALIVE? is false, close the connection port before
|
|
|
|
|
returning."
|
2016-03-14 17:44:59 -04:00
|
|
|
|
(let connect ((port port)
|
|
|
|
|
(requests requests)
|
2015-10-28 06:45:27 -04:00
|
|
|
|
(result seed))
|
2019-11-28 05:41:32 -05:00
|
|
|
|
(define batch
|
2020-03-02 15:17:18 -05:00
|
|
|
|
(at-most batch-size requests))
|
2019-11-28 05:41:32 -05:00
|
|
|
|
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
;; (format (current-error-port) "connecting (~a requests left)..."
|
|
|
|
|
;; (length requests))
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(let ((p (or port (open-connection base-uri
|
|
|
|
|
#:verify-certificate?
|
|
|
|
|
verify-certificate?))))
|
2016-03-10 05:53:03 -05:00
|
|
|
|
;; For HTTPS, P is not a file port and does not support 'setvbuf'.
|
|
|
|
|
(when (file-port? p)
|
2019-01-07 04:57:18 -05:00
|
|
|
|
(setvbuf p 'block (expt 2 16)))
|
2016-03-10 05:53:03 -05:00
|
|
|
|
|
2019-11-28 05:41:32 -05:00
|
|
|
|
;; Send BATCH in a row.
|
2016-03-10 07:53:23 -05:00
|
|
|
|
;; XXX: Do our own caching to work around inefficiencies when
|
|
|
|
|
;; communicating over TLS: <http://bugs.gnu.org/22966>.
|
|
|
|
|
(let-values (((buffer get) (open-bytevector-output-port)))
|
2018-02-15 10:13:36 -05:00
|
|
|
|
;; Inherit the HTTP proxying property from P.
|
|
|
|
|
(set-http-proxy-port?! buffer (http-proxy-port? p))
|
2016-03-10 07:53:23 -05:00
|
|
|
|
|
2017-10-25 23:57:06 -04:00
|
|
|
|
(for-each (cut write-request <> buffer)
|
2019-11-28 05:41:32 -05:00
|
|
|
|
batch)
|
2016-03-10 07:53:23 -05:00
|
|
|
|
(put-bytevector p (get))
|
|
|
|
|
(force-output p))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
|
|
|
|
;; Now start processing responses.
|
2019-11-28 05:41:32 -05:00
|
|
|
|
(let loop ((sent batch)
|
|
|
|
|
(processed 0)
|
|
|
|
|
(result result))
|
|
|
|
|
(match sent
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(()
|
2019-11-28 05:41:32 -05:00
|
|
|
|
(match (drop requests processed)
|
|
|
|
|
(()
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(unless keep-alive?
|
|
|
|
|
(close-port p))
|
2019-11-28 05:41:32 -05:00
|
|
|
|
(reverse result))
|
|
|
|
|
(remainder
|
2020-03-02 15:13:39 -05:00
|
|
|
|
(connect p remainder result))))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
((head tail ...)
|
2015-07-06 18:52:16 -04:00
|
|
|
|
(let* ((resp (read-response p))
|
|
|
|
|
(body (response-body-port resp))
|
2015-10-28 06:45:27 -04:00
|
|
|
|
(result (proc head resp body result)))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
;; The server can choose to stop responding at any time, in which
|
|
|
|
|
;; case we have to try again. Check whether that is the case.
|
2015-07-06 18:52:16 -04:00
|
|
|
|
;; Note that even upon "Connection: close", we can read from BODY.
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(match (assq 'connection (response-headers resp))
|
|
|
|
|
(('connection 'close)
|
2020-01-03 09:47:12 -05:00
|
|
|
|
(close-port p)
|
2019-11-28 05:41:32 -05:00
|
|
|
|
(connect #f ;try again
|
2020-01-15 04:05:54 -05:00
|
|
|
|
(drop requests (+ 1 processed))
|
2019-11-28 05:41:32 -05:00
|
|
|
|
result))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(_
|
2019-11-28 05:41:32 -05:00
|
|
|
|
(loop tail (+ 1 processed) result)))))))))) ;keep going
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
|
|
|
|
(define (read-to-eof port)
|
|
|
|
|
"Read from PORT until EOF is reached. The data are discarded."
|
|
|
|
|
(dump-port port (%make-void-port "w")))
|
|
|
|
|
|
|
|
|
|
(define (narinfo-from-file file url)
|
|
|
|
|
"Attempt to read a narinfo from FILE, using URL as the cache URL. Return #f
|
|
|
|
|
if file doesn't exist, and the narinfo otherwise."
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(call-with-input-file file
|
|
|
|
|
(cut read-narinfo <> url)))
|
|
|
|
|
(lambda args
|
|
|
|
|
(if (= ENOENT (system-error-errno args))
|
|
|
|
|
#f
|
|
|
|
|
(apply throw args)))))
|
|
|
|
|
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(define %unreachable-hosts
|
|
|
|
|
;; Set of names of unreachable hosts.
|
|
|
|
|
(make-hash-table))
|
|
|
|
|
|
|
|
|
|
(define* (open-connection-for-uri/maybe uri
|
|
|
|
|
#:key
|
2020-12-19 09:41:46 -05:00
|
|
|
|
fresh?
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(time %fetch-timeout))
|
2020-12-19 09:41:46 -05:00
|
|
|
|
"Open a connection to URI via 'open-connection-for-uri/cached' and return a
|
|
|
|
|
port to it, or, if connection failed, print a warning and return #f. Pass
|
|
|
|
|
#:fresh? to 'open-connection-for-uri/cached'."
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(define host
|
|
|
|
|
(uri-host uri))
|
|
|
|
|
|
|
|
|
|
(catch #t
|
|
|
|
|
(lambda ()
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(open-connection-for-uri/cached uri #:timeout time
|
|
|
|
|
#:fresh? fresh?))
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(match-lambda*
|
|
|
|
|
(('getaddrinfo-error error)
|
|
|
|
|
(unless (hash-ref %unreachable-hosts host)
|
|
|
|
|
(hash-set! %unreachable-hosts host #t) ;warn only once
|
|
|
|
|
(warning (G_ "~a: host not found: ~a~%")
|
|
|
|
|
host (gai-strerror error)))
|
|
|
|
|
#f)
|
|
|
|
|
(('system-error . args)
|
|
|
|
|
(unless (hash-ref %unreachable-hosts host)
|
|
|
|
|
(hash-set! %unreachable-hosts host #t)
|
|
|
|
|
(warning (G_ "~a: connection failed: ~a~%") host
|
|
|
|
|
(strerror
|
|
|
|
|
(system-error-errno `(system-error ,@args)))))
|
|
|
|
|
#f)
|
|
|
|
|
(args
|
|
|
|
|
(apply throw args)))))
|
|
|
|
|
|
2015-07-13 05:38:31 -04:00
|
|
|
|
(define (fetch-narinfos url paths)
|
|
|
|
|
"Retrieve all the narinfos for PATHS from the cache at URL and return them."
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(define update-progress!
|
2017-07-21 08:13:58 -04:00
|
|
|
|
(let ((done 0)
|
|
|
|
|
(total (length paths)))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(lambda ()
|
2018-06-12 03:28:28 -04:00
|
|
|
|
(display "\r\x1b[K" (current-error-port)) ;erase current line
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(force-output (current-error-port))
|
|
|
|
|
(format (current-error-port)
|
2018-06-12 04:30:30 -04:00
|
|
|
|
(G_ "updating substitutes from '~a'... ~5,1f%")
|
2017-07-21 08:13:58 -04:00
|
|
|
|
url (* 100. (/ done total)))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(set! done (+ 1 done)))))
|
|
|
|
|
|
2017-07-21 08:07:29 -04:00
|
|
|
|
(define hash-part->path
|
|
|
|
|
(let ((mapping (fold (lambda (path result)
|
|
|
|
|
(vhash-cons (store-path-hash-part path) path
|
|
|
|
|
result))
|
|
|
|
|
vlist-null
|
|
|
|
|
paths)))
|
|
|
|
|
(lambda (hash)
|
|
|
|
|
(match (vhash-assoc hash mapping)
|
|
|
|
|
(#f #f)
|
|
|
|
|
((_ . path) path)))))
|
|
|
|
|
|
2015-10-28 06:45:27 -04:00
|
|
|
|
(define (handle-narinfo-response request response port result)
|
2016-03-17 16:49:05 -04:00
|
|
|
|
(let* ((code (response-code response))
|
|
|
|
|
(len (response-content-length response))
|
2016-03-16 10:31:18 -04:00
|
|
|
|
(cache (response-cache-control response))
|
|
|
|
|
(ttl (and cache (assoc-ref cache 'max-age))))
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(update-progress!)
|
|
|
|
|
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
;; Make sure to read no more than LEN bytes since subsequent bytes may
|
|
|
|
|
;; belong to the next response.
|
2016-03-17 16:49:05 -04:00
|
|
|
|
(if (= code 200) ; hit
|
|
|
|
|
(let ((narinfo (read-narinfo port url #:size len)))
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(if (string=? (dirname (narinfo-path narinfo))
|
|
|
|
|
(%store-prefix))
|
|
|
|
|
(begin
|
|
|
|
|
(cache-narinfo! url (narinfo-path narinfo) narinfo ttl)
|
|
|
|
|
(cons narinfo result))
|
|
|
|
|
result))
|
2016-03-17 16:49:05 -04:00
|
|
|
|
(let* ((path (uri-path (request-uri request)))
|
2016-07-14 09:19:07 -04:00
|
|
|
|
(hash-part (basename
|
|
|
|
|
(string-drop-right path 8)))) ;drop ".narinfo"
|
2016-03-17 16:49:05 -04:00
|
|
|
|
(if len
|
|
|
|
|
(get-bytevector-n port len)
|
|
|
|
|
(read-to-eof port))
|
2017-07-21 08:07:29 -04:00
|
|
|
|
(cache-narinfo! url (hash-part->path hash-part) #f
|
2020-10-28 14:03:59 -04:00
|
|
|
|
(if (or (= 404 code) (= 202 code))
|
2016-03-17 16:49:05 -04:00
|
|
|
|
ttl
|
|
|
|
|
%narinfo-transient-error-ttl))
|
|
|
|
|
result))))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(define (do-fetch uri)
|
2015-11-27 18:02:23 -05:00
|
|
|
|
(case (and=> uri uri-scheme)
|
2016-03-10 05:53:03 -05:00
|
|
|
|
((http https)
|
2020-12-19 09:41:46 -05:00
|
|
|
|
;; Note: Do not check HTTPS server certificates to avoid depending
|
|
|
|
|
;; on the X.509 PKI. We can do it because we authenticate
|
|
|
|
|
;; narinfos, which provides a much stronger guarantee.
|
|
|
|
|
(let* ((requests (map (cut narinfo-request url <>) paths))
|
|
|
|
|
(result (call-with-cached-connection uri
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(if port
|
|
|
|
|
(begin
|
|
|
|
|
(update-progress!)
|
|
|
|
|
(http-multiple-get uri
|
|
|
|
|
handle-narinfo-response '()
|
|
|
|
|
requests
|
|
|
|
|
#:open-connection
|
|
|
|
|
open-connection-for-uri/cached
|
|
|
|
|
#:verify-certificate? #f
|
|
|
|
|
#:port port))
|
|
|
|
|
'()))
|
|
|
|
|
open-connection-for-uri/maybe)))
|
|
|
|
|
result))
|
2015-11-27 18:02:23 -05:00
|
|
|
|
((file #f)
|
|
|
|
|
(let* ((base (string-append (uri-path uri) "/"))
|
|
|
|
|
(files (map (compose (cut string-append base <> ".narinfo")
|
|
|
|
|
store-path-hash-part)
|
|
|
|
|
paths)))
|
|
|
|
|
(filter-map (cut narinfo-from-file <> url) files)))
|
|
|
|
|
(else
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "~s: unsupported server URI scheme~%")
|
2015-11-27 18:02:23 -05:00
|
|
|
|
(if uri (uri-scheme uri) url)))))
|
|
|
|
|
|
2019-11-21 14:36:20 -05:00
|
|
|
|
(do-fetch (string->uri url)))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
|
|
|
|
(define (lookup-narinfos cache paths)
|
|
|
|
|
"Return the narinfos for PATHS, invoking the server at CACHE when no
|
|
|
|
|
information is available locally."
|
|
|
|
|
(let-values (((cached missing)
|
|
|
|
|
(fold2 (lambda (path cached missing)
|
|
|
|
|
(let-values (((valid? value)
|
2015-07-13 09:52:29 -04:00
|
|
|
|
(cached-narinfo cache path)))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(if valid?
|
2015-10-28 06:48:27 -04:00
|
|
|
|
(if value
|
|
|
|
|
(values (cons value cached) missing)
|
|
|
|
|
(values cached missing))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
(values cached (cons path missing)))))
|
|
|
|
|
'()
|
|
|
|
|
'()
|
|
|
|
|
paths)))
|
|
|
|
|
(if (null? missing)
|
|
|
|
|
cached
|
2015-07-13 05:38:31 -04:00
|
|
|
|
(let ((missing (fetch-narinfos cache missing)))
|
|
|
|
|
(append cached (or missing '()))))))
|
substitute-binary: Pipeline HTTP requests instead of using threads.
* guix/scripts/substitute-binary.scm (fetch-narinfo, %lookup-threads,
n-par-map*): Remove.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
http-multiple-get, read-to-eof, fetch-narinfos, lookup-narinfos,
narinfo-from-file): New procedures.
(lookup-narinfo): Rewrite in terms of 'lookup-narinfos'.
(guix-substitute-binary): Use 'lookup-narinfos' instead of
'lookup-narinfo'.
2015-03-23 17:25:04 -04:00
|
|
|
|
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(define (equivalent-narinfo? narinfo1 narinfo2)
|
|
|
|
|
"Return true if NARINFO1 and NARINFO2 are equivalent--i.e., if they describe
|
|
|
|
|
the same store item. This ignores unnecessary metadata such as the Nar URL."
|
|
|
|
|
(and (string=? (narinfo-hash narinfo1)
|
|
|
|
|
(narinfo-hash narinfo2))
|
|
|
|
|
|
|
|
|
|
;; The following is not needed if all we want is to download a valid
|
|
|
|
|
;; nar, but it's necessary if we want valid narinfo.
|
|
|
|
|
(string=? (narinfo-path narinfo1)
|
|
|
|
|
(narinfo-path narinfo2))
|
|
|
|
|
(equal? (narinfo-references narinfo1)
|
|
|
|
|
(narinfo-references narinfo2))
|
|
|
|
|
|
|
|
|
|
(= (narinfo-size narinfo1)
|
|
|
|
|
(narinfo-size narinfo2))))
|
|
|
|
|
|
|
|
|
|
(define (lookup-narinfos/diverse caches paths authorized?)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
"Look up narinfos for PATHS on all of CACHES, a list of URLS, in that order.
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
That is, when a cache lacks an AUTHORIZED? narinfo, look it up in the next
|
|
|
|
|
cache, and so on.
|
|
|
|
|
|
|
|
|
|
Return a list of narinfos for PATHS or a subset thereof. The returned
|
|
|
|
|
narinfos are either AUTHORIZED?, or they claim a hash that matches an
|
|
|
|
|
AUTHORIZED? narinfo."
|
|
|
|
|
(define (select-hit result)
|
|
|
|
|
(lambda (path)
|
|
|
|
|
(match (vhash-fold* cons '() path result)
|
|
|
|
|
((one)
|
|
|
|
|
one)
|
|
|
|
|
((several ..1)
|
|
|
|
|
(let ((authorized (find authorized? (reverse several))))
|
|
|
|
|
(and authorized
|
|
|
|
|
(find (cut equivalent-narinfo? <> authorized)
|
|
|
|
|
several)))))))
|
|
|
|
|
|
2015-10-28 05:11:43 -04:00
|
|
|
|
(let loop ((caches caches)
|
|
|
|
|
(paths paths)
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(result vlist-null) ;path->narinfo vhash
|
|
|
|
|
(hits '())) ;paths
|
2015-10-28 05:11:43 -04:00
|
|
|
|
(match paths
|
|
|
|
|
(() ;we're done
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
;; Now iterate on all the HITS, and return exactly one match for each
|
|
|
|
|
;; hit: the first narinfo that is authorized, or that has the same hash
|
|
|
|
|
;; as an authorized narinfo, in the order of CACHES.
|
|
|
|
|
(filter-map (select-hit result) hits))
|
2015-10-28 05:11:43 -04:00
|
|
|
|
(_
|
|
|
|
|
(match caches
|
|
|
|
|
((cache rest ...)
|
|
|
|
|
(let* ((narinfos (lookup-narinfos cache paths))
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(definite (map narinfo-path (filter authorized? narinfos)))
|
|
|
|
|
(missing (lset-difference string=? paths definite))) ;XXX: perf
|
|
|
|
|
(loop rest missing
|
|
|
|
|
(fold vhash-cons result
|
|
|
|
|
(map narinfo-path narinfos) narinfos)
|
|
|
|
|
(append definite hits))))
|
2015-10-28 05:11:43 -04:00
|
|
|
|
(() ;that's it
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(filter-map (select-hit result) hits)))))))
|
2015-10-28 05:11:43 -04:00
|
|
|
|
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(define (lookup-narinfo caches path authorized?)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
"Return the narinfo for PATH in CACHES, or #f when no substitute for PATH
|
|
|
|
|
was found."
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(match (lookup-narinfos/diverse caches (list path) authorized?)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
((answer) answer)
|
|
|
|
|
(_ #f)))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(define (cached-narinfo-expiration-time file)
|
|
|
|
|
"Return the expiration time for FILE, which is a cached narinfo."
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(call-with-input-file file
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(match (read port)
|
|
|
|
|
(('narinfo ('version 2) ('cache-uri uri)
|
|
|
|
|
('date date) ('ttl ttl) ('value #f))
|
2017-05-11 04:24:49 -04:00
|
|
|
|
(+ date ttl))
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(('narinfo ('version 2) ('cache-uri uri)
|
|
|
|
|
('date date) ('ttl ttl) ('value value))
|
|
|
|
|
(+ date ttl))
|
|
|
|
|
(x
|
|
|
|
|
0)))))
|
|
|
|
|
(lambda args
|
|
|
|
|
;; FILE may have been deleted.
|
|
|
|
|
0)))
|
2013-04-20 09:12:24 -04:00
|
|
|
|
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(define (narinfo-cache-directories directory)
|
2015-07-13 09:52:29 -04:00
|
|
|
|
"Return the list of narinfo cache directories (one per cache URL.)"
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(map (cut string-append directory "/" <>)
|
2015-07-13 09:52:29 -04:00
|
|
|
|
(scandir %narinfo-cache-directory
|
|
|
|
|
(lambda (item)
|
|
|
|
|
(and (not (member item '("." "..")))
|
|
|
|
|
(file-is-directory?
|
|
|
|
|
(string-append %narinfo-cache-directory
|
|
|
|
|
"/" item)))))))
|
|
|
|
|
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(define* (cached-narinfo-files #:optional
|
|
|
|
|
(directory %narinfo-cache-directory))
|
|
|
|
|
"Return the list of cached narinfo files under DIRECTORY."
|
|
|
|
|
(append-map (lambda (directory)
|
|
|
|
|
(map (cut string-append directory "/" <>)
|
|
|
|
|
(scandir directory
|
|
|
|
|
(lambda (file)
|
|
|
|
|
(= (string-length file) 32)))))
|
|
|
|
|
(narinfo-cache-directories directory)))
|
2013-04-20 09:12:24 -04:00
|
|
|
|
|
2013-05-29 17:21:54 -04:00
|
|
|
|
(define-syntax with-networking
|
|
|
|
|
(syntax-rules ()
|
2016-03-22 04:57:15 -04:00
|
|
|
|
"Catch DNS lookup errors and TLS errors and gracefully exit."
|
2013-05-29 17:21:54 -04:00
|
|
|
|
;; Note: no attempt is made to catch other networking errors, because DNS
|
|
|
|
|
;; lookup errors are typically the first one, and because other errors are
|
|
|
|
|
;; a subset of `system-error', which is harder to filter.
|
|
|
|
|
((_ exp ...)
|
2016-03-22 04:57:15 -04:00
|
|
|
|
(catch #t
|
2013-05-29 17:21:54 -04:00
|
|
|
|
(lambda () exp ...)
|
2016-03-22 04:57:15 -04:00
|
|
|
|
(match-lambda*
|
|
|
|
|
(('getaddrinfo-error error)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "host name lookup error: ~a~%")
|
2016-03-22 04:57:15 -04:00
|
|
|
|
(gai-strerror error)))
|
|
|
|
|
(('gnutls-error error proc . rest)
|
|
|
|
|
(let ((error->string (module-ref (resolve-interface '(gnutls))
|
|
|
|
|
'error->string)))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "TLS error in procedure '~a': ~a~%")
|
2016-03-22 04:57:15 -04:00
|
|
|
|
proc (error->string error))))
|
|
|
|
|
(args
|
|
|
|
|
(apply throw args)))))))
|
2013-05-29 17:21:54 -04:00
|
|
|
|
|
2013-09-13 17:42:36 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Help.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (show-help)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(display (G_ "Usage: guix substitute [OPTION]...
|
2013-09-13 17:42:36 -04:00
|
|
|
|
Internal tool to substitute a pre-built binary to a local build.\n"))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(display (G_ "
|
2013-09-13 17:42:36 -04:00
|
|
|
|
--query report on the availability of substitutes for the
|
|
|
|
|
store file names passed on the standard input"))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(display (G_ "
|
2013-09-13 17:42:36 -04:00
|
|
|
|
--substitute STORE-FILE DESTINATION
|
|
|
|
|
download STORE-FILE and store it as a Nar in file
|
|
|
|
|
DESTINATION"))
|
|
|
|
|
(newline)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(display (G_ "
|
2013-09-13 17:42:36 -04:00
|
|
|
|
-h, --help display this help and exit"))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(display (G_ "
|
2013-09-13 17:42:36 -04:00
|
|
|
|
-V, --version display version information and exit"))
|
|
|
|
|
(newline)
|
|
|
|
|
(show-bug-report-information))
|
|
|
|
|
|
|
|
|
|
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Daemon/substituter protocol.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (display-narinfo-data narinfo)
|
2015-09-03 17:37:33 -04:00
|
|
|
|
"Write to the current output port the contents of NARINFO in the format
|
2015-07-13 11:51:02 -04:00
|
|
|
|
expected by the daemon."
|
|
|
|
|
(format #t "~a\n~a\n~a\n"
|
|
|
|
|
(narinfo-path narinfo)
|
|
|
|
|
(or (and=> (narinfo-deriver narinfo)
|
|
|
|
|
(cute string-append (%store-prefix) "/" <>))
|
|
|
|
|
"")
|
|
|
|
|
(length (narinfo-references narinfo)))
|
|
|
|
|
(for-each (cute format #t "~a/~a~%" (%store-prefix) <>)
|
|
|
|
|
(narinfo-references narinfo))
|
2019-05-31 10:26:08 -04:00
|
|
|
|
|
2019-12-04 17:07:03 -05:00
|
|
|
|
(let-values (((uri compression file-size) (narinfo-best-uri narinfo)))
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(format #t "~a\n~a\n"
|
|
|
|
|
(or file-size 0)
|
|
|
|
|
(or (narinfo-size narinfo) 0))))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
|
|
|
|
(define* (process-query command
|
2015-10-28 05:11:43 -04:00
|
|
|
|
#:key cache-urls acl)
|
2015-07-13 11:51:02 -04:00
|
|
|
|
"Reply to COMMAND, a query as written by the daemon to this process's
|
|
|
|
|
standard input. Use ACL as the access-control list against which to check
|
|
|
|
|
authorized substitutes."
|
2020-12-24 11:01:25 -05:00
|
|
|
|
(define valid?
|
|
|
|
|
(if (%allow-unauthenticated-substitutes?)
|
|
|
|
|
(begin
|
|
|
|
|
(warn-about-missing-authentication)
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
2020-12-24 11:01:25 -05:00
|
|
|
|
(const #t))
|
|
|
|
|
(lambda (obj)
|
|
|
|
|
(valid-narinfo? obj acl))))
|
2020-12-01 09:01:40 -05:00
|
|
|
|
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(match (string-tokenize command)
|
|
|
|
|
(("have" paths ..1)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
;; Return the subset of PATHS available in CACHE-URLS.
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(let ((substitutable (lookup-narinfos/diverse cache-urls paths valid?)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(for-each (lambda (narinfo)
|
|
|
|
|
(format #t "~a~%" (narinfo-path narinfo)))
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
substitutable)
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(newline)))
|
|
|
|
|
(("info" paths ..1)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
;; Reply info about PATHS if it's in CACHE-URLS.
|
substitute: Download from unauthorized sources that provide the right content.
This allows substitutes to be downloaded from unauthorized servers, as
long as they advertise the same hash and references as one of the
authorized servers.
* guix/scripts/substitute.scm (assert-valid-narinfo): Remove.
(valid-narinfo?): Add #:verbose?. Handle each case of
'signature-case'.
(equivalent-narinfo?): New procedure.
(lookup-narinfos/diverse): Add 'authorized?' parameter and honor it.
[select-hit]: New procedure.
(lookup-narinfo): Add 'authorized?' parameter and pass it.
(process-query): Adjust callers accordingly.
(process-substitution): Remove call to 'assert-valid-narinfo'. Check
whether 'lookup-narinfo' returns true and call 'leave' if not.
* tests/substitute.scm (%main-substitute-directory)
(%alternate-substitute-directory): New variables.
(call-with-narinfo): Make 'narinfo-directory' a parameter. Call
'mkdir-p' to create it. Change unwind handler to check whether
CACHE-DIRECTORY exists before deleting it.
(with-narinfo*): New macro.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key"): Change expected error message to "no
valid substitute".
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, unsigned narinfo comes first")
("substitute, two invalid narinfos"): New tests.
* doc/guix.texi (Substitutes): Explain the new behavior.
2017-08-31 18:15:31 -04:00
|
|
|
|
(let ((substitutable (lookup-narinfos/diverse cache-urls paths valid?)))
|
|
|
|
|
(for-each display-narinfo-data substitutable)
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(newline)))
|
|
|
|
|
(wtf
|
|
|
|
|
(error "unknown `--query' command" wtf))))
|
|
|
|
|
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(define %compression-methods
|
|
|
|
|
;; Known compression methods and a thunk to determine whether they're
|
|
|
|
|
;; supported. See 'decompressed-port' in (guix utils).
|
|
|
|
|
`(("gzip" . ,(const #t))
|
Use "guile-zlib" and "guile-lzlib" instead of (guix config).
* Makefile.am (MODULES): Remove guix/zlib.scm and guix/lzlib.scm,
(SCM_TESTS): remove tests/zlib.scm, tests/lzlib.scm.
* build-aux/build-self.scm (make-config.scm): Remove unused %libz variable.
* configure.ac: Remove LIBZ and LIBLZ variables and check instead for
Guile-zlib and Guile-lzlib.
* doc/guix.texi ("Requirements"): Remove zlib requirement and add Guile-zlib
and Guile-lzlib instead.
* gnu/packages/package-management.scm (guix)[native-inputs]: Add "guile-zlib"
and "guile-lzlib",
[inputs]: remove "zlib" and "lzlib",
[propagated-inputs]: ditto,
[arguments]: add "guile-zlib" and "guile-lzlib" to Guile load path.
* guix/config.scm.in (%libz, %liblz): Remove them.
* guix/lzlib.scm: Remove it.
* guix/man-db.scm: Use (zlib) instead of (guix zlib).
* guix/profiles.scm (manual-database): Do not stub (guix config) in imported
modules list, instead add "guile-zlib" to the extension list.
* guix/scripts/publish.scm: Use (zlib) instead of (guix zlib) and (lzlib)
instead of (guix lzlib),
(string->compression-type, effective-compression): do not check for zlib and
lzlib availability.
* guix/scripts/substitute.scm (%compression-methods): Do not check for lzlib
availability.
* guix/self.scm (specification->package): Add "guile-zlib" and "guile-lzlib"
and remove "zlib" and "lzlib",
(compiled-guix): remove "zlib" and "lzlib" arguments and add guile-zlib and
guile-lzlib to the dependencies, also do not pass "zlib" and "lzlib" to
"make-config.scm" procedure,
(make-config.scm): remove "zlib" and "lzlib" arguments as well as %libz and
%liblz variables.
* guix/utils.scm (lzip-port): Use (lzlib) instead of (guix lzlib) and do not
check for lzlib availability.
* guix/zlib.scm: Remove it.
* m4/guix.m4 (GUIX_LIBZ_LIBDIR, GUIX_LIBLZ_FILE_NAME): Remove them.
* tests/lzlib.scm: Use (zlib) instead of (guix zlib) and (lzlib)
instead of (guix lzlib), and do not check for zlib and lzlib availability.
* tests/publish.scm: Ditto.
* tests/substitute.scm: Do not check for lzlib availability.
* tests/utils.scm: Ditto.
* tests/zlib.scm: Remove it.
2020-07-27 10:36:39 -04:00
|
|
|
|
("lzip" . ,(const #t))
|
2020-12-27 06:34:27 -05:00
|
|
|
|
("zstd" . ,(lambda ()
|
|
|
|
|
(resolve-module '(zstd) #t #f #:ensure #f)))
|
2019-05-31 10:26:08 -04:00
|
|
|
|
("xz" . ,(const #t))
|
|
|
|
|
("bzip2" . ,(const #t))
|
|
|
|
|
("none" . ,(const #t))))
|
|
|
|
|
|
|
|
|
|
(define (supported-compression? compression)
|
|
|
|
|
"Return true if COMPRESSION, a string, denotes a supported compression
|
|
|
|
|
method."
|
|
|
|
|
(match (assoc-ref %compression-methods compression)
|
|
|
|
|
(#f #f)
|
|
|
|
|
(supported? (supported?))))
|
|
|
|
|
|
|
|
|
|
(define (compresses-better? compression1 compression2)
|
|
|
|
|
"Return true if COMPRESSION1 generally compresses better than COMPRESSION2;
|
|
|
|
|
this is a rough approximation."
|
|
|
|
|
(match compression1
|
|
|
|
|
("none" #f)
|
|
|
|
|
("gzip" (string=? compression2 "none"))
|
2020-12-27 06:34:27 -05:00
|
|
|
|
("lzip" #t)
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(_ (or (string=? compression2 "none")
|
|
|
|
|
(string=? compression2 "gzip")))))
|
|
|
|
|
|
2019-12-04 17:07:03 -05:00
|
|
|
|
(define (narinfo-best-uri narinfo)
|
2019-05-31 10:26:08 -04:00
|
|
|
|
"Select the \"best\" URI to download NARINFO's nar, and return three values:
|
|
|
|
|
the URI, its compression method (a string), and the compressed file size."
|
|
|
|
|
(define choices
|
|
|
|
|
(filter (match-lambda
|
|
|
|
|
((uri compression file-size)
|
|
|
|
|
(supported-compression? compression)))
|
|
|
|
|
(zip (narinfo-uris narinfo)
|
|
|
|
|
(narinfo-compressions narinfo)
|
|
|
|
|
(narinfo-file-sizes narinfo))))
|
|
|
|
|
|
|
|
|
|
(define (file-size<? c1 c2)
|
|
|
|
|
(match c1
|
|
|
|
|
((uri1 compression1 (? integer? file-size1))
|
|
|
|
|
(match c2
|
|
|
|
|
((uri2 compression2 (? integer? file-size2))
|
|
|
|
|
(< file-size1 file-size2))
|
|
|
|
|
(_ #t)))
|
|
|
|
|
((uri compression1 #f)
|
|
|
|
|
(match c2
|
|
|
|
|
((uri2 compression2 _)
|
|
|
|
|
(compresses-better? compression1 compression2))))
|
|
|
|
|
(_ #f))) ;we can't tell
|
|
|
|
|
|
|
|
|
|
(match (sort choices file-size<?)
|
|
|
|
|
(((uri compression file-size) _ ...)
|
|
|
|
|
(values uri compression file-size))))
|
|
|
|
|
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(define %max-cached-connections
|
|
|
|
|
;; Maximum number of connections kept in cache by
|
|
|
|
|
;; 'open-connection-for-uri/cached'.
|
|
|
|
|
16)
|
|
|
|
|
|
|
|
|
|
(define open-connection-for-uri/cached
|
|
|
|
|
(let ((cache '()))
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(lambda* (uri #:key fresh? timeout verify-certificate?)
|
2020-12-02 16:49:39 -05:00
|
|
|
|
"Return a connection for URI, possibly reusing a cached connection.
|
2020-12-19 09:41:46 -05:00
|
|
|
|
When FRESH? is true, delete any cached connections for URI and open a new one.
|
|
|
|
|
Return #f if URI's scheme is 'file' or #f.
|
|
|
|
|
|
|
|
|
|
When true, TIMEOUT is the maximum number of milliseconds to wait for
|
|
|
|
|
connection establishment. When VERIFY-CERTIFICATE? is true, verify HTTPS
|
|
|
|
|
server certificates."
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(define host (uri-host uri))
|
|
|
|
|
(define scheme (uri-scheme uri))
|
|
|
|
|
(define key (list host scheme (uri-port uri)))
|
|
|
|
|
|
|
|
|
|
(and (not (memq scheme '(file #f)))
|
|
|
|
|
(match (assoc-ref cache key)
|
|
|
|
|
(#f
|
|
|
|
|
;; Open a new connection to URI and evict old entries from
|
|
|
|
|
;; CACHE, if any.
|
|
|
|
|
(let-values (((socket)
|
|
|
|
|
(guix:open-connection-for-uri
|
2020-12-19 09:41:46 -05:00
|
|
|
|
uri
|
|
|
|
|
#:verify-certificate? verify-certificate?
|
|
|
|
|
#:timeout timeout))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
((new-cache evicted)
|
|
|
|
|
(at-most (- %max-cached-connections 1) cache)))
|
|
|
|
|
(for-each (match-lambda
|
|
|
|
|
((_ . port)
|
|
|
|
|
(false-if-exception (close-port port))))
|
|
|
|
|
evicted)
|
|
|
|
|
(set! cache (alist-cons key socket new-cache))
|
|
|
|
|
socket))
|
|
|
|
|
(socket
|
|
|
|
|
(if (or fresh? (port-closed? socket))
|
|
|
|
|
(begin
|
|
|
|
|
(false-if-exception (close-port socket))
|
|
|
|
|
(set! cache (alist-delete key cache))
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(open-connection-for-uri/cached uri #:timeout timeout
|
|
|
|
|
#:verify-certificate?
|
|
|
|
|
verify-certificate?))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(begin
|
|
|
|
|
;; Drain input left from the previous use.
|
|
|
|
|
(drain-input socket)
|
|
|
|
|
socket))))))))
|
|
|
|
|
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(define* (call-with-cached-connection uri proc
|
|
|
|
|
#:optional
|
|
|
|
|
(open-connection
|
|
|
|
|
open-connection-for-uri/cached))
|
|
|
|
|
(let ((port (open-connection uri)))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(catch #t
|
|
|
|
|
(lambda ()
|
|
|
|
|
(proc port))
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
;; If PORT was cached and the server closed the connection in the
|
|
|
|
|
;; meantime, we get EPIPE. In that case, open a fresh connection and
|
|
|
|
|
;; retry. We might also get 'bad-response or a similar exception from
|
2021-01-04 05:05:58 -05:00
|
|
|
|
;; (web response) later on, once we've sent the request, or a
|
|
|
|
|
;; ERROR/INVALID-SESSION from GnuTLS.
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(if (or (and (eq? key 'system-error)
|
|
|
|
|
(= EPIPE (system-error-errno `(,key ,@args))))
|
2021-01-04 05:05:58 -05:00
|
|
|
|
(and (eq? key 'gnutls-error)
|
|
|
|
|
(eq? (first args) error/invalid-session))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(memq key '(bad-response bad-header bad-header-component)))
|
2020-12-19 09:41:46 -05:00
|
|
|
|
(proc (open-connection uri #:fresh? #t))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(apply throw key args))))))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-cached-connection uri port exp ...)
|
|
|
|
|
"Bind PORT with EXP... to a socket connected to URI."
|
|
|
|
|
(call-with-cached-connection uri (lambda (port) exp ...)))
|
|
|
|
|
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(define* (process-substitution store-item destination
|
2020-12-14 11:59:32 -05:00
|
|
|
|
#:key cache-urls acl
|
|
|
|
|
deduplicate? print-build-trace?)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
"Substitute STORE-ITEM (a store file name) from CACHE-URLS, and write it to
|
daemon: Let 'guix substitute' perform hash checks.
This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon. Consequently, it should reduce latency between
subsequent substitute downloads.
This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.
* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it. Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ. When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'. Parse it and handle
"success" and "hash-mismatch" accordingly. Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
2020-12-13 16:46:03 -05:00
|
|
|
|
DESTINATION as a nar file. Verify the substitute against ACL, and verify its
|
2020-12-14 11:59:32 -05:00
|
|
|
|
hash against what appears in the narinfo. When DEDUPLICATE? is true, and if
|
|
|
|
|
DESTINATION is in the store, deduplicate its files. Print a status line on
|
|
|
|
|
the current output port."
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(define narinfo
|
|
|
|
|
(lookup-narinfo cache-urls store-item
|
2020-12-24 11:01:25 -05:00
|
|
|
|
(if (%allow-unauthenticated-substitutes?)
|
|
|
|
|
(const #t)
|
|
|
|
|
(cut valid-narinfo? <> acl))))
|
2019-05-31 10:26:08 -04:00
|
|
|
|
|
2020-12-14 11:59:32 -05:00
|
|
|
|
(define destination-in-store?
|
|
|
|
|
(string-prefix? (string-append (%store-prefix) "/")
|
|
|
|
|
destination))
|
|
|
|
|
|
|
|
|
|
(define (dump-file/deduplicate* . args)
|
|
|
|
|
;; Make sure deduplication looks at the right store (necessary in test
|
|
|
|
|
;; environments).
|
|
|
|
|
(apply dump-file/deduplicate
|
|
|
|
|
(append args (list #:store (%store-prefix)))))
|
|
|
|
|
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(unless narinfo
|
|
|
|
|
(leave (G_ "no valid substitute for '~a'~%")
|
|
|
|
|
store-item))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(let-values (((uri compression file-size)
|
2019-12-04 17:07:03 -05:00
|
|
|
|
(narinfo-best-uri narinfo)))
|
2017-01-18 17:21:29 -05:00
|
|
|
|
(unless print-build-trace?
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
(G_ "Downloading ~a...~%") (uri->string uri)))
|
|
|
|
|
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(let*-values (((raw download-size)
|
2020-12-02 16:49:39 -05:00
|
|
|
|
;; 'guix publish' without '--cache' doesn't specify a
|
|
|
|
|
;; Content-Length, so DOWNLOAD-SIZE is #f in this case.
|
|
|
|
|
(with-cached-connection uri port
|
|
|
|
|
(fetch uri #:buffered? #f #:timeout? #f
|
|
|
|
|
#:port port
|
|
|
|
|
#:keep-alive? #t)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
((progress)
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(let* ((dl-size (or download-size
|
|
|
|
|
(and (equal? compression "none")
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(narinfo-size narinfo))))
|
2017-01-18 17:21:29 -05:00
|
|
|
|
(reporter (if print-build-trace?
|
|
|
|
|
(progress-reporter/trace
|
|
|
|
|
destination
|
|
|
|
|
(uri->string uri) dl-size
|
|
|
|
|
(current-error-port))
|
|
|
|
|
(progress-reporter/file
|
|
|
|
|
(uri->string uri) dl-size
|
|
|
|
|
(current-error-port)
|
|
|
|
|
#:abbreviation nar-uri-abbreviation))))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
;; Keep RAW open upon completion so we can later reuse
|
|
|
|
|
;; the underlying connection.
|
|
|
|
|
(progress-report-port reporter raw #:close? #f)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
((input pids)
|
2017-10-14 10:45:55 -04:00
|
|
|
|
;; NOTE: This 'progress' port of current process will be
|
|
|
|
|
;; closed here, while the child process doing the
|
|
|
|
|
;; reporting will close it upon exit.
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(decompressed-port (string->symbol compression)
|
daemon: Let 'guix substitute' perform hash checks.
This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon. Consequently, it should reduce latency between
subsequent substitute downloads.
This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.
* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it. Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ. When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'. Parse it and handle
"success" and "hash-mismatch" accordingly. Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
2020-12-13 16:46:03 -05:00
|
|
|
|
progress))
|
|
|
|
|
|
|
|
|
|
;; Compute the actual nar hash as we read it.
|
|
|
|
|
((algorithm expected)
|
|
|
|
|
(narinfo-hash-algorithm+value narinfo))
|
|
|
|
|
((hashed get-hash)
|
|
|
|
|
(open-hash-input-port algorithm input)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
;; Unpack the Nar at INPUT into DESTINATION.
|
2020-12-14 11:59:32 -05:00
|
|
|
|
(restore-file hashed destination
|
|
|
|
|
#:dump-file (if (and destination-in-store?
|
|
|
|
|
deduplicate?)
|
|
|
|
|
dump-file/deduplicate*
|
|
|
|
|
dump-file))
|
daemon: Let 'guix substitute' perform hash checks.
This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon. Consequently, it should reduce latency between
subsequent substitute downloads.
This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.
* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it. Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ. When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'. Parse it and handle
"success" and "hash-mismatch" accordingly. Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
2020-12-13 16:46:03 -05:00
|
|
|
|
(close-port hashed)
|
2017-09-16 03:16:04 -04:00
|
|
|
|
(close-port input)
|
2017-10-14 10:45:55 -04:00
|
|
|
|
|
|
|
|
|
;; Wait for the reporter to finish.
|
|
|
|
|
(every (compose zero? cdr waitpid) pids)
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
2017-09-16 16:10:18 -04:00
|
|
|
|
;; Skip a line after what 'progress-reporter/file' printed, and another
|
|
|
|
|
;; one to visually separate substitutions.
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
(display "\n\n" (current-error-port))
|
|
|
|
|
|
daemon: Let 'guix substitute' perform hash checks.
This way, the hash of the store item can be computed as it is restored,
thereby avoiding an additional file tree traversal ('hashPath' call)
later on in the daemon. Consequently, it should reduce latency between
subsequent substitute downloads.
This is a followup to 5ff521452b9ec2aae9ed8e4bb7bdc250a581f203.
* guix/scripts/substitute.scm (narinfo-hash-algorithm+value): New
procedure.
(process-substitution): Wrap INPUT into a hash input port, 'hashed', and
read from it. Compare the actual and expected hashes, and print a
"hash-mismatch" status line when they differ. When they match, print
not just "success" but also the nar hash and size.
* nix/libstore/build.cc (class SubstitutionGoal)[expectedHashStr]:
Remove.
(SubstitutionGoal::finished): Tokenize 'status'. Parse it and handle
"success" and "hash-mismatch" accordingly. Call 'hashPath' only when
the returned hash is not SHA256.
(SubstitutionGoal::handleChildOutput): Remove 'expectedHashStr'
handling.
* tests/substitute.scm ("substitute, invalid hash"): Rename to...
("substitute, invalid narinfo hash"): ... this.
("substitute, invalid hash"): New test.
2020-12-13 16:46:03 -05:00
|
|
|
|
;; Check whether we got the data announced in NARINFO.
|
|
|
|
|
(let ((actual (get-hash)))
|
|
|
|
|
(if (bytevector=? actual expected)
|
|
|
|
|
;; Tell the daemon that we're done.
|
|
|
|
|
(format (current-output-port) "success ~a ~a~%"
|
|
|
|
|
(narinfo-hash narinfo) (narinfo-size narinfo))
|
|
|
|
|
;; The actual data has a different hash than that in NARINFO.
|
|
|
|
|
(format (current-output-port) "hash-mismatch ~a ~a ~a~%"
|
|
|
|
|
(hash-algorithm-name algorithm)
|
|
|
|
|
(bytevector->nix-base32-string expected)
|
|
|
|
|
(bytevector->nix-base32-string actual)))))))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Entry point.
|
|
|
|
|
;;;
|
|
|
|
|
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(define (check-acl-initialized)
|
|
|
|
|
"Warn if the ACL is uninitialized."
|
|
|
|
|
(define (singleton? acl)
|
|
|
|
|
;; True if ACL contains just the user's public key.
|
|
|
|
|
(and (file-exists? %public-key-file)
|
|
|
|
|
(let ((key (call-with-input-file %public-key-file
|
|
|
|
|
(compose string->canonical-sexp
|
2016-10-19 08:28:56 -04:00
|
|
|
|
read-string))))
|
2014-06-19 17:35:21 -04:00
|
|
|
|
(match acl
|
|
|
|
|
((thing)
|
|
|
|
|
(equal? (canonical-sexp->string thing)
|
|
|
|
|
(canonical-sexp->string key)))
|
|
|
|
|
(_
|
|
|
|
|
#f)))))
|
|
|
|
|
|
|
|
|
|
(let ((acl (acl->public-keys (current-acl))))
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
(when (or (null? acl) (singleton? acl))
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(warning (G_ "ACL for archive imports seems to be uninitialized, \
|
substitute-binary: Defer narinfo authentication and authorization checks.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Catch 'gcry-error' around 'string->canonical-sexp' call, and re-raise
as a SRFI-35 &message and &nar-signature-error.
(narinfo-maker): Handle when SIGNATURE is #f or an invalid canonical
sexp.
(&nar-signature-error, &nar-invalid-hash-error): New variables.
(assert-valid-signature): Use them. Expect 'signature' to be a
canonical sexp.
(read-narinfo): Remove authentication and authorization checks.
(%signature-line-rx): New variable.
(assert-valid-narinfo, valid-narinfo?): New procedures.
(guix-substitute-binary): Wrap body in 'with-error-handling'.
[valid?]: New procedure.
<--query>: Show only store items of narinfos that match
'valid-narinfo?'.
<--substitute>: Call 'assert-valid-narinfo'.
* tests/substitute-binary.scm (test-error*): Use 'test-equal'.
(%keypair): Remove.
(%public-key, %private-key): Load from signing-key.{pub,sec}.
(signature-body): Add #:public-key parameter.
(call-with-narinfo): New procedure.
(with-narinfo): New macro.
("corrupt signature data", "unauthorized public key", "invalid
signature"): Make the first argument to 'assert-valid-signature' a
canonical sexp.
("invalid hash", "valid read-narinfo", "valid write-narinfo"):
Remove.
("query narinfo with invalid hash", "query narinfo signed with
authorized key", "query narinfo signed with unauthorized key",
"substitute, invalid hash", "substitute, unauthorized key"): New
tests.
2014-03-30 16:29:35 -04:00
|
|
|
|
substitutes may be unavailable\n")))))
|
|
|
|
|
|
2014-10-09 07:25:41 -04:00
|
|
|
|
(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))
|
|
|
|
|
|
2017-08-31 17:27:26 -04:00
|
|
|
|
(define %default-substitute-urls
|
2016-03-16 13:13:02 -04:00
|
|
|
|
(match (and=> (or (find-daemon-option "untrusted-substitute-urls") ;client
|
|
|
|
|
(find-daemon-option "substitute-urls")) ;admin
|
2014-10-09 07:38:16 -04:00
|
|
|
|
string-tokenize)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
((urls ...)
|
|
|
|
|
urls)
|
2014-10-09 07:38:16 -04:00
|
|
|
|
(#f
|
|
|
|
|
;; This can only happen when this script is not invoked by the
|
|
|
|
|
;; daemon.
|
2019-05-01 05:05:47 -04:00
|
|
|
|
'("http://ci.guix.gnu.org"))))
|
2014-10-09 07:25:41 -04:00
|
|
|
|
|
2020-11-24 08:05:21 -05:00
|
|
|
|
;; In order to prevent using large number of discovered local substitute
|
|
|
|
|
;; servers, limit the local substitute urls list size.
|
|
|
|
|
(define %max-substitute-urls 50)
|
|
|
|
|
|
|
|
|
|
(define* (randomize-substitute-urls urls
|
|
|
|
|
#:key
|
|
|
|
|
(max %max-substitute-urls))
|
|
|
|
|
"Return a list containing MAX urls from URLS, picked randomly. If URLS list
|
|
|
|
|
is shorter than MAX elements, then it is directly returned."
|
|
|
|
|
(define (random-item list)
|
|
|
|
|
(list-ref list (random (length list))))
|
|
|
|
|
|
|
|
|
|
(if (<= (length urls) max)
|
|
|
|
|
urls
|
|
|
|
|
(let loop ((res '())
|
|
|
|
|
(urls urls))
|
|
|
|
|
(if (eq? (length res) max)
|
|
|
|
|
res
|
|
|
|
|
(let ((url (random-item urls)))
|
|
|
|
|
(loop (cons url res) (delete url urls)))))))
|
|
|
|
|
|
|
|
|
|
(define %local-substitute-urls
|
|
|
|
|
;; If the following option is passed to the daemon, use the substitutes list
|
|
|
|
|
;; provided by "guix discover" process.
|
2020-12-04 08:25:57 -05:00
|
|
|
|
(let* ((option (find-daemon-option "discover"))
|
|
|
|
|
(discover? (and option (string=? option "yes"))))
|
|
|
|
|
(if discover?
|
|
|
|
|
(randomize-substitute-urls (read-substitute-urls))
|
|
|
|
|
'())))
|
2020-11-24 08:05:21 -05:00
|
|
|
|
|
2017-08-31 17:27:26 -04:00
|
|
|
|
(define substitute-urls
|
|
|
|
|
;; List of substitute URLs.
|
2020-11-24 08:05:21 -05:00
|
|
|
|
(make-parameter (append %local-substitute-urls
|
|
|
|
|
%default-substitute-urls)))
|
2017-08-31 17:27:26 -04:00
|
|
|
|
|
2016-04-14 18:10:22 -04:00
|
|
|
|
(define (client-terminal-columns)
|
|
|
|
|
"Return the number of columns in the client's terminal, if it is known, or a
|
|
|
|
|
default value."
|
|
|
|
|
(or (and=> (or (find-daemon-option "untrusted-terminal-columns")
|
|
|
|
|
(find-daemon-option "terminal-columns"))
|
2016-04-20 17:21:49 -04:00
|
|
|
|
(lambda (str)
|
|
|
|
|
(let ((number (string->number str)))
|
|
|
|
|
(and number (max 20 (- number 1))))))
|
2016-04-14 18:10:22 -04:00
|
|
|
|
80))
|
|
|
|
|
|
2017-05-02 06:28:23 -04:00
|
|
|
|
(define (validate-uri uri)
|
|
|
|
|
(unless (string->uri uri)
|
ui: Rename '_' to 'G_'.
This avoids collisions with '_' when the latter is used as a 'match'
pattern for instance. See
<https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>.
* guix/ui.scm: Rename '_' to 'G_'.
* po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly.
* build-aux/compile-all.scm (warnings): Remove 'format'.
* gnu/packages.scm,
gnu/services.scm,
gnu/services/shepherd.scm,
gnu/system.scm,
gnu/system/shadow.scm,
guix/gnupg.scm,
guix/http-client.scm,
guix/import/cpan.scm,
guix/import/elpa.scm,
guix/import/pypi.scm,
guix/nar.scm,
guix/scripts.scm,
guix/scripts/archive.scm,
guix/scripts/authenticate.scm,
guix/scripts/build.scm,
guix/scripts/challenge.scm,
guix/scripts/container.scm,
guix/scripts/container/exec.scm,
guix/scripts/copy.scm,
guix/scripts/download.scm,
guix/scripts/edit.scm,
guix/scripts/environment.scm,
guix/scripts/gc.scm,
guix/scripts/graph.scm,
guix/scripts/hash.scm,
guix/scripts/import.scm,
guix/scripts/import/cpan.scm,
guix/scripts/import/cran.scm,
guix/scripts/import/crate.scm,
guix/scripts/import/elpa.scm,
guix/scripts/import/gem.scm,
guix/scripts/import/gnu.scm,
guix/scripts/import/hackage.scm,
guix/scripts/import/nix.scm,
guix/scripts/import/pypi.scm,
guix/scripts/import/stackage.scm,
guix/scripts/lint.scm,
guix/scripts/offload.scm,
guix/scripts/pack.scm,
guix/scripts/package.scm,
guix/scripts/perform-download.scm,
guix/scripts/publish.scm,
guix/scripts/pull.scm,
guix/scripts/refresh.scm,
guix/scripts/size.scm,
guix/scripts/substitute.scm,
guix/scripts/system.scm,
guix/ssh.scm,
guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was
obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
2017-05-03 09:57:02 -04:00
|
|
|
|
(leave (G_ "~a: invalid URI~%") uri)))
|
2017-05-02 06:28:23 -04:00
|
|
|
|
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
(define %error-to-file-descriptor-4?
|
|
|
|
|
;; Whether to direct 'current-error-port' to file descriptor 4 like
|
|
|
|
|
;; 'guix-daemon' expects.
|
|
|
|
|
(make-parameter #t))
|
|
|
|
|
|
2020-09-01 16:13:11 -04:00
|
|
|
|
(define-command (guix-substitute . args)
|
|
|
|
|
(category internal)
|
|
|
|
|
(synopsis "implement the build daemon's substituter protocol")
|
|
|
|
|
|
2017-01-18 17:21:29 -05:00
|
|
|
|
(define print-build-trace?
|
|
|
|
|
(match (or (find-daemon-option "untrusted-print-extended-build-trace")
|
|
|
|
|
(find-daemon-option "print-extended-build-trace"))
|
|
|
|
|
(#f #f)
|
|
|
|
|
((= string->number number) (> number 0))
|
|
|
|
|
(_ #f)))
|
|
|
|
|
|
2020-12-14 11:59:32 -05:00
|
|
|
|
(define deduplicate?
|
|
|
|
|
(find-daemon-option "deduplicate"))
|
|
|
|
|
|
2020-12-01 09:01:40 -05:00
|
|
|
|
;; The daemon's agent code opens file descriptor 4 for us and this is where
|
|
|
|
|
;; stderr should go.
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
(parameterize ((current-error-port (if (%error-to-file-descriptor-4?)
|
|
|
|
|
(fdopen 4 "wl")
|
|
|
|
|
(current-error-port))))
|
2020-12-01 09:01:40 -05:00
|
|
|
|
;; Redirect diagnostics to file descriptor 4 as well.
|
|
|
|
|
(guix-warning-port (current-error-port))
|
|
|
|
|
|
|
|
|
|
(mkdir-p %narinfo-cache-directory)
|
|
|
|
|
(maybe-remove-expired-cache-entries %narinfo-cache-directory
|
|
|
|
|
cached-narinfo-files
|
|
|
|
|
#:entry-expiration
|
|
|
|
|
cached-narinfo-expiration-time
|
|
|
|
|
#:cleanup-period
|
|
|
|
|
%narinfo-expired-cache-entry-removal-delay)
|
|
|
|
|
(check-acl-initialized)
|
|
|
|
|
|
|
|
|
|
;; Sanity-check SUBSTITUTE-URLS so we can provide a meaningful error
|
|
|
|
|
;; message.
|
|
|
|
|
(for-each validate-uri (substitute-urls))
|
|
|
|
|
|
|
|
|
|
;; Attempt to install the client's locale so that messages are suitably
|
|
|
|
|
;; translated. LC_CTYPE must be a UTF-8 locale; it's the case by default
|
|
|
|
|
;; so don't change it.
|
|
|
|
|
(match (or (find-daemon-option "untrusted-locale")
|
|
|
|
|
(find-daemon-option "locale"))
|
|
|
|
|
(#f #f)
|
|
|
|
|
(locale (false-if-exception (setlocale LC_MESSAGES locale))))
|
|
|
|
|
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(set-thread-name "guix substitute"))
|
|
|
|
|
(const #t)) ;GNU/Hurd lacks 'prctl'
|
|
|
|
|
|
|
|
|
|
(with-networking
|
|
|
|
|
(with-error-handling ; for signature errors
|
|
|
|
|
(match args
|
|
|
|
|
(("--query")
|
|
|
|
|
(let ((acl (current-acl)))
|
|
|
|
|
(let loop ((command (read-line)))
|
|
|
|
|
(or (eof-object? command)
|
|
|
|
|
(begin
|
|
|
|
|
(process-query command
|
|
|
|
|
#:cache-urls (substitute-urls)
|
|
|
|
|
#:acl acl)
|
|
|
|
|
(loop (read-line)))))))
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
(("--substitute")
|
2020-12-01 09:01:40 -05:00
|
|
|
|
;; Download STORE-PATH and store it as a Nar in file DESTINATION.
|
|
|
|
|
;; Specify the number of columns of the terminal so the progress
|
|
|
|
|
;; report displays nicely.
|
|
|
|
|
(parameterize ((current-terminal-columns (client-terminal-columns)))
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
(let loop ()
|
|
|
|
|
(match (read-line)
|
|
|
|
|
((? eof-object?)
|
|
|
|
|
#t)
|
|
|
|
|
((= string-tokenize ("substitute" store-path destination))
|
|
|
|
|
(process-substitution store-path destination
|
|
|
|
|
#:cache-urls (substitute-urls)
|
|
|
|
|
#:acl (current-acl)
|
2020-12-14 11:59:32 -05:00
|
|
|
|
#:deduplicate? deduplicate?
|
daemon: Run 'guix substitute --substitute' as an agent.
This avoids spawning one substitute process per substitution.
* nix/libstore/build.cc (class Worker)[substituter]: New field.
[outPipe, logPipe, pid]: Remove.
(class SubstitutionGoal)[expectedHashStr, status, substituter]: New fields.
(SubstitutionGoal::timedOut): Adjust to check 'substituter'.
(SubstitutionGoal::tryToRun): Remove references to 'outPipe' and
'logPipe'. Run "guix substitute --substitute" as an 'Agent'. Send the
request with 'writeLine'.
(SubstitutionGoal::finished): Likewise.
(SubstitutionGoal::handleChildOutput): Change to fill in
'expectedHashStr' and 'status'.
(SubstitutionGoal::handleEOF): Call 'wakeUp' unconditionally.
(SubstitutionGoal::~SubstitutionGoal): Adjust to check 'substituter'.
* guix/scripts/substitute.scm (process-substitution): Write "success\n"
to stdout upon success.
(%error-to-file-descriptor-4?): New variable.
(guix-substitute): Set 'current-error-port' to file descriptor 4
unless (%error-to-file-descriptor-4?) is false.
Remove "--substitute" arguments. Loop reading line from stdin.
* tests/substitute.scm <top level>: Call '%error-to-file-descriptor-4?'.
(request-substitution): New procedure.
("substitute, no signature")
("substitute, invalid hash")
("substitute, unauthorized key")
("substitute, authorized key")
("substitute, unauthorized narinfo comes first")
("substitute, unsigned narinfo comes first")
("substitute, first narinfo is unsigned and has wrong hash")
("substitute, first narinfo is unsigned and has wrong refs")
("substitute, two invalid narinfos")
("substitute, narinfo with several URLs"): Adjust to new "guix
substitute --substitute" calling convention.
2020-12-02 10:27:34 -05:00
|
|
|
|
#:print-build-trace?
|
|
|
|
|
print-build-trace?)
|
|
|
|
|
(loop))))))
|
2020-12-01 09:01:40 -05:00
|
|
|
|
((or ("-V") ("--version"))
|
|
|
|
|
(show-version-and-exit "guix substitute"))
|
|
|
|
|
(("--help")
|
|
|
|
|
(show-help))
|
|
|
|
|
(opts
|
|
|
|
|
(leave (G_ "~a: unrecognized options~%") opts)))))))
|
2013-04-02 04:44:20 -04:00
|
|
|
|
|
2013-06-29 16:10:06 -04:00
|
|
|
|
;;; Local Variables:
|
2013-06-17 18:11:40 -04:00
|
|
|
|
;;; eval: (put 'with-timeout 'scheme-indent-function 1)
|
2020-12-02 16:49:39 -05:00
|
|
|
|
;;; eval: (put 'with-cached-connection 'scheme-indent-function 2)
|
2020-12-19 09:41:46 -05:00
|
|
|
|
;;; eval: (put 'call-with-cached-connection 'scheme-indent-function 1)
|
2013-06-04 03:43:38 -04:00
|
|
|
|
;;; End:
|
|
|
|
|
|
2015-03-25 05:34:27 -04:00
|
|
|
|
;;; substitute.scm ends here
|