From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id stqjBE6JlF89OgAA0tVLHw (envelope-from ) for ; Sat, 24 Oct 2020 20:06:38 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 6KViAE6JlF9aSwAAB5/wlQ (envelope-from ) for ; Sat, 24 Oct 2020 20:06:38 +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 B8AD29401DD for ; Sat, 24 Oct 2020 20:06:36 +0000 (UTC) Received: from localhost ([::1]:53146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kWPoB-0002W7-FV for larch@yhetil.org; Sat, 24 Oct 2020 16:06:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kWPd0-0002V2-7C for guix-patches@gnu.org; Sat, 24 Oct 2020 15:55:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kWPcz-0008CY-Ry for guix-patches@gnu.org; Sat, 24 Oct 2020 15:55:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kWPcz-0002hw-R4 for guix-patches@gnu.org; Sat, 24 Oct 2020 15:55:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#44199] [PATCH 1/1] guix: Add (guix gnunet-download). References: <5c72bcb9c86934deda97d952eb5cd459e615b313.camel@student.kuleuven.be> In-Reply-To: <5c72bcb9c86934deda97d952eb5cd459e615b313.camel@student.kuleuven.be> Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 24 Oct 2020 19:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44199 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44199@debbugs.gnu.org Received: via spool by 44199-submit@debbugs.gnu.org id=B44199.160356926710361 (code B ref 44199); Sat, 24 Oct 2020 19:55:01 +0000 Received: (at 44199) by debbugs.gnu.org; 24 Oct 2020 19:54:27 +0000 Received: from localhost ([127.0.0.1]:35222 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kWPcK-0002gv-5S for submit@debbugs.gnu.org; Sat, 24 Oct 2020 15:54:26 -0400 Received: from rhcavuit02.kulnet.kuleuven.be ([134.58.240.130]:59618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kWPcH-0002gh-5x for 44199@debbugs.gnu.org; Sat, 24 Oct 2020 15:54:18 -0400 X-KULeuven-Envelope-From: maxime.devos@student.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 0F1DD120333.A0C73 X-KULeuven-Information: Katholieke Universiteit Leuven Received: from icts-p-smtps-1.cc.kuleuven.be (icts-p-smtps-1e.kulnet.kuleuven.be [134.58.240.33]) by rhcavuit02.kulnet.kuleuven.be (Postfix) with ESMTP id 0F1DD120333 for <44199@debbugs.gnu.org>; Sat, 24 Oct 2020 21:54:13 +0200 (CEST) Received: from butterfly.local (178-119-10-153.access.telenet.be [178.119.10.153]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by icts-p-smtps-1.cc.kuleuven.be (Postfix) with ESMTPSA id D18C940B2 for <44199@debbugs.gnu.org>; Sat, 24 Oct 2020 21:54:12 +0200 (CEST) Message-ID: X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Maxime Devos Date: Sat, 24 Oct 2020 21:54:12 +0200 Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-y/0cAtxQWHh0glfHeTmu" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 X-Spam-Score: -0.3 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: 1.0 (+) X-Mailman-Approved-At: Sat, 24 Oct 2020 16:06:20 -0400 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.11 X-TUID: 8E2UgyNIZAMr --=-y/0cAtxQWHh0glfHeTmu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This method allows fetching sources over GNUnet's file-sharing system, presuming GNUnet has been configured on the local system. Missing: - time-outs - fetching substitutes over GNUnet - fallback to legacy non-P2P servers - GNUnet system service * guix/gnunet-download.scm, guix/build/gnunet.scm: New files. * Makefile.am (MODULES): Add them. * doc/guix.texi (Defining Packages): Document gnunet-fetch. --- Makefile.am | 2 + doc/guix.texi | 7 +++ guix/build/gnunet.scm | 113 +++++++++++++++++++++++++++++++++++++++ guix/gnunet-download.scm | 89 ++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+) create mode 100644 guix/build/gnunet.scm create mode 100644 guix/gnunet-download.scm diff --git a/Makefile.am b/Makefile.am index a75d9c1ffc..f046020017 100644 --- a/Makefile.am +++ b/Makefile.am @@ -94,6 +94,7 @@ MODULES =3D \ guix/android-repo-download.scm \ guix/bzr-download.scm \ guix/git-download.scm \ + guix/gnunet-download.scm \ guix/hg-download.scm \ guix/swh.scm \ guix/monads.scm \ @@ -187,6 +188,7 @@ MODULES =3D \ guix/build/bzr.scm \ guix/build/copy-build-system.scm \ guix/build/git.scm \ + guix/build/gnunet.scm \ guix/build/hg.scm \ guix/build/glib-or-gtk-build-system.scm \ guix/build/gnu-bootstrap.scm \ diff --git a/doc/guix.texi b/doc/guix.texi index 8514dfe86f..8a5f0559f3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -81,6 +81,7 @@ Copyright @copyright{} 2020 R Veera Kumar@* Copyright @copyright{} 2020 Pierre Langlois@* Copyright @copyright{} 2020 pinoaffe@* Copyright @copyright{} 2020 Andr=C3=A9 Batista@* +Copyright @copyright{} 2020 Maxime Devos@* =20 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -6595,6 +6596,12 @@ specified in the @code{uri} field as a @code{git-reference} object; a (url "https://git.savannah.gnu.org/git/hello.git") (commit "v2.10")) @end lisp + +@vindex gnunet-fetch +@item @var{gnunet-feth} from @code{(guix gnunet-download)} +download a file specified by its GNUnet chk-URI. To use +this method, the GNUnet file-sharing daemon has to be configured +to accept connections from the loopback networking interface. @end table =20 @item @code{sha256} diff --git a/guix/build/gnunet.scm b/guix/build/gnunet.scm new file mode 100644 index 0000000000..3cee161cc2 --- /dev/null +++ b/guix/build/gnunet.scm @@ -0,0 +1,113 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2016 Ricardo Wurmus +;;; Copyright =C2=A9 2018 Mark H Weaver +;;; Copyright =C2=A9 2018 Bj=C3=B6rn H=C3=B6fling +;;; Copyright =C2=A9 2020 Simon Tournier +;;; Copyright =C2=A9 2020 Maxime Devos +;;; +;;; 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 gnunet) + #:use-module (guix build utils) + #:use-module (srfi srfi-34) + #:use-module (ice-9 format) + #:use-module (rnrs io ports) + #:export (gnunet-fetch)) + +;;; Commentary: +;;; +;;; This is the build-side support code of (guix gnunet-download). It=20 allows +;;; files of which the GNUnet chk-URI is known to be downloaded from the GNUnet +;;; file-sharing system. The code has been derived from (guix build hg). +;;; +;;; Code: + +;; Copied from (guix utils) +(define (call-with-temporary-output-file proc) + "Call PROC with a name of a temporary file and open output port to that +file; close the file and delete it when leaving the dynamic extent of this +call." + (let* ((directory (or (getenv "TMPDIR") "/tmp")) + (template (string-append directory "/guix-file.XXXXXX")) + (out (mkstemp! template))) + (dynamic-wind + (lambda () + #t) + (lambda () + (proc template out)) + (lambda () + (false-if-exception (close out)) + (false-if-exception (delete-file template)))))) + +(define (gnunet-fs-up? port) + "#t if the GNUnet FS daemon seems to be up at @var{port}, #f otherwise" + (let ((s (socket PF_INET SOCK_STREAM 0))) + (catch 'system-error + (lambda () + (connect s AF_INET INADDR_LOOPBACK port) + (close-port s) + #t) + (lambda (tag function msg msg+ errno) + (close-port s) + (if (and (equal? function "connect") + (equal? errno (list ECONNREFUSED))) + #f + (throw tag function msg msg+ errno)))))) + +;; TODO: gnunet directories, time-outs, perhaps use guile-gnunet +(define* (gnunet-fetch uri file + #:key (gnunet-download-command "gnunet- download")) + "Fetch a file identified by a GNUnet chk-URI @var{URI} into @var{file}. +@var{uri} must not be a directory. Return #t on success, #f otherwise." + (guard (c ((invoke-error? c) + (format (current-error-port) + "gnunet-fetch: '~a~{ ~a~}' failed with exit code ~a~%" + (invoke-error-program c) + (invoke-error-arguments c) + (or (invoke-error-exit-status c) + (invoke-error-stop-signal c) + (invoke-error-term-signal c))) + (false-if-exception (delete-file-recursively file)) + #f)) + (define port + (let ((p (getenv "gnunet port"))) + (and p (< 0 (string-length p)) + (string->number p)))) + (define anonymity + (let ((a (getenv "GNUNET_ANONYMITY"))) + (cond ((equal? a "") "1") + ((not a) "1") + (else a)))) + ;; Check if the GNUnet daemon is up, + ;; otherwise gnunet-download might wait forever. + (if (or (not port) (gnunet-fs-up? port)) + (call-with-temporary-output-file + (lambda (config-file-name config-output-port) + ;; Tell gnunet-download how to contact the FS daemon + (display (getenv "gnunet configuration") config-output- port) + (flush-output-port config-output-port) + (invoke gnunet-download-command uri + "-c" config-file-name + "-V" ;; print progress information + "-a" anonymity + "-o" file) + #t)) + (begin + (format (current-error-port) + "gnunet-fetch: file-sharing daemon is down.~%") + #f)))) + +;;; gnunet.scm ends here diff --git a/guix/gnunet-download.scm b/guix/gnunet-download.scm new file mode 100644 index 0000000000..8a825b90ae --- /dev/null +++ b/guix/gnunet-download.scm @@ -0,0 +1,89 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2018 Pierre Neidhardt +;;; Copyright =C2=A9 2020 Maxime Devos +;;; +;;; 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 gnunet-download) + #:use-module (guix packages) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (guix gexp) + #:use-module (ice-9 popen) + #:use-module (ice-9 rdelim) + #:export (gnunet-fetch)) + +;;; An method that uses gnunet-download to fetch a specific hash +;;; the GNUnet file-sharing system. The hash is specified as a GNUnet chk-URI +;;; string. The code has been derived from (guix gx-download). +;;; +;;; Code: + +(define (gnunet-package) + "Return the default GNUnet package." + (let ((distro (resolve-interface '(gnu packages gnunet)))) + (module-ref distro 'gnunet))) + +(define* (gnunet-configuration #:key (gnunet (gnunet-package))) + "Make a configuration file allowing the build process to talk +with the GNUnet FS daemon." + ;; TODO: is it acceptable to assume + ;; the existence of gnunet-config in PATH? + ;; If not, can @var{gnunet} be compiled? + ;; Alternatively, parse .config/gnunet.conf manually. + ;; + ;; TODO: by default, GNUnet uses Unix sockets + ;; instead of IP for IPC. Can we poke a hole + ;; in the build process isolation allowing this + ;; setup? + (let* ((p (open-pipe* OPEN_READ "gnunet-config" "--section" "fs" "- o" "PORT")) + (port (read-line p))) + (close-pipe p) + (values (format #f "[fs]~%PORT =3D ~a\n" port) + port))) + +(define* (gnunet-fetch uri hash-algo hash + #:optional name + #:key (system (%current-system)) (guile (default-guile)) + (gnunet (gnunet-package))) + "Return a fixed-output derivation that fetches @var{uri}, a GNUnet chk-URI +string. The output is expected to have hash @var{hash} of type +@var{hash-algo}. Use @var{name} as the file name, or a generic name if #f." + (define build + (with-imported-modules '((guix build gnunet) + (guix build utils)) + #~(begin + (use-modules (guix build gnunet)) + (or (gnunet-fetch '#$uri + #$output + #:gnunet-download-command + (string-append #+gnunet "/bin/gnunet- download")))))) + (define env-vars + (call-with-values (lambda () (gnunet-configuration #:gnunet gnunet)) + (lambda (configuration port) + `(("gnunet configuration" . ,configuration) + ("gnunet port" . ,port))))) + (mlet %store-monad ((guile (package->derivation guile system))) + (gexp->derivation (or name "gnunet-chk") build + #:system system + #:local-build? #t ;; don't offload downloads + #:hash-algo hash-algo + #:hash hash + #:recursive? #f + #:leaked-env-vars '("GNUNET_ANONYMITY") + #:env-vars env-vars + #:guile-for-build guile))) + +;;; gnunet-download.scm ends here --=-y/0cAtxQWHh0glfHeTmu Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iJcEABYIAD8WIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCX5SGZCEcbWF4aW1lLmRl dm9zQHN0dWRlbnQua3VsZXV2ZW4uYmUACgkQSePuIhkXJe5uAAEArZnvBoDnRG5J FetXk6KkL/uGKiQmc6IBmjP6kqdwD/UA/2dGBa2mzP6UM1mNZcEOnZDHBjFuf4yI PyQFqza+a3YO =O+eh -----END PGP SIGNATURE----- --=-y/0cAtxQWHh0glfHeTmu--