2013-04-02 04:44:20 -04:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2023-01-09 04:27:54 -05:00
|
|
|
|
;;; Copyright © 2013-2023 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)
|
guix: Move narinfo code from substitute script to module.
This separation between the code for dealing with narinfos from the code doing
that for a purpose should make things clearer, and better support components
other that the substitute script in using this code.
This is just moving the code around, no code should have been significantly
changed.
* guix/scripts/substitute.scm (<narinfo>): Move record type to (guix narinfo).
(fields->alist, narinfo-hash-algorithm+value, narinfo-hash->sha256,
narinfo-signature->canonical-sexp, narinfo-maker, read-narinfo,
narinfo-sha256, valid-narinfo?, write-narinfo, narinfo->string,
string->narinfo, equivalent-narinfo?, supported-compression?,
compresses-better?, narinfo-best-uri): Move procedures to (guix narinfo).
(%compression-methods): Move variable to (guix narinfo).
* guix/narinfo.scm: New file.
* Makefile.am (MODULES): Add it.
* po/guix/POTFILES.in: Add 'guix/narinfo.scm'.
2020-12-24 10:50:54 -05:00
|
|
|
|
#:use-module (guix narinfo)
|
2020-01-03 09:47:12 -05:00
|
|
|
|
#:use-module (guix store)
|
guix: Split (guix substitutes) from (guix scripts substitute).
This means there's a module for working with substitutes, rather than all the
code sitting in the script. The need for this can be seen with the weather and
challenge scripts, that now don't have to use code from the substitute script,
but can instead use the substitute module.
The separation here between the actual functionality of the substitute script
and the underlying functionality used both there and elsewhere should make
maintenance easier moving forward.
This commit just moves code, none of the code should have been changed
significantly.
* guix/scripts/substitute.scm (%narinfo-cache-directory, %narinfo-ttl,
%narinfo-negative-ttl, %narinfo-transient-error-ttl, %unreachable-hosts): Move
variables to guix/substitutes.scm.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
read-to-eof, call-with-connection-error-handling, fetch-narinfos,
lookup-narinfos, lookup-narinfos/diverse): Move procedures to
guix/substitutes.scm.
* guix/substitutes.scm: New file.
* Makefile.am: Add it.
* guix/narinfo.scm: Remove redundant module.
* guix/scripts/challenge.scm: Change (guix scripts substitute) to (guix
substitutes).
* guix/scripts/weather.scm: Change (guix scripts substitute) to (guix
substitutes).
2021-02-22 17:42:03 -05:00
|
|
|
|
#:use-module (guix substitutes)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (guix utils)
|
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)
|
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)
|
2023-06-08 16:43:05 -04:00
|
|
|
|
#:autoload (guix build utils) (mkdir-p delete-file-recursively)
|
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: Split (guix substitutes) from (guix scripts substitute).
This means there's a module for working with substitutes, rather than all the
code sitting in the script. The need for this can be seen with the weather and
challenge scripts, that now don't have to use code from the substitute script,
but can instead use the substitute module.
The separation here between the actual functionality of the substitute script
and the underlying functionality used both there and elsewhere should make
maintenance easier moving forward.
This commit just moves code, none of the code should have been changed
significantly.
* guix/scripts/substitute.scm (%narinfo-cache-directory, %narinfo-ttl,
%narinfo-negative-ttl, %narinfo-transient-error-ttl, %unreachable-hosts): Move
variables to guix/substitutes.scm.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
read-to-eof, call-with-connection-error-handling, fetch-narinfos,
lookup-narinfos, lookup-narinfos/diverse): Move procedures to
guix/substitutes.scm.
* guix/substitutes.scm: New file.
* Makefile.am: Add it.
* guix/narinfo.scm: Remove redundant module.
* guix/scripts/challenge.scm: Change (guix scripts substitute) to (guix
substitutes).
* guix/scripts/weather.scm: Change (guix scripts substitute) to (guix
substitutes).
2021-02-22 17:42:03 -05:00
|
|
|
|
. guix:open-connection-for-uri)))
|
2021-04-24 11:59:14 -04:00
|
|
|
|
#:autoload (gnutls) (error/invalid-session error/again error/interrupted)
|
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 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)
|
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-26)
|
2014-03-01 09:38:11 -05:00
|
|
|
|
#:use-module (srfi srfi-34)
|
2022-06-26 17:07:39 -04:00
|
|
|
|
#:use-module (srfi srfi-71)
|
2013-04-02 04:44:20 -04:00
|
|
|
|
#:use-module (web uri)
|
2013-07-14 10:35:37 -04:00
|
|
|
|
#:use-module (guix http-client)
|
guix: Split (guix substitutes) from (guix scripts substitute).
This means there's a module for working with substitutes, rather than all the
code sitting in the script. The need for this can be seen with the weather and
challenge scripts, that now don't have to use code from the substitute script,
but can instead use the substitute module.
The separation here between the actual functionality of the substitute script
and the underlying functionality used both there and elsewhere should make
maintenance easier moving forward.
This commit just moves code, none of the code should have been changed
significantly.
* guix/scripts/substitute.scm (%narinfo-cache-directory, %narinfo-ttl,
%narinfo-negative-ttl, %narinfo-transient-error-ttl, %unreachable-hosts): Move
variables to guix/substitutes.scm.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
read-to-eof, call-with-connection-error-handling, fetch-narinfos,
lookup-narinfos, lookup-narinfos/diverse): Move procedures to
guix/substitutes.scm.
* guix/substitutes.scm: New file.
* Makefile.am: Add it.
* guix/narinfo.scm: Remove redundant module.
* guix/scripts/challenge.scm: Change (guix scripts substitute) to (guix
substitutes).
* guix/scripts/weather.scm: Change (guix scripts substitute) to (guix
substitutes).
2021-02-22 17:42:03 -05:00
|
|
|
|
#:export (%allow-unauthenticated-substitutes?
|
2021-04-06 06:10:29 -04:00
|
|
|
|
%reply-file-descriptor
|
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:
|
|
|
|
|
|
guix: Split (guix substitutes) from (guix scripts substitute).
This means there's a module for working with substitutes, rather than all the
code sitting in the script. The need for this can be seen with the weather and
challenge scripts, that now don't have to use code from the substitute script,
but can instead use the substitute module.
The separation here between the actual functionality of the substitute script
and the underlying functionality used both there and elsewhere should make
maintenance easier moving forward.
This commit just moves code, none of the code should have been changed
significantly.
* guix/scripts/substitute.scm (%narinfo-cache-directory, %narinfo-ttl,
%narinfo-negative-ttl, %narinfo-transient-error-ttl, %unreachable-hosts): Move
variables to guix/substitutes.scm.
(narinfo-cache-file, cached-narinfo, cache-narinfo!, narinfo-request,
read-to-eof, call-with-connection-error-handling, fetch-narinfos,
lookup-narinfos, lookup-narinfos/diverse): Move procedures to
guix/substitutes.scm.
* guix/substitutes.scm: New file.
* Makefile.am: Add it.
* guix/narinfo.scm: Remove redundant module.
* guix/scripts/challenge.scm: Change (guix scripts substitute) to (guix
substitutes).
* guix/scripts/weather.scm: Change (guix scripts substitute) to (guix
substitutes).
2021-02-22 17:42:03 -05:00
|
|
|
|
(define %narinfo-expired-cache-entry-removal-delay
|
|
|
|
|
;; How often we want to remove files corresponding to expired cache entries.
|
|
|
|
|
(* 7 24 3600))
|
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-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)))))
|
|
|
|
|
|
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)))))))
|
|
|
|
|
|
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 (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)))))
|
|
|
|
|
|
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."
|
2021-06-04 02:49:39 -04:00
|
|
|
|
(match (lookup-narinfos/diverse
|
|
|
|
|
caches (list path) authorized?
|
|
|
|
|
#:open-connection open-connection-for-uri/cached)
|
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."
|
2023-05-31 17:02:16 -04:00
|
|
|
|
(define max-ttl
|
|
|
|
|
;; Upper bound on the TTL used to avoid keeping around cached narinfos for
|
|
|
|
|
;; too long, which makes the cache bigger and more expensive to traverse.
|
|
|
|
|
(* 2 30 24 60 60)) ;2 months
|
|
|
|
|
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(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))
|
2023-05-31 17:02:16 -04:00
|
|
|
|
(+ date (min ttl max-ttl)))
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(('narinfo ('version 2) ('cache-uri uri)
|
|
|
|
|
('date date) ('ttl ttl) ('value value))
|
2023-05-31 17:02:16 -04:00
|
|
|
|
(+ date (min ttl max-ttl)))
|
2017-04-18 16:07:49 -04:00
|
|
|
|
(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 ...)
|
2021-02-23 11:01:24 -05:00
|
|
|
|
;; Use a pre-unwind handler so that re-throwing preserves useful
|
|
|
|
|
;; backtraces. 'with-throw-handler' works for Guile 2.2 and 3.0.
|
|
|
|
|
(with-throw-handler #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)
|
2021-12-26 11:19:50 -05:00
|
|
|
|
(display (G_ "Usage: guix substitute OPTION [ARGUMENT]...
|
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.
|
|
|
|
|
;;;
|
|
|
|
|
|
2021-03-14 10:05:30 -04:00
|
|
|
|
(define %prefer-fast-decompression?
|
|
|
|
|
;; Whether to prefer fast decompression over good compression ratios. This
|
|
|
|
|
;; serves in particular to choose between lzip (high compression ratio but
|
|
|
|
|
;; low decompression throughput) and zstd (lower compression ratio but high
|
|
|
|
|
;; decompression throughput).
|
|
|
|
|
#f)
|
|
|
|
|
|
|
|
|
|
(define (call-with-cpu-usage-monitoring proc)
|
|
|
|
|
(let ((before (times)))
|
|
|
|
|
(proc)
|
|
|
|
|
(let ((after (times)))
|
|
|
|
|
(if (= (tms:clock after) (tms:clock before))
|
|
|
|
|
0
|
|
|
|
|
(/ (- (tms:utime after) (tms:utime before))
|
|
|
|
|
(- (tms:clock after) (tms:clock before))
|
|
|
|
|
1.)))))
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-cpu-usage-monitoring exp ...)
|
|
|
|
|
"Evaluate EXP... Return its CPU usage as a fraction between 0 and 1."
|
|
|
|
|
(call-with-cpu-usage-monitoring (lambda () exp ...)))
|
|
|
|
|
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(define (display-narinfo-data port narinfo)
|
|
|
|
|
"Write to PORT the contents of NARINFO in the format expected by the
|
|
|
|
|
daemon."
|
|
|
|
|
(format port "~a\n~a\n~a\n"
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(narinfo-path narinfo)
|
|
|
|
|
(or (and=> (narinfo-deriver narinfo)
|
|
|
|
|
(cute string-append (%store-prefix) "/" <>))
|
|
|
|
|
"")
|
|
|
|
|
(length (narinfo-references narinfo)))
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(for-each (cute format port "~a/~a~%" (%store-prefix) <>)
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(narinfo-references narinfo))
|
2019-05-31 10:26:08 -04:00
|
|
|
|
|
2022-06-26 17:07:39 -04:00
|
|
|
|
(let ((uri compression file-size
|
|
|
|
|
(narinfo-best-uri narinfo
|
|
|
|
|
#:fast-decompression?
|
|
|
|
|
%prefer-fast-decompression?)))
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(format port "~a\n~a\n"
|
2019-05-31 10:26:08 -04:00
|
|
|
|
(or file-size 0)
|
|
|
|
|
(or (narinfo-size narinfo) 0))))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(define* (process-query port command
|
2015-10-28 05:11:43 -04:00
|
|
|
|
#:key cache-urls acl)
|
2021-04-06 06:10:29 -04:00
|
|
|
|
"Reply on PORT to COMMAND, a query as written by the daemon to this process's
|
2015-07-13 11:51:02 -04:00
|
|
|
|
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
|
|
|
|
|
2020-12-09 13:56:05 -05:00
|
|
|
|
(define* (make-progress-reporter total #:key url)
|
|
|
|
|
(define done 0)
|
|
|
|
|
|
|
|
|
|
(define (report-progress)
|
|
|
|
|
(erase-current-line (current-error-port)) ;erase current line
|
|
|
|
|
(force-output (current-error-port))
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
(G_ "updating substitutes from '~a'... ~5,1f%")
|
|
|
|
|
url (* 100. (/ done total)))
|
|
|
|
|
(set! done (+ 1 done)))
|
|
|
|
|
|
|
|
|
|
(progress-reporter
|
|
|
|
|
(start report-progress)
|
|
|
|
|
(report report-progress)
|
|
|
|
|
(stop (lambda ()
|
|
|
|
|
(newline (current-error-port))))))
|
|
|
|
|
|
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.
|
2021-01-07 16:00:23 -05:00
|
|
|
|
(let ((substitutable (lookup-narinfos/diverse
|
|
|
|
|
cache-urls paths valid?
|
2020-12-09 13:56:05 -05:00
|
|
|
|
#:open-connection open-connection-for-uri/cached
|
|
|
|
|
#:make-progress-reporter make-progress-reporter)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(for-each (lambda (narinfo)
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(format port "~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)
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(newline port)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(("info" paths ..1)
|
2015-10-28 05:11:43 -04:00
|
|
|
|
;; Reply info about PATHS if it's in CACHE-URLS.
|
2021-01-07 16:00:23 -05:00
|
|
|
|
(let ((substitutable (lookup-narinfos/diverse
|
|
|
|
|
cache-urls paths valid?
|
2020-12-09 13:56:05 -05:00
|
|
|
|
#:open-connection open-connection-for-uri/cached
|
|
|
|
|
#:make-progress-reporter make-progress-reporter)))
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(for-each (cut display-narinfo-data port <>) substitutable)
|
|
|
|
|
(newline port)))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
(wtf
|
|
|
|
|
(error "unknown `--query' command" wtf))))
|
|
|
|
|
|
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 '()))
|
2021-02-13 06:06:37 -05:00
|
|
|
|
(lambda* (uri #:key fresh? (timeout %fetch-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.
|
|
|
|
|
|
2022-12-05 08:50:34 -05:00
|
|
|
|
When true, TIMEOUT is the maximum number of seconds to wait for
|
2020-12-19 09:41:46 -05:00
|
|
|
|
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.
|
2022-06-26 17:07:39 -04:00
|
|
|
|
(let ((socket
|
|
|
|
|
(guix:open-connection-for-uri
|
|
|
|
|
uri
|
|
|
|
|
#:verify-certificate? verify-certificate?
|
|
|
|
|
#:timeout timeout))
|
|
|
|
|
(new-cache evicted
|
|
|
|
|
(at-most (- %max-cached-connections 1) cache)))
|
2020-12-02 16:49:39 -05:00
|
|
|
|
(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))))))))
|
|
|
|
|
|
2023-05-22 06:15:14 -04:00
|
|
|
|
(define kind-and-args-exception?
|
|
|
|
|
(exception-predicate &exception-with-kind-and-args))
|
|
|
|
|
|
2021-03-15 11:05:08 -04:00
|
|
|
|
(define (call-with-cached-connection uri proc)
|
|
|
|
|
(let ((port (open-connection-for-uri/cached uri
|
|
|
|
|
#:verify-certificate? #f)))
|
2023-05-22 06:15:14 -04:00
|
|
|
|
(guard (c ((kind-and-args-exception? c)
|
|
|
|
|
(let ((key (exception-kind c))
|
|
|
|
|
(args (exception-args c)))
|
|
|
|
|
;; 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 (web response) later on, once we've sent the
|
|
|
|
|
;; request, or a ERROR/INVALID-SESSION from GnuTLS.
|
|
|
|
|
(if (or (and (eq? key 'system-error)
|
|
|
|
|
(= EPIPE (system-error-errno `(,key ,@args))))
|
|
|
|
|
(and (eq? key 'gnutls-error)
|
|
|
|
|
(memq (first args)
|
|
|
|
|
(list error/invalid-session
|
|
|
|
|
|
|
|
|
|
;; XXX: These two are not properly handled in
|
|
|
|
|
;; GnuTLS < 3.7.3, in
|
|
|
|
|
;; 'write_to_session_record_port'; see
|
|
|
|
|
;; <https://bugs.gnu.org/47867>.
|
|
|
|
|
error/again error/interrupted)))
|
|
|
|
|
(memq key '(bad-response bad-header bad-header-component)))
|
|
|
|
|
(proc (open-connection-for-uri/cached uri
|
|
|
|
|
#:verify-certificate? #f
|
|
|
|
|
#:fresh? #t))
|
|
|
|
|
(raise c))))
|
|
|
|
|
(#t
|
|
|
|
|
;; An exception that's not handled here, such as
|
|
|
|
|
;; '&http-get-error'. Re-raise it.
|
|
|
|
|
(raise c)))
|
|
|
|
|
(proc port))))
|
2021-03-15 11:05:08 -04:00
|
|
|
|
|
|
|
|
|
(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 ...)))
|
|
|
|
|
|
2023-06-08 16:43:05 -04:00
|
|
|
|
(define-syntax-rule (catch-system-error exp)
|
|
|
|
|
(catch 'system-error
|
|
|
|
|
(lambda () exp)
|
|
|
|
|
(const #f)))
|
|
|
|
|
|
2022-09-22 06:08:16 -04:00
|
|
|
|
(define* (download-nar narinfo destination
|
|
|
|
|
#:key status-port
|
|
|
|
|
deduplicate? print-build-trace?)
|
|
|
|
|
"Download the nar prescribed in NARINFO, which is assumed to be authentic
|
|
|
|
|
and authorized, and write it to DESTINATION. When DEDUPLICATE? is true, and
|
|
|
|
|
if DESTINATION is in the store, deduplicate its files. Print a status line to
|
|
|
|
|
STATUS-PORT."
|
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)))))
|
|
|
|
|
|
2021-01-07 15:41:50 -05:00
|
|
|
|
(define (fetch uri)
|
|
|
|
|
(case (uri-scheme uri)
|
|
|
|
|
((file)
|
|
|
|
|
(let ((port (open-file (uri-path uri) "r0b")))
|
|
|
|
|
(values port (stat:size (stat port)))))
|
|
|
|
|
((http https)
|
substitute: Retry downloading when a nar is unavailable.
Fixes <https://issues.guix.gnu.org/57978>
Reported by Attila Lendvai <attila@lendvai.name>.
Previously, if a narinfo was available but its corresponding nar was
missing (for instance because the narinfo was cached and the server
became unreachable in the meantime), 'guix substitute --substitute'
would try to download the nar from its preferred location and abort when
that fails. This change forces one retry with each of the URLs.
* guix/scripts/substitute.scm (download-nar): Do not catch
'http-get-error?' exceptions.
(system-error?, network-error?, process-substitution/fallback): New
procedures.
(process-substitution): Call 'process-substitution/fallback' upon
'network-error?'.
* tests/substitute.scm ("substitute, first URL has narinfo but lacks nar, second URL unauthorized")
("substitute, first URL has narinfo but nar is 404, both URLs authorized")
("substitute, first URL has narinfo but nar is 404, one URL authorized")
("substitute, narinfo is available but nar is missing"): New tests.
2022-09-23 02:00:13 -04: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
|
|
|
|
|
(with-timeout %fetch-timeout
|
|
|
|
|
(begin
|
|
|
|
|
(warning (G_ "while fetching ~a: server is somewhat slow~%")
|
|
|
|
|
(uri->string uri))
|
|
|
|
|
(warning (G_ "try `--no-substitutes' if the problem persists~%")))
|
|
|
|
|
(with-cached-connection uri port
|
|
|
|
|
(http-fetch uri #:text? #f
|
|
|
|
|
#:port port
|
|
|
|
|
#:keep-alive? #t
|
|
|
|
|
#:buffered? #f))))
|
2021-01-07 15:41:50 -05:00
|
|
|
|
(else
|
|
|
|
|
(leave (G_ "unsupported substitute URI scheme: ~a~%")
|
|
|
|
|
(uri->string uri)))))
|
|
|
|
|
|
2023-05-22 11:19:39 -04:00
|
|
|
|
(define (try-fetch choices)
|
|
|
|
|
(match choices
|
|
|
|
|
(((uri compression file-size) rest ...)
|
|
|
|
|
(guard (c ((and (pair? rest) (http-get-error? c))
|
|
|
|
|
(warning (G_ "download from '~a' failed, trying next URL~%")
|
|
|
|
|
(uri->string uri))
|
|
|
|
|
(try-fetch rest)))
|
|
|
|
|
(let ((port download-size (fetch uri)))
|
|
|
|
|
(unless print-build-trace?
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
(G_ "Downloading ~a...~%") (uri->string uri)))
|
|
|
|
|
(values port uri compression download-size))))
|
|
|
|
|
(()
|
|
|
|
|
(leave (G_ "no valid nar URLs for ~a at ~a~%")
|
|
|
|
|
(narinfo-path narinfo)
|
|
|
|
|
(narinfo-uri-base narinfo)))))
|
|
|
|
|
|
2023-06-08 16:43:05 -04:00
|
|
|
|
;; Delete DESTINATION first--necessary when starting over after a failed
|
|
|
|
|
;; download.
|
|
|
|
|
(catch-system-error (delete-file-recursively destination))
|
|
|
|
|
|
2023-05-22 11:19:39 -04:00
|
|
|
|
(let ((choices (narinfo-preferred-uris narinfo
|
|
|
|
|
#:fast-decompression?
|
|
|
|
|
%prefer-fast-decompression?)))
|
|
|
|
|
;; 'guix publish' without '--cache' doesn't specify a Content-Length, so
|
|
|
|
|
;; DOWNLOAD-SIZE is #f in this case.
|
|
|
|
|
(let* ((raw uri compression download-size (try-fetch choices))
|
2022-06-26 17:07:39 -04:00
|
|
|
|
(progress
|
|
|
|
|
(let* ((dl-size (or download-size
|
|
|
|
|
(and (equal? compression "none")
|
|
|
|
|
(narinfo-size narinfo))))
|
|
|
|
|
(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))))
|
|
|
|
|
;; Keep RAW open upon completion so we can later reuse
|
|
|
|
|
;; the underlying connection. Pass the download size so
|
|
|
|
|
;; that this procedure won't block reading from RAW.
|
|
|
|
|
(progress-report-port reporter raw
|
|
|
|
|
#:close? #f
|
|
|
|
|
#:download-size dl-size)))
|
|
|
|
|
(input pids
|
|
|
|
|
;; NOTE: This 'progress' port of current process will be
|
|
|
|
|
;; closed here, while the child process doing the
|
|
|
|
|
;; reporting will close it upon exit.
|
|
|
|
|
(decompressed-port (string->symbol compression)
|
|
|
|
|
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.
|
2021-03-14 10:05:30 -04:00
|
|
|
|
(define cpu-usage
|
|
|
|
|
(with-cpu-usage-monitoring
|
|
|
|
|
(restore-file hashed destination
|
|
|
|
|
#:dump-file (if (and destination-in-store?
|
|
|
|
|
deduplicate?)
|
|
|
|
|
dump-file/deduplicate*
|
|
|
|
|
dump-file))))
|
|
|
|
|
|
|
|
|
|
;; Create a hysteresis: depending on CPU usage, favor compression
|
|
|
|
|
;; methods with faster decompression (like ztsd) or methods with better
|
|
|
|
|
;; compression ratios (like lzip). This stems from the observation that
|
|
|
|
|
;; substitution can be CPU-bound when high-speed networks are used:
|
|
|
|
|
;; <https://lists.gnu.org/archive/html/guix-devel/2020-12/msg00177.html>.
|
|
|
|
|
;; To simulate "slow" networking or changing conditions, run:
|
|
|
|
|
;; sudo tc qdisc add dev eno1 root tbf rate 512kbit latency 50ms burst 1540
|
|
|
|
|
;; and then cancel with:
|
|
|
|
|
;; sudo tc qdisc del dev eno1 root
|
|
|
|
|
(when (> cpu-usage .8)
|
|
|
|
|
(set! %prefer-fast-decompression? #t))
|
|
|
|
|
(when (< cpu-usage .2)
|
|
|
|
|
(set! %prefer-fast-decompression? #f))
|
|
|
|
|
|
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
|
2021-03-21 12:20:10 -04:00
|
|
|
|
;; one to visually separate substitutions. When PRINT-BUILD-TRACE? is
|
|
|
|
|
;; true, leave it up to (guix status) to prettify things.
|
|
|
|
|
(newline (current-error-port))
|
|
|
|
|
(unless print-build-trace?
|
|
|
|
|
(newline (current-error-port)))
|
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
|
|
|
|
|
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.
|
2022-09-22 06:08:16 -04:00
|
|
|
|
(format status-port "success ~a ~a~%"
|
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
|
|
|
|
(narinfo-hash narinfo) (narinfo-size narinfo))
|
|
|
|
|
;; The actual data has a different hash than that in NARINFO.
|
2022-09-22 06:08:16 -04:00
|
|
|
|
(format status-port "hash-mismatch ~a ~a ~a~%"
|
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
|
|
|
|
(hash-algorithm-name algorithm)
|
|
|
|
|
(bytevector->nix-base32-string expected)
|
|
|
|
|
(bytevector->nix-base32-string actual)))))))
|
2015-07-13 11:51:02 -04:00
|
|
|
|
|
2023-05-22 06:15:14 -04:00
|
|
|
|
(define (system-error? exception)
|
|
|
|
|
"Return true if EXCEPTION is a Guile 'system-error exception."
|
|
|
|
|
(and (kind-and-args-exception? exception)
|
|
|
|
|
(eq? 'system-error (exception-kind exception))))
|
substitute: Retry downloading when a nar is unavailable.
Fixes <https://issues.guix.gnu.org/57978>
Reported by Attila Lendvai <attila@lendvai.name>.
Previously, if a narinfo was available but its corresponding nar was
missing (for instance because the narinfo was cached and the server
became unreachable in the meantime), 'guix substitute --substitute'
would try to download the nar from its preferred location and abort when
that fails. This change forces one retry with each of the URLs.
* guix/scripts/substitute.scm (download-nar): Do not catch
'http-get-error?' exceptions.
(system-error?, network-error?, process-substitution/fallback): New
procedures.
(process-substitution): Call 'process-substitution/fallback' upon
'network-error?'.
* tests/substitute.scm ("substitute, first URL has narinfo but lacks nar, second URL unauthorized")
("substitute, first URL has narinfo but nar is 404, both URLs authorized")
("substitute, first URL has narinfo but nar is 404, one URL authorized")
("substitute, narinfo is available but nar is missing"): New tests.
2022-09-23 02:00:13 -04:00
|
|
|
|
|
|
|
|
|
(define network-error?
|
|
|
|
|
(let ((kind-and-args? (exception-predicate &exception-with-kind-and-args)))
|
|
|
|
|
(lambda (exception)
|
|
|
|
|
"Return true if EXCEPTION denotes a networking error."
|
|
|
|
|
(or (and (system-error? exception)
|
|
|
|
|
(let ((errno (system-error-errno
|
|
|
|
|
(cons 'system-error (exception-args exception)))))
|
2023-04-17 10:00:16 -04:00
|
|
|
|
(memv errno (list ECONNRESET ECONNABORTED ETIMEDOUT
|
substitute: Retry downloading when a nar is unavailable.
Fixes <https://issues.guix.gnu.org/57978>
Reported by Attila Lendvai <attila@lendvai.name>.
Previously, if a narinfo was available but its corresponding nar was
missing (for instance because the narinfo was cached and the server
became unreachable in the meantime), 'guix substitute --substitute'
would try to download the nar from its preferred location and abort when
that fails. This change forces one retry with each of the URLs.
* guix/scripts/substitute.scm (download-nar): Do not catch
'http-get-error?' exceptions.
(system-error?, network-error?, process-substitution/fallback): New
procedures.
(process-substitution): Call 'process-substitution/fallback' upon
'network-error?'.
* tests/substitute.scm ("substitute, first URL has narinfo but lacks nar, second URL unauthorized")
("substitute, first URL has narinfo but nar is 404, both URLs authorized")
("substitute, first URL has narinfo but nar is 404, one URL authorized")
("substitute, narinfo is available but nar is missing"): New tests.
2022-09-23 02:00:13 -04:00
|
|
|
|
ECONNREFUSED EHOSTUNREACH
|
|
|
|
|
ENOENT)))) ;for "file://"
|
|
|
|
|
(and (kind-and-args? exception)
|
|
|
|
|
(memq (exception-kind exception)
|
|
|
|
|
'(gnutls-error getaddrinfo-error)))
|
|
|
|
|
(and (http-get-error? exception)
|
|
|
|
|
(begin
|
|
|
|
|
(warning (G_ "download from '~a' failed: ~a, ~s~%")
|
|
|
|
|
(uri->string (http-get-error-uri exception))
|
|
|
|
|
(http-get-error-code exception)
|
|
|
|
|
(http-get-error-reason exception))
|
|
|
|
|
#t))))))
|
|
|
|
|
|
|
|
|
|
(define* (process-substitution/fallback port narinfo destination
|
|
|
|
|
#:key cache-urls acl
|
|
|
|
|
deduplicate? print-build-trace?)
|
|
|
|
|
"Attempt to substitute NARINFO, which is assumed to be authorized or
|
|
|
|
|
equivalent, by trying to download its nar from each entry in CACHE-URLS.
|
|
|
|
|
|
|
|
|
|
This can be less efficient than 'lookup-narinfo', which stops at the first
|
|
|
|
|
entry that provides a valid narinfo, but it makes sure we eventually find a
|
|
|
|
|
way to download the nar."
|
|
|
|
|
;; Note: Keep NARINFO's uri-base in CACHE-URLS: that lets us retry in case
|
|
|
|
|
;; this was a transient issue.
|
|
|
|
|
(let loop ((cache-urls cache-urls))
|
|
|
|
|
(match cache-urls
|
|
|
|
|
(()
|
2023-12-02 06:04:23 -05:00
|
|
|
|
(report-error (G_ "failed to find alternative substitute for '~a'~%")
|
|
|
|
|
(narinfo-path narinfo))
|
|
|
|
|
(display "not-found\n" port))
|
substitute: Retry downloading when a nar is unavailable.
Fixes <https://issues.guix.gnu.org/57978>
Reported by Attila Lendvai <attila@lendvai.name>.
Previously, if a narinfo was available but its corresponding nar was
missing (for instance because the narinfo was cached and the server
became unreachable in the meantime), 'guix substitute --substitute'
would try to download the nar from its preferred location and abort when
that fails. This change forces one retry with each of the URLs.
* guix/scripts/substitute.scm (download-nar): Do not catch
'http-get-error?' exceptions.
(system-error?, network-error?, process-substitution/fallback): New
procedures.
(process-substitution): Call 'process-substitution/fallback' upon
'network-error?'.
* tests/substitute.scm ("substitute, first URL has narinfo but lacks nar, second URL unauthorized")
("substitute, first URL has narinfo but nar is 404, both URLs authorized")
("substitute, first URL has narinfo but nar is 404, one URL authorized")
("substitute, narinfo is available but nar is missing"): New tests.
2022-09-23 02:00:13 -04:00
|
|
|
|
((cache-url rest ...)
|
|
|
|
|
(match (lookup-narinfos cache-url
|
|
|
|
|
(list (narinfo-path narinfo))
|
|
|
|
|
#:open-connection
|
|
|
|
|
open-connection-for-uri/cached)
|
|
|
|
|
((alternate)
|
|
|
|
|
(if (or (equivalent-narinfo? narinfo alternate)
|
|
|
|
|
(valid-narinfo? alternate acl)
|
|
|
|
|
(%allow-unauthenticated-substitutes?))
|
|
|
|
|
(guard (c ((network-error? c) (loop rest)))
|
|
|
|
|
(download-nar alternate destination
|
|
|
|
|
#:status-port port
|
|
|
|
|
#:deduplicate? deduplicate?
|
|
|
|
|
#:print-build-trace? print-build-trace?))
|
|
|
|
|
(loop rest)))
|
|
|
|
|
(()
|
|
|
|
|
(loop rest)))))))
|
|
|
|
|
|
2022-09-22 06:08:16 -04:00
|
|
|
|
(define* (process-substitution port store-item destination
|
|
|
|
|
#:key cache-urls acl
|
|
|
|
|
deduplicate? print-build-trace?)
|
|
|
|
|
"Substitute STORE-ITEM (a store file name) from CACHE-URLS, and write it to
|
|
|
|
|
DESTINATION as a nar file. Verify the substitute against ACL, and verify its
|
|
|
|
|
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 to
|
|
|
|
|
PORT."
|
|
|
|
|
(define narinfo
|
|
|
|
|
(lookup-narinfo cache-urls store-item
|
|
|
|
|
(if (%allow-unauthenticated-substitutes?)
|
|
|
|
|
(const #t)
|
|
|
|
|
(cut valid-narinfo? <> acl))))
|
|
|
|
|
|
|
|
|
|
(unless narinfo
|
|
|
|
|
(leave (G_ "no valid substitute for '~a'~%")
|
|
|
|
|
store-item))
|
|
|
|
|
|
substitute: Retry downloading when a nar is unavailable.
Fixes <https://issues.guix.gnu.org/57978>
Reported by Attila Lendvai <attila@lendvai.name>.
Previously, if a narinfo was available but its corresponding nar was
missing (for instance because the narinfo was cached and the server
became unreachable in the meantime), 'guix substitute --substitute'
would try to download the nar from its preferred location and abort when
that fails. This change forces one retry with each of the URLs.
* guix/scripts/substitute.scm (download-nar): Do not catch
'http-get-error?' exceptions.
(system-error?, network-error?, process-substitution/fallback): New
procedures.
(process-substitution): Call 'process-substitution/fallback' upon
'network-error?'.
* tests/substitute.scm ("substitute, first URL has narinfo but lacks nar, second URL unauthorized")
("substitute, first URL has narinfo but nar is 404, both URLs authorized")
("substitute, first URL has narinfo but nar is 404, one URL authorized")
("substitute, narinfo is available but nar is missing"): New tests.
2022-09-23 02:00:13 -04:00
|
|
|
|
(guard (c ((network-error? c)
|
|
|
|
|
(format (current-error-port)
|
|
|
|
|
(G_ "retrying download of '~a' with other substitute URLs...~%")
|
|
|
|
|
store-item)
|
|
|
|
|
(process-substitution/fallback port narinfo destination
|
|
|
|
|
#:cache-urls cache-urls
|
|
|
|
|
#:acl acl
|
|
|
|
|
#:deduplicate? deduplicate?
|
|
|
|
|
#:print-build-trace?
|
|
|
|
|
print-build-trace?)))
|
|
|
|
|
(download-nar narinfo destination
|
|
|
|
|
#:status-port port
|
|
|
|
|
#:deduplicate? deduplicate?
|
|
|
|
|
#:print-build-trace? print-build-trace?)))
|
2022-09-22 06:08:16 -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)))))
|
|
|
|
|
|
2023-01-09 04:27:54 -05:00
|
|
|
|
(define find-daemon-option
|
|
|
|
|
(let ((options (delay (daemon-options))))
|
|
|
|
|
(lambda (option)
|
|
|
|
|
"Return the value of build daemon option OPTION, or #f if it could not be
|
2014-10-09 07:25:41 -04:00
|
|
|
|
found."
|
2023-01-09 04:27:54 -05:00
|
|
|
|
(assoc-ref (force options) option))))
|
2014-10-09 07:25:41 -04:00
|
|
|
|
|
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.
|
2021-05-15 06:02:36 -04:00
|
|
|
|
'("http://ci.guix.gnu.org"
|
|
|
|
|
"http://bordeaux.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"))
|
2021-03-29 10:55:58 -04:00
|
|
|
|
(discover? (and option (string=? option "true"))))
|
2020-12-04 08:25:57 -05:00
|
|
|
|
(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
|
|
|
|
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(define %reply-file-descriptor
|
|
|
|
|
;; The file descriptor where replies to the daemon must be sent, or #f to
|
|
|
|
|
;; use the current output port instead.
|
|
|
|
|
(make-parameter 4))
|
2021-02-24 09:05:06 -05:00
|
|
|
|
|
2020-09-01 16:13:11 -04:00
|
|
|
|
(define-command (guix-substitute . args)
|
|
|
|
|
(category internal)
|
|
|
|
|
(synopsis "implement the build daemon's substituter protocol")
|
|
|
|
|
|
2022-05-22 09:54:42 -04:00
|
|
|
|
(match args
|
|
|
|
|
((or ("-V") ("--version"))
|
|
|
|
|
(show-version-and-exit "guix substitute"))
|
|
|
|
|
((or ("-h") ("--help") ())
|
2023-10-16 12:44:35 -04:00
|
|
|
|
(leave-on-EPIPE (show-help))
|
2022-05-22 09:54:42 -04:00
|
|
|
|
(exit 0))
|
|
|
|
|
(_ #t))
|
|
|
|
|
|
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"))
|
|
|
|
|
|
2021-04-06 06:10:29 -04:00
|
|
|
|
(define reply-port
|
|
|
|
|
;; Port used to reply to the daemon.
|
|
|
|
|
(if (%reply-file-descriptor)
|
|
|
|
|
(fdopen (%reply-file-descriptor) "wl")
|
|
|
|
|
(current-output-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 reply-port command
|
|
|
|
|
#:cache-urls (substitute-urls)
|
|
|
|
|
#:acl acl)
|
|
|
|
|
(loop (read-line)))))))
|
|
|
|
|
(("--substitute")
|
|
|
|
|
;; 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)))
|
|
|
|
|
(let loop ()
|
|
|
|
|
(match (read-line)
|
|
|
|
|
((? eof-object?)
|
|
|
|
|
#t)
|
|
|
|
|
((= string-tokenize ("substitute" store-path destination))
|
|
|
|
|
(process-substitution reply-port store-path destination
|
|
|
|
|
#:cache-urls (substitute-urls)
|
|
|
|
|
#:acl (current-acl)
|
|
|
|
|
#:deduplicate? deduplicate?
|
|
|
|
|
#:print-build-trace?
|
|
|
|
|
print-build-trace?)
|
|
|
|
|
(loop))))))
|
|
|
|
|
(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)
|
2021-02-24 09:05:06 -05:00
|
|
|
|
;;; eval: (put 'with-redirected-error-port 'scheme-indent-function 0)
|
2021-03-15 11:05:08 -04:00
|
|
|
|
;;; eval: (put 'with-cached-connection 'scheme-indent-function 2)
|
|
|
|
|
;;; 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
|