summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Neidhardt <mail@ambrevar.xyz>2018-10-17 18:56:38 +0200
committerPierre Neidhardt <mail@ambrevar.xyz>2018-10-24 12:30:42 +0200
commit376a9fa08fa3ffb5a5ab0980acf75abdfc797486 (patch)
tree40249fc0d093b3f8e5020e6fa4bf947fa2ebd05c
parentb90dc0641033db1273a392faea61f82e9aeb1e85 (diff)
gx-download (DRAFT)origin/wip-ipfs2
-rw-r--r--guix/build/gx.scm60
-rw-r--r--guix/gx-download.scm131
2 files changed, 191 insertions, 0 deletions
diff --git a/guix/build/gx.scm b/guix/build/gx.scm
new file mode 100644
index 0000000000..4ba0197b4f
--- /dev/null
+++ b/guix/build/gx.scm
@@ -0,0 +1,60 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 "gx/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 0000000000..4acf7bf61d
--- /dev/null
+++ b/guix/gx-download.scm
@@ -0,0 +1,131 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 <origin> method that uses gx to fetch a specific hash over IPFS.
+;;; See https://github.com/whyrusleeping/gx.
+;;; The hash is specified with a <gx-reference> object.
+;;;
+;;; Code:
+
+(define-record-type* <gx-reference>
+ 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 <gx-reference>
+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) => ,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