From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre Neidhardt Subject: Re: Guix & IPFS Date: Wed, 24 Oct 2018 15:58:41 +0200 Message-ID: <87efcfxx7y.fsf@ambrevar.xyz> References: <87r2grk5dj.fsf@ambrevar.xyz> <87lg6zfr20.fsf@gnu.org> <87lg6zjxwt.fsf@ambrevar.xyz> <20181016162747.GB25057@jasmine.lan> <87r2goecf5.fsf@ambrevar.xyz> <87in1ygi94.fsf@gnu.org> <87va5yoxa0.fsf@ambrevar.xyz> <87h8hb32mf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFJgS-0005OZ-8B for guix-devel@gnu.org; Wed, 24 Oct 2018 09:58:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFJgM-0004hY-St for guix-devel@gnu.org; Wed, 24 Oct 2018 09:58:51 -0400 In-reply-to: <87h8hb32mf.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: Guix-devel --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > To be precise, builders of fixed-output derivations (derivations for > which the hash of the result is known in advance) have network access. Oh, I did not know this detail. Thanks for pointing it out! > How did you define =E2=80=98gx-fetch=E2=80=99? It's on the wip-ipfs2 branch. Find the (broken) patch attached. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-gx-download-DRAFT.patch Content-Transfer-Encoding: quoted-printable From=20376a9fa08fa3ffb5a5ab0980acf75abdfc797486 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Wed, 17 Oct 2018 18:56:38 +0200 Subject: [PATCH] gx-download (DRAFT) =2D-- guix/build/gx.scm | 60 ++++++++++++++++++++ guix/gx-download.scm | 131 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 guix/build/gx.scm create mode 100644 guix/gx-download.scm diff --git a/guix/build/gx.scm b/guix/build/gx.scm new file mode 100644 index 000000000..4ba0197b4 =2D-- /dev/null +++ b/guix/build/gx.scm @@ -0,0 +1,60 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2018 Pierre Neidhardt +;;; +;;; 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 build gx) + #:use-module (guix build utils) + #:use-module (ice-9 popen) + #:export (gx-fetch)) + +;;; Commentary: +;;; +;;; This is the build-side support code of (guix gx-download). It allows a +;;; gx hash to be fetched. +;;; +;;; Code: + +(define* (gx-fetch hash directory + #:key (gx-command "gx")) + "Fetch IPFS HASH into DIRECTORY. HASH must be a valid IPFS hash. +Return #t on success, #f otherwise." + + (mkdir-p directory) + + (with-directory-excursion directory + ;; TODO: Silence verbose output. + + ;; Initialization is interactive, but we can shut it up by piping it to + ;; nothing. + (let ((port (open-pipe* OPEN_WRITE gx-command "init"))) + (display "\n" port) + (if (not (eqv? 0 (status:exit-val (close-pipe port)))) + (error "Cannot initialize gx package"))) + + ;; Fetch to the "vendor" directory. + (let ((port (open-pipe* OPEN_WRITE gx-command "import" "--local" hash)= )) + (display "N\n" port) + (if (not (eqv? 0 (status:exit-val (close-pipe port)))) + (error "Cannot import gx package"))) + + (delete-file "package.json") + (mkdir-p "gx/ipfs") + (rename-file (string-append "vendor/gx/ipfs/" hash) (string-append "g= x/ipfs/" hash)) + (delete-file-recursively "vendor") + #t)) + +;;; gx.scm ends here diff --git a/guix/gx-download.scm b/guix/gx-download.scm new file mode 100644 index 000000000..4acf7bf61 =2D-- /dev/null +++ b/guix/gx-download.scm @@ -0,0 +1,131 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2018 Pierre Neidhardt +;;; +;;; 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 gx-download) + #:use-module (guix gexp) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (guix records) + #:use-module (guix packages) + #:use-module (guix utils) + #:use-module (guix modules) + ;; #:autoload (guix build-system gnu) (standard-packages) + #:use-module (ice-9 match) + #:use-module (ice-9 vlist) + #:use-module (srfi srfi-1) + #:export (gx-reference + gx-reference? + gx-reference-hash + + gx-fetch + gx-version + gx-file-name)) + +;;; Commentary: +;;; +;;; An method that uses gx to fetch a specific hash over IPFS. +;;; See https://github.com/whyrusleeping/gx. +;;; The hash is specified with a object. +;;; +;;; Code: + +(define-record-type* + gx-reference make-gx-reference + gx-reference? + (hash gx-reference-hash)) + +(define (gx-package) + "Return the default gx package." + (let ((distro (resolve-interface '(gnu packages ipfs)))) + (module-ref distro 'gx))) + +(define* (gx-fetch ref hash-algo hash + #:optional name + #:key (system (%current-system)) (guile (default-guile= )) + (gx (gx-package))) + "Return a fixed-output derivation that fetches REF, a +object. The output is expected to have recursive hash HASH of type +HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." + ;; (define inputs + ;; ;; When doing 'git clone --recursive', we need sed, grep, etc. to be + ;; ;; available so that 'git submodule' works. + ;; ;; (if (git-reference-recursive? ref) + ;; ;; (standard-packages) + ;; ;; '()) + ;; ) + + ;; (define zlib + ;; (module-ref (resolve-interface '(gnu packages compression)) 'zlib)) + + ;; (define config.scm + ;; (scheme-file "config.scm" + ;; #~(begin + ;; (define-module (guix config) + ;; #:export (%libz)) + + ;; (define %libz + ;; #+(file-append zlib "/lib/libz"))))) + + ;; (define modules + ;; (cons `((guix config) =3D> ,config.scm) + ;; (delete '(guix config) + ;; (source-module-closure '((guix build git) + ;; (guix build utils) + ;; (guix build download-nar))))= )) + + (define build + (with-imported-modules '((guix build gx) + (guix build utils)) + #~(begin + (use-modules (guix build gx) + ;; (guix build utils) + ;; (guix build download-nar) + ;; (ice-9 match) + ) + + ;; The 'git submodule' commands expects Coreutils, sed, + ;; grep, etc. to be in $PATH. + ;; (set-path-environment-variable "PATH" '("bin") + ;; (match '#+inputs + ;; (((names dirs outputs ...) .= ..) + ;; dirs))) + + (or (gx-fetch '#$(gx-reference-hash ref) + #$output + #:gx-command (string-append #+gx "/bin/gx")) + ;; (download-nar #$output) + )))) + + (mlet %store-monad ((guile (package->derivation guile system))) + (gexp->derivation (or name "gx-checkout") build + #:system system + #:local-build? #t + #:hash-algo hash-algo + #:hash hash + #:recursive? #t + #:guile-for-build guile))) + +(define (gx-version version revision hash) + "Return the version string for packages using gx-download." + (string-append version "-" revision "." (string-take hash 7))) + +(define (gx-file-name name version) + "Return the file-name for packages using gx-download." + (string-append name "-" version "-checkout")) + +;;; gx-download.scm ends here =2D-=20 2.19.1 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlvQepEACgkQm9z0l6S7 zH+kcwf/XpA6wrgCgedRQhzF2Ydu2vs+39acAWM0lOv5aM82vvvR8LnjTNPnaX93 V98d6UUUM05qU+NnJZcAAwsOvC/t/fGxygY/piERhbgDC0B6nuMxC25GpkobP1Yr NzqzUrd3usrjKP3vB/yaT0x0YYEgEyE3MTcnVcCeYX1y3zTQjCPh3iG1u6xrxil/ PY0tbxjDedNFXnu5Mtw3klzQzAakFb2gdV2FCPzGXUVZjaIPHkInDuRHylBmhQaP OVOcLzG8IB0vfSSXlUEFyNL/LmP2tYEl/XZt+D2mqm27r+lyLMd+2n2QGCxFlvoo xlnVO5/gkIJy5X2E0faoctBFLdAmfA== =pIs4 -----END PGP SIGNATURE----- --==-=-=--