From patchwork Mon May 18 21:32:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22195 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C072D27BBE3; Mon, 18 May 2020 22:33:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 9380A27BBE1 for ; Mon, 18 May 2020 22:33:17 +0100 (BST) Received: from localhost ([::1]:53330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNt-0007eY-2o for patchwork@mira.cbaines.net; Mon, 18 May 2020 17:33:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1janNd-0007dy-WD for guix-patches@gnu.org; Mon, 18 May 2020 17:33:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36908) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1janNd-0000Qb-N7 for guix-patches@gnu.org; Mon, 18 May 2020 17:33:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1janNd-0001Xq-JJ for guix-patches@gnu.org; Mon, 18 May 2020 17:33:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41382] [PATCH 1/6] tests: Test 'add-to-store' with several hash algorithms. References: <20200518213116.23978-1-ludo@gnu.org> In-Reply-To: <20200518213116.23978-1-ludo@gnu.org> 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:33:01 +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.15898375795924 (code B ref 41382); Mon, 18 May 2020 21:33:01 +0000 Received: (at 41382) by debbugs.gnu.org; 18 May 2020 21:32:59 +0000 Received: from localhost ([127.0.0.1]:48453 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNb-0001XT-Ia for submit@debbugs.gnu.org; Mon, 18 May 2020 17:32:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNa-0001XE-C6 for 41382@debbugs.gnu.org; Mon, 18 May 2020 17:32:58 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37551) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNU-0000Po-N7; Mon, 18 May 2020 17:32:52 -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 1janNU-0007J8-68; Mon, 18 May 2020 17:32:52 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 18 May 2020 23:32:39 +0200 Message-Id: <20200518213244.24165-1-ludo@gnu.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * tests/store.scm ("add-to-store"): New test. --- tests/store.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/store.scm b/tests/store.scm index 0af099c1ad..f007846dc1 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -115,6 +115,18 @@ (passwd:name (getpwuid (getuid))))))) (list (stat:uid s) (stat:perms s)))) +(test-equal "add-to-store" + '("sha1" "sha256" "sha512") + (let* ((file (search-path %load-path "guix.scm")) + (content (call-with-input-file file get-bytevector-all))) + (map (lambda (hash-algo) + (let ((file (add-to-store %store "guix.scm" #f hash-algo file))) + (and (direct-store-path? file) + (bytevector=? (call-with-input-file file get-bytevector-all) + content) + hash-algo))) + '("sha1" "sha256" "sha512")))) + (test-equal "add-data-to-store" #vu8(1 2 3 4 5) (call-with-input-file (add-data-to-store %store "data" #vu8(1 2 3 4 5)) From patchwork Mon May 18 21:32:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22196 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 25D2F27BBE4; Mon, 18 May 2020 22:34:40 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id C1C2627BBE1 for ; Mon, 18 May 2020 22:34:39 +0100 (BST) Received: from localhost ([::1]:53844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janPD-0007wu-A5 for patchwork@mira.cbaines.net; Mon, 18 May 2020 17:34:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1janOc-0007vq-MM for guix-patches@gnu.org; Mon, 18 May 2020 17:34:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36923) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1janOc-0000Vt-1Y for guix-patches@gnu.org; Mon, 18 May 2020 17:34:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1janOb-0001aD-V7 for guix-patches@gnu.org; Mon, 18 May 2020 17:34:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41382] [PATCH 2/6] tests: Test fixed-output derivations with several hash algorithms. 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:01 +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.15898375845976 (code B ref 41382); Mon, 18 May 2020 21:34:01 +0000 Received: (at 41382) by debbugs.gnu.org; 18 May 2020 21:33:04 +0000 Received: from localhost ([127.0.0.1]:48459 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNf-0001YJ-RN for submit@debbugs.gnu.org; Mon, 18 May 2020 17:33:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59556) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNb-0001XH-QJ for 41382@debbugs.gnu.org; Mon, 18 May 2020 17:33:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37555) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNW-0000Q2-Iw; Mon, 18 May 2020 17:32:54 -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 1janNV-0007J8-B2; Mon, 18 May 2020 17:32:53 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 18 May 2020 23:32:40 +0200 Message-Id: <20200518213244.24165-2-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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * tests/derivations.scm ("fixed-output derivation"): Test several hash algorithms. --- tests/derivations.scm | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/tests/derivations.scm b/tests/derivations.scm index ef6cec6c76..a409fa99f0 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -324,20 +324,29 @@ #:hash hash #:hash-algo 'sha256))) (fixed-output-derivation? drv))) -(test-assert "fixed-output derivation" - (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" - "echo -n hello > $out" '())) - (hash (sha256 (string->utf8 "hello"))) - (drv (derivation %store "fixed" - %bash `(,builder) - #:sources `(,builder) ;optional - #:hash hash #:hash-algo 'sha256)) - (succeeded? (build-derivations %store (list drv)))) - (and succeeded? - (let ((p (derivation->output-path drv))) - (and (equal? (string->utf8 "hello") - (call-with-input-file p get-bytevector-all)) - (bytevector? (query-path-hash %store p))))))) +(test-equal "fixed-output derivation" + '(sha1 sha256 sha512) + (map (lambda (hash-algorithm) + (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" + "echo -n hello > $out" '())) + (sha256 (sha256 (string->utf8 "hello"))) + (hash (bytevector-hash + (string->utf8 "hello") + (lookup-hash-algorithm hash-algorithm))) + (drv (derivation %store + (string-append + "fixed-" (symbol->string hash-algorithm)) + %bash `(,builder) + #:sources `(,builder) ;optional + #:hash hash + #:hash-algo hash-algorithm))) + (build-derivations %store (list drv)) + (let ((p (derivation->output-path drv))) + (and (bytevector=? (string->utf8 "hello") + (call-with-input-file p get-bytevector-all)) + (bytevector? (query-path-hash %store p)) + hash-algorithm)))) + '(sha1 sha256 sha512))) (test-assert "fixed-output derivation: output paths are equal" (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh" From patchwork Mon May 18 21:32:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22198 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6F64F27BBE4; Mon, 18 May 2020 22:34:59 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id D361527BBE3 for ; Mon, 18 May 2020 22:34:54 +0100 (BST) Received: from localhost ([::1]:54406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janPS-0008EP-Cr for patchwork@mira.cbaines.net; Mon, 18 May 2020 17:34:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1janOc-0007vr-NB for guix-patches@gnu.org; Mon, 18 May 2020 17:34:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1janOc-0000Vw-EX for guix-patches@gnu.org; Mon, 18 May 2020 17:34:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1janOc-0001aL-C2 for guix-patches@gnu.org; Mon, 18 May 2020 17:34:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41382] [PATCH 3/6] guix hash, guix download: Add '--hash'. 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:02 +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.15898375845983 (code B ref 41382); Mon, 18 May 2020 21:34:02 +0000 Received: (at 41382) by debbugs.gnu.org; 18 May 2020 21:33:04 +0000 Received: from localhost ([127.0.0.1]:48461 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNg-0001YL-4b for submit@debbugs.gnu.org; Mon, 18 May 2020 17:33:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59566) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNd-0001XK-Vs for 41382@debbugs.gnu.org; Mon, 18 May 2020 17:33:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37557) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNY-0000QD-Nz; Mon, 18 May 2020 17:32:56 -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 1janNX-0007J8-ND; Mon, 18 May 2020 17:32:56 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 18 May 2020 23:32:41 +0200 Message-Id: <20200518213244.24165-3-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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/download.scm (%default-options): Add 'hash-algorithm'. (show-help, %options): Add "--hash". (guix-download): Honor it. * guix/scripts/hash.scm (%default-options): Add 'hash-algorithm'. (show-help, %options): Add "--hash". (guix-hash): Honor it. * tests/guix-hash.sh: Test '-H sha512'. * doc/guix.texi (Invoking guix download): Document it. (Invoking guix hash): Document it. --- doc/guix.texi | 15 +++++++++++++++ guix/scripts/download.scm | 14 ++++++++++++-- guix/scripts/hash.scm | 21 +++++++++++++++++---- tests/guix-hash.sh | 6 +++++- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index eef5b703fe..0cf006770e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9018,6 +9018,11 @@ Certificates}), unless @option{--no-check-certificate} is used. The following options are available: @table @code +@item --hash=@var{algorithm} +@itemx -H @var{algorithm} +Compute a hash using the specified @var{algorithm}. @xref{Invoking guix +hash}, for more information. + @item --format=@var{fmt} @itemx -f @var{fmt} Write the hash in the format specified by @var{fmt}. For more @@ -9057,6 +9062,16 @@ following options: @table @code +@item --hash=@var{algorithm} +@itemx -H @var{algorithm} +Compute a hash using the specified @var{algorithm}, @code{sha256} by +default. + +@var{algorithm} must the name of a cryptographic hash algorithm +supported by Libgcrypt @i{via} Guile-Gcrypt---e.g., @code{sha512} or +@code{sha3-256} (@pxref{Hash Functions,,, guile-gcrypt, Guile-Gcrypt +Reference Manual}). + @item --format=@var{fmt} @itemx -f @var{fmt} Write the hash in the format specified by @var{fmt}. diff --git a/guix/scripts/download.scm b/guix/scripts/download.scm index 22cd75ea0b..b4446c2e2f 100644 --- a/guix/scripts/download.scm +++ b/guix/scripts/download.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2015, 2016, 2017 Ludovic Courtès +;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2020 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -77,6 +77,7 @@ (define %default-options ;; Alist of default option values. `((format . ,bytevector->nix-base32-string) + (hash-algorithm . ,(hash-algorithm sha256)) (verify-certificate? . #t) (download-proc . ,download-to-store*))) @@ -89,6 +90,8 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex' and 'hexadecimal' can be used as well).\n")) (format #t (G_ " -f, --format=FMT write the hash in the given format")) + (format #t (G_ " + -H, --hash=ALGORITHM use the given hash ALGORITHM")) (format #t (G_ " --no-check-certificate do not validate the certificate of HTTPS servers ")) @@ -119,6 +122,13 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (alist-cons 'format fmt-proc (alist-delete 'format result)))) + (option '(#\H "hash") #t #f + (lambda (opt name arg result) + (match (lookup-hash-algorithm (string->symbol arg)) + (#f + (leave (G_ "~a: unknown hash algorithm~%") arg)) + (algo + (alist-cons 'hash-algorithm algo result))))) (option '("no-check-certificate") #f #f (lambda (opt name arg result) (alist-cons 'verify-certificate? #f result))) @@ -175,7 +185,7 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (or path (leave (G_ "~a: download failed~%") arg)) - port-sha256)) + (cute port-hash (assoc-ref opts 'hash-algorithm) <>))) (fmt (assq-ref opts 'format))) (format #t "~a~%~a~%" path (fmt hash)) #t))) diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index b8b2158195..cfc4420260 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2016, 2017 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2016, 2017, 2020 Ludovic Courtès ;;; Copyright © 2013 Nikita Karetnikov ;;; Copyright © 2016 Jan Nieuwenhuizen ;;; Copyright © 2018 Tim Gesthuizen @@ -42,7 +42,8 @@ (define %default-options ;; Alist of default option values. - `((format . ,bytevector->nix-base32-string))) + `((format . ,bytevector->nix-base32-string) + (hash-algorithm . ,(hash-algorithm sha256)))) (define (show-help) (display (G_ "Usage: guix hash [OPTION] FILE @@ -53,6 +54,8 @@ and 'hexadecimal' can be used as well).\n")) (format #t (G_ " -x, --exclude-vcs exclude version control directories")) (format #t (G_ " + -H, --hash=ALGORITHM use the given hash ALGORITHM")) + (format #t (G_ " -f, --format=FMT write the hash in the given format")) (format #t (G_ " -r, --recursive compute the hash on FILE recursively")) @@ -69,6 +72,13 @@ and 'hexadecimal' can be used as well).\n")) (list (option '(#\x "exclude-vcs") #f #f (lambda (opt name arg result) (alist-cons 'exclude-vcs? #t result))) + (option '(#\H "hash") #t #f + (lambda (opt name arg result) + (match (lookup-hash-algorithm (string->symbol arg)) + (#f + (leave (G_ "~a: unknown hash algorithm~%") arg)) + (algo + (alist-cons 'hash-algorithm algo result))))) (option '(#\f "format") #t #f (lambda (opt name arg result) (define fmt-proc @@ -139,8 +149,11 @@ and 'hexadecimal' can be used as well).\n")) (force-output port) (get-hash)) (match file - ("-" (port-sha256 (current-input-port))) - (_ (call-with-input-file file port-sha256)))))) + ("-" (port-hash (assoc-ref opts 'hash-algorithm) + (current-input-port))) + (_ (call-with-input-file file + (cute port-hash (assoc-ref opts 'hash-algorithm) + <>))))))) (match args ((file) diff --git a/tests/guix-hash.sh b/tests/guix-hash.sh index 190c9e7f8a..1c595b49ed 100644 --- a/tests/guix-hash.sh +++ b/tests/guix-hash.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2013, 2014, 2016 Ludovic Courtès +# Copyright © 2013, 2014, 2016, 2020 Ludovic Courtès # Copyright © 2016 Jan Nieuwenhuizen # # This file is part of GNU Guix. @@ -31,6 +31,10 @@ test `echo -n | guix hash -` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9 test `guix hash -f nix-base32 /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73 test `guix hash -f hex /dev/null` = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfeswmrw6csxbkq +test `guix hash -H sha512 -f hex /dev/null` = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e + +if guix hash -H abcd1234 /dev/null; +then false; else true; fi mkdir "$tmpdir" echo -n executable > "$tmpdir/exe" From patchwork Mon May 18 21:32:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22200 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5633B27BBE3; Mon, 18 May 2020 22:35:18 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 94E8527BBE1 for ; Mon, 18 May 2020 22:35:17 +0100 (BST) Received: from localhost ([::1]:55202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janPp-00006K-56 for patchwork@mira.cbaines.net; Mon, 18 May 2020 17:35:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1janOe-0007wC-Ii for guix-patches@gnu.org; Mon, 18 May 2020 17:34:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1janOc-0000W4-R4 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 1janOc-0001aS-Os for guix-patches@gnu.org; Mon, 18 May 2020 17:34:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41382] [PATCH 4/6] guix hash, guix download: Support base64 format. 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:02 +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.15898375896006 (code B ref 41382); Mon, 18 May 2020 21:34:02 +0000 Received: (at 41382) by debbugs.gnu.org; 18 May 2020 21:33:09 +0000 Received: from localhost ([127.0.0.1]:48465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNk-0001Ym-LR for submit@debbugs.gnu.org; Mon, 18 May 2020 17:33:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNf-0001XM-2r for 41382@debbugs.gnu.org; Mon, 18 May 2020 17:33:03 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37558) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNZ-0000QI-RM; Mon, 18 May 2020 17:32:57 -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 1janNZ-0007J8-20; Mon, 18 May 2020 17:32:57 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 18 May 2020 23:32:42 +0200 Message-Id: <20200518213244.24165-4-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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/download.scm (show-help, %options): Support "base64" format. * guix/scripts/hash.scm (show-help, %options): Likewise. * tests/guix-hash.sh: Test it. * doc/guix.texi (Invoking guix hash): Document it. --- doc/guix.texi | 2 +- guix/scripts/download.scm | 12 ++++++++---- guix/scripts/hash.scm | 14 +++++++++----- tests/guix-hash.sh | 1 + 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 0cf006770e..fdd9622211 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9076,7 +9076,7 @@ Reference Manual}). @itemx -f @var{fmt} Write the hash in the format specified by @var{fmt}. -Supported formats: @code{nix-base32}, @code{base32}, @code{base16} +Supported formats: @code{base64}, @code{nix-base32}, @code{base32}, @code{base16} (@code{hex} and @code{hexadecimal} can be used as well). If the @option{--format} option is not specified, @command{guix hash} diff --git a/guix/scripts/download.scm b/guix/scripts/download.scm index b4446c2e2f..589f62da9d 100644 --- a/guix/scripts/download.scm +++ b/guix/scripts/download.scm @@ -23,6 +23,7 @@ #:use-module (gcrypt hash) #:use-module (guix base16) #:use-module (guix base32) + #:autoload (guix base64) (base64-encode) #:use-module ((guix download) #:hide (url-fetch)) #:use-module ((guix build download) #:select (url-fetch)) @@ -84,10 +85,11 @@ (define (show-help) (display (G_ "Usage: guix download [OPTION] URL Download the file at URL to the store or to the given file, and print its -file name and the hash of its contents. - -Supported formats: 'nix-base32' (default), 'base32', and 'base16' -('hex' and 'hexadecimal' can be used as well).\n")) +file name and the hash of its contents.\n")) + (newline) + (display (G_ "\ +Supported formats: 'base64', 'nix-base32' (default), 'base32', +and 'base16' ('hex' and 'hexadecimal' can be used as well).\n")) (format #t (G_ " -f, --format=FMT write the hash in the given format")) (format #t (G_ " @@ -111,6 +113,8 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (lambda (opt name arg result) (define fmt-proc (match arg + ("base64" + base64-encode) ("nix-base32" bytevector->nix-base32-string) ("base32" diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index cfc4420260..9b4f419a24 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -20,12 +20,13 @@ ;;; along with GNU Guix. If not, see . (define-module (guix scripts hash) - #:use-module (guix base32) #:use-module (gcrypt hash) #:use-module (guix serialization) #:use-module (guix ui) #:use-module (guix scripts) #:use-module (guix base16) + #:use-module (guix base32) + #:autoload (guix base64) (base64-encode) #:use-module (ice-9 binary-ports) #:use-module (rnrs files) #:use-module (ice-9 match) @@ -47,10 +48,11 @@ (define (show-help) (display (G_ "Usage: guix hash [OPTION] FILE -Return the cryptographic hash of FILE. - -Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex' -and 'hexadecimal' can be used as well).\n")) +Return the cryptographic hash of FILE.\n")) + (newline) + (display (G_ "\ +Supported formats: 'base64', 'nix-base32' (default), 'base32', +and 'base16' ('hex' and 'hexadecimal' can be used as well).\n")) (format #t (G_ " -x, --exclude-vcs exclude version control directories")) (format #t (G_ " @@ -83,6 +85,8 @@ and 'hexadecimal' can be used as well).\n")) (lambda (opt name arg result) (define fmt-proc (match arg + ("base64" + base64-encode) ("nix-base32" bytevector->nix-base32-string) ("base32" diff --git a/tests/guix-hash.sh b/tests/guix-hash.sh index 1c595b49ed..3538b9aeda 100644 --- a/tests/guix-hash.sh +++ b/tests/guix-hash.sh @@ -32,6 +32,7 @@ test `guix hash -f nix-base32 /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lz test `guix hash -f hex /dev/null` = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfeswmrw6csxbkq test `guix hash -H sha512 -f hex /dev/null` = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e +test `guix hash -H sha1 -f base64 /dev/null` = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" if guix hash -H abcd1234 /dev/null; then false; else true; fi From patchwork Mon May 18 21:32:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22199 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3B63A27BBE3; Mon, 18 May 2020 22:35:08 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 6148327BBE1 for ; Mon, 18 May 2020 22:35:07 +0100 (BST) Received: from localhost ([::1]:54968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janPe-0008S5-4c for patchwork@mira.cbaines.net; Mon, 18 May 2020 17:35:07 -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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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" From patchwork Mon May 18 21:32:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22197 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id AFE9327BBE3; Mon, 18 May 2020 22:34:48 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 3DEE427BBE1 for ; Mon, 18 May 2020 22:34:48 +0100 (BST) Received: from localhost ([::1]:53918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janPL-0007zs-Qh for patchwork@mira.cbaines.net; Mon, 18 May 2020 17:34:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1janOe-0007wE-JX for guix-patches@gnu.org; Mon, 18 May 2020 17:34:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1janOd-0000WA-KA 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-0001ah-Hn for guix-patches@gnu.org; Mon, 18 May 2020 17:34:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41382] [PATCH 6/6] packages: Add 'base64' macro. 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.15898376016039 (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]:48469 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNx-0001ZG-C5 for submit@debbugs.gnu.org; Mon, 18 May 2020 17:33:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59578) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1janNh-0001Xh-T1 for 41382@debbugs.gnu.org; Mon, 18 May 2020 17:33:06 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37560) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1janNc-0000QU-LM; Mon, 18 May 2020 17:33:00 -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 1janNc-0007J8-0x; Mon, 18 May 2020 17:33:00 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 18 May 2020 23:32:44 +0200 Message-Id: <20200518213244.24165-6-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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/packages.scm (define-compile-time-decoder): New macro. (base32): Redefine in terms of it. (base64): New macro. --- guix/packages.scm | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/guix/packages.scm b/guix/packages.scm index 7cf4c9c3e6..724d7693c7 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -28,6 +28,7 @@ #:use-module (guix monads) #:use-module (guix gexp) #:use-module (guix base32) + #:autoload (guix base64) (base64-decode) #:use-module (guix grafts) #:use-module (guix derivations) #:use-module (guix memoization) @@ -62,6 +63,7 @@ origin-snippet origin-modules base32 + base64 package package? @@ -198,19 +200,24 @@ (set-record-type-printer! print-origin) -(define-syntax base32 - (lambda (s) - "Return the bytevector corresponding to the given Nix-base32 +(define-syntax-rule (define-compile-time-decoder name string->bytevector) + "Define NAME as a macro that runs STRING->BYTEVECTOR at macro expansion time +if possible." + (define-syntax name + (lambda (s) + "Return the bytevector corresponding to the given textual representation." - (syntax-case s () - ((_ str) - (string? (syntax->datum #'str)) - ;; A literal string: do the conversion at expansion time. - (with-syntax ((bv (nix-base32-string->bytevector - (syntax->datum #'str)))) - #''bv)) - ((_ str) - #'(nix-base32-string->bytevector str))))) + (syntax-case s () + ((_ str) + (string? (syntax->datum #'str)) + ;; A literal string: do the conversion at expansion time. + (with-syntax ((bv (string->bytevector (syntax->datum #'str)))) + #''bv)) + ((_ str) + #'(string->bytevector str)))))) + +(define-compile-time-decoder base32 nix-base32-string->bytevector) +(define-compile-time-decoder base64 base64-decode) (define (origin-actual-file-name origin) "Return the file name of ORIGIN, either its 'file-name' field or the file