From patchwork Thu Dec 29 18:13:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: pukkamustard X-Patchwork-Id: 45682 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 25E7A27BBEB; Thu, 29 Dec 2022 18:49:03 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id AC57927BBE9 for ; Thu, 29 Dec 2022 18:49:00 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pAxQl-0000AP-JM; Thu, 29 Dec 2022 13:15:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pAxQk-0000A3-Om for guix-patches@gnu.org; Thu, 29 Dec 2022 13:15:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pAxQk-00042z-Ft for guix-patches@gnu.org; Thu, 29 Dec 2022 13:15:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pAxQk-0007RH-AF for guix-patches@gnu.org; Thu, 29 Dec 2022 13:15:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52555] [PATCH v3 2/8] publish: Store ERIS encoded blocks to a local block store. Resent-From: pukkamustard Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 29 Dec 2022 18:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52555 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52555@debbugs.gnu.org Cc: pukkamustard Received: via spool by 52555-submit@debbugs.gnu.org id=B52555.167233767628487 (code B ref 52555); Thu, 29 Dec 2022 18:15:02 +0000 Received: (at 52555) by debbugs.gnu.org; 29 Dec 2022 18:14:36 +0000 Received: from localhost ([127.0.0.1]:32804 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pAxQJ-0007PO-MS for submit@debbugs.gnu.org; Thu, 29 Dec 2022 13:14:36 -0500 Received: from mout02.posteo.de ([185.67.36.66]:58729) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pAxQB-0007OH-UO for 52555@debbugs.gnu.org; Thu, 29 Dec 2022 13:14:29 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 6ECD92401BC for <52555@debbugs.gnu.org>; Thu, 29 Dec 2022 19:14:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1672337662; bh=uHwlg5kIjSso0T2R2trMFAAlm0ymvpLunCNwcfsNJy8=; h=From:To:Cc:Subject:Date:From; b=f38MZYaBgd5YNNv18miJEWnShK3EJs5B0CbbFOj9w4nqv9rTNVhBpExcFgZvrT6B0 UFY+xOV6pYBdM3e2WxrZCTdGbGSzi19ov2hs+JTD6XaakFlykMD2os6btN1z91ugsL J1QxQ10LrBCdpMrxVOXX3DJQ+Yby1Y70bupb6fkHixnSn+EbRZcoXj43lUuoictbew VPI/mOVnTMFAIUl62tzromgjAhLdlMO4wCpU/VYhzz196YXi2awwrXU6ZA744NwuH4 7W8P34QUq0e5jkAE2SNdzAdC25hV6W7hrxATWjgvToPQv5wzWOa5IMzAUDOiCPTgIj 7/Li8N4ZNeeBg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Njc3d6jzwz6tmY; Thu, 29 Dec 2022 19:14:21 +0100 (CET) From: pukkamustard Date: Thu, 29 Dec 2022 18:13:21 +0000 Message-Id: <20221229181327.758-3-pukkamustard@posteo.net> In-Reply-To: <20221229181327.758-1-pukkamustard@posteo.net> References: <20221229181327.758-1-pukkamustard@posteo.net> 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/eris.scm: New file. * guix/eris/fs-store.scm: New file. * Makefile.am (MODULES): Add new files. * guix/scripts/publish.scm (bake-narinfo+nar): Use guix-eris-block-reducer. --- Makefile.am | 2 ++ guix/eris.scm | 36 +++++++++++++++++++++ guix/eris/fs-store.scm | 67 ++++++++++++++++++++++++++++++++++++++++ guix/scripts/publish.scm | 14 +++++---- 4 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 guix/eris.scm create mode 100644 guix/eris/fs-store.scm diff --git a/Makefile.am b/Makefile.am index b54288c0fc..c549fc8580 100644 --- a/Makefile.am +++ b/Makefile.am @@ -132,6 +132,8 @@ MODULES = \ guix/least-authority.scm \ guix/read-print.scm \ guix/ipfs.scm \ + guix/eris.scm \ + guix/eris/fs-store.scm \ guix/platform.scm \ guix/platforms/arm.scm \ guix/platforms/mips.scm \ diff --git a/guix/eris.scm b/guix/eris.scm new file mode 100644 index 0000000000..29d5e7b1db --- /dev/null +++ b/guix/eris.scm @@ -0,0 +1,36 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 pukkamustard +;;; +;;; 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 . + +(define-module (guix eris) + #:use-module (eris) + + #:use-module (guix config) + #:use-module (guix eris fs-store) + + #:export (guix-eris-block-reducer + + %eris-block-store-directory)) + +(define %eris-block-store-directory + (make-parameter + (or (getenv "GUIX_ERIS_BLOCK_STORE_DIRECTORY") + (string-append %state-directory "/eris")))) + +(define (guix-eris-block-reducer) + "Returns a block reducer that stores blocks of ERIS encoded content." + (eris-fs-store-reducer (%eris-block-store-directory))) diff --git a/guix/eris/fs-store.scm b/guix/eris/fs-store.scm new file mode 100644 index 0000000000..2ef7607988 --- /dev/null +++ b/guix/eris/fs-store.scm @@ -0,0 +1,67 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 pukkamustard +;;; +;;; 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 . + +(define-module (guix eris fs-store) + #:use-module (rnrs io ports) + #:use-module (guix build utils) ; for mkdir-p + #:use-module (eris utils base32) + + #:export (eris-fs-store-reducer + eris-fs-store-ref)) + +;;; Commentary: +;;; +;;; This module provides a file-system based store of ERIS encoded blocks. +;;; +;;; Code: + +(define (eris-fs-store-reducer store-directory) + (case-lambda + (() (mkdir-p store-directory)) + + ((result) result) + + ((_ ref-block) + (let* ((ref (car ref-block)) + (b32 (base32-encode ref)) + (pre (substring b32 0 2)) + (suf (substring b32 2)) + (pre-dir (string-append store-directory "/" pre)) + (path (string-append pre-dir "/" suf)) + (block (cdr ref-block))) + + (mkdir-p pre-dir) + + (unless (file-exists? path) + (call-with-output-file path + (lambda (port) (put-bytevector port block)) + #:binary #t)) + + #t)))) + +(define (eris-fs-store-ref store-directory) + (lambda (ref) + (let* ((b32 (base32-encode ref)) + (pre (substring b32 0 2)) + (suf (substring b32 2)) + (path (string-append store-directory "/" pre "/" suf))) + (if (file-exists? path) + (call-with-input-file path + (lambda (port) (get-bytevector-all port)) + #:binary #t) + #f)))) diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index 76b5a429f4..7f14e4d4d4 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -52,6 +52,7 @@ (define-module (guix scripts publish) #:use-module (guix base64) #:use-module (guix config) #:use-module (guix derivations) + #:use-module (guix eris) #:use-module (gcrypt hash) #:use-module (guix pki) #:use-module (gcrypt pk-crypto) @@ -647,12 +648,13 @@ (define (eris-encode-nar compressions) (and stat (call-with-input-file nar (lambda (port) - (let ((eris-urn _ - (eris-encode port - #:block-size 'large - #:block-reducer rcount - #:convergence-secret - %null-convergence-secret))) + (let ((eris-urn + _ (eris-encode port + #:block-size 'large + #:block-reducer + (guix-eris-block-reducer) + #:convergence-secret + %null-convergence-secret))) eris-urn))))))) (let ((compression (actual-compressions item compressions)))