From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id GMJWAYr/wl5rDAAA0tVLHw (envelope-from ) for ; Mon, 18 May 2020 21:35:06 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 8KzUOIn/wl7VJwAA1q6Kng (envelope-from ) for ; Mon, 18 May 2020 21:35:05 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5D229940428 for ; Mon, 18 May 2020 21:35:05 +0000 (UTC) Received: from localhost ([::1]:54968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janPc-0008S5-Ae for larch@yhetil.org; Mon, 18 May 2020 17:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1janOe-0007wA-IE for guix-patches@gnu.org; Mon, 18 May 2020 17:34:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1janOd-0000W7-7c for guix-patches@gnu.org; Mon, 18 May 2020 17:34:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1janOd-0001aZ-4c for guix-patches@gnu.org; Mon, 18 May 2020 17:34:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41382] [PATCH 5/6] packages: Add 'sha512' optional field to . Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 May 2020 21:34:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41382 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 41382@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 41382-submit@debbugs.gnu.org id=B41382.15898376016033 (code B ref 41382); Mon, 18 May 2020 21:34:03 +0000 Received: (at 41382) by debbugs.gnu.org; 18 May 2020 21:33:21 +0000 Received: from localhost ([127.0.0.1]:48467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNl-0001Yp-0f for submit@debbugs.gnu.org; Mon, 18 May 2020 17:33:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59574) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNg-0001Xb-UN for 41382@debbugs.gnu.org; Mon, 18 May 2020 17:33:05 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37559) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNb-0000QN-Mu; Mon, 18 May 2020 17:32:59 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=50964 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1janNa-0007J8-PW; Mon, 18 May 2020 17:32:59 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 18 May 2020 23:32:43 +0200 Message-Id: <20200518213244.24165-5-ludo@gnu.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518213244.24165-1-ludo@gnu.org> References: <20200518213244.24165-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 3.99 X-TUID: cGOrIK7alXEU * guix/packages.scm ()[sha512]: New field. (print-origin): Honor it. (origin->derivation): Likewise. * tests/packages.scm ("package-source-derivation, origin, sha512"): New test. * doc/guix.texi (origin Reference): Document 'sha512'. --- doc/guix.texi | 8 +++++++- guix/packages.scm | 25 ++++++++++++++----------- tests/packages.scm | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index fdd9622211..50d7eb7a43 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5966,10 +5966,16 @@ specified in the @code{uri} field as a @code{git-reference} object; a @end table @item @code{sha256} -A bytevector containing the SHA-256 hash of the source. Typically the +@itemx @code{sha512} +A bytevector containing the SHA-256 (respectively SHA-512) hash of the source. Typically the @code{base32} form is used here to generate the bytevector from a base-32 string. +One of these fields must be a bytevector while the others can be +@code{#f}. When several hashes are provided, the ``strongest'' is used +when computing the underlying fixed-output derivation +(@pxref{Derivations}). + You can obtain this information using @code{guix download} (@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking guix hash}). diff --git a/guix/packages.scm b/guix/packages.scm index 3fff50a6e8..7cf4c9c3e6 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -164,6 +164,7 @@ (uri origin-uri) ; string (method origin-method) ; procedure (sha256 origin-sha256) ; bytevector + (sha512 origin-sha512 (default #f)) ; bytevector | #f (file-name origin-file-name (default #f)) ; optional file name ;; Patches are delayed so that the 'search-patch' calls are made lazily, @@ -189,9 +190,9 @@ (define (print-origin origin port) "Write a concise representation of ORIGIN to PORT." (match origin - (($ uri method sha256 file-name patches) + (($ uri method sha256 sha512 file-name patches) (simple-format port "#" - uri (bytevector->base32-string sha256) + uri (bytevector->base32-string (or sha512 sha256)) (force patches) (number->string (object-address origin) 16))))) @@ -1381,18 +1382,20 @@ unless you know what you are doing." #:optional (system (%current-system))) "Return the derivation corresponding to ORIGIN." (match origin - (($ uri method sha256 name (= force ()) #f) + (($ uri method sha256 sha512 name (= force ()) #f) ;; No patches, no snippet: this is a fixed-output derivation. - (method uri 'sha256 sha256 name #:system system)) - (($ uri method sha256 name (= force (patches ...)) snippet + (let ((algorithm (if sha512 'sha512 'sha256))) + (method uri algorithm (or sha512 sha256) name #:system system))) + (($ uri method sha256 sha512 name (= force (patches ...)) snippet (flags ...) inputs (modules ...) guile-for-build) ;; Patches and/or a snippet. - (mlet %store-monad ((source (method uri 'sha256 sha256 name - #:system system)) - (guile (package->derivation (or guile-for-build - (default-guile)) - system - #:graft? #f))) + (mlet* %store-monad ((algorithm -> (if sha512 'sha512 'sha256)) + (source (method uri algorithm (or sha512 sha256) + name #:system system)) + (guile (package->derivation (or guile-for-build + (default-guile)) + system + #:graft? #f))) (patch-and-repack source patches #:inputs inputs #:snippet snippet diff --git a/tests/packages.scm b/tests/packages.scm index c528d2080c..06d41b5ce7 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -51,6 +51,7 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (srfi srfi-64) + #:use-module (rnrs bytevectors) #:use-module (rnrs io ports) #:use-module (ice-9 vlist) #:use-module (ice-9 regex) @@ -497,6 +498,31 @@ (search-path %load-path "guix/base32.scm") get-bytevector-all))))) +(test-equal "package-source-derivation, origin, sha512" + "hello" + (let* ((bash (search-bootstrap-binary "bash" (%current-system))) + (builder (add-text-to-store %store "my-fixed-builder.sh" + "echo -n hello > $out" '())) + (method (lambda* (url hash-algo hash #:optional name + #:rest rest) + (and (eq? hash-algo 'sha512) + (raw-derivation name bash (list builder) + #:sources (list builder) + #:hash hash + #:hash-algo hash-algo)))) + (source (origin + (method method) + (uri "unused://") + (file-name "origin-sha512") + (sha256 (bytevector-hash (string->utf8 "hello") + (hash-algorithm sha256))) + (sha512 (bytevector-hash (string->utf8 "hello") + (hash-algorithm sha512))))) + (drv (package-source-derivation %store source)) + (output (derivation->output-path drv))) + (build-derivations %store (list drv)) + (call-with-input-file output get-string-all))) + (unless (network-reachable?) (test-skip 1)) (test-equal "package-source-derivation, snippet" "OK" -- 2.26.2