summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 00000000000..4ba0197b4fa
--- /dev/null
+++ b/guix/build/gx.scm
@@ -0,0 +1,60 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (guix build gx)
20 #:use-module (guix build utils)
21 #:use-module (ice-9 popen)
22 #:export (gx-fetch))
23
24;;; Commentary:
25;;;
26;;; This is the build-side support code of (guix gx-download). It allows a
27;;; gx hash to be fetched.
28;;;
29;;; Code:
30
31(define* (gx-fetch hash directory
32 #:key (gx-command "gx"))
33 "Fetch IPFS HASH into DIRECTORY. HASH must be a valid IPFS hash.
34Return #t on success, #f otherwise."
35
36 (mkdir-p directory)
37
38 (with-directory-excursion directory
39 ;; TODO: Silence verbose output.
40
41 ;; Initialization is interactive, but we can shut it up by piping it to
42 ;; nothing.
43 (let ((port (open-pipe* OPEN_WRITE gx-command "init")))
44 (display "\n" port)
45 (if (not (eqv? 0 (status:exit-val (close-pipe port))))
46 (error "Cannot initialize gx package")))
47
48 ;; Fetch to the "vendor" directory.
49 (let ((port (open-pipe* OPEN_WRITE gx-command "import" "--local" hash)))
50 (display "N\n" port)
51 (if (not (eqv? 0 (status:exit-val (close-pipe port))))
52 (error "Cannot import gx package")))
53
54 (delete-file "package.json")
55 (mkdir-p "gx/ipfs")
56 (rename-file (string-append "vendor/gx/ipfs/" hash) (string-append "gx/ipfs/" hash))
57 (delete-file-recursively "vendor")
58 #t))
59
60;;; gx.scm ends here
diff --git a/guix/gx-download.scm b/guix/gx-download.scm
new file mode 100644
index 00000000000..4acf7bf61d8
--- /dev/null
+++ b/guix/gx-download.scm
@@ -0,0 +1,131 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (guix gx-download)
20 #:use-module (guix gexp)
21 #:use-module (guix store)
22 #:use-module (guix monads)
23 #:use-module (guix records)
24 #:use-module (guix packages)
25 #:use-module (guix utils)
26 #:use-module (guix modules)
27 ;; #:autoload (guix build-system gnu) (standard-packages)
28 #:use-module (ice-9 match)
29 #:use-module (ice-9 vlist)
30 #:use-module (srfi srfi-1)
31 #:export (gx-reference
32 gx-reference?
33 gx-reference-hash
34
35 gx-fetch
36 gx-version
37 gx-file-name))
38
39;;; Commentary:
40;;;
41;;; An <origin> method that uses gx to fetch a specific hash over IPFS.
42;;; See https://github.com/whyrusleeping/gx.
43;;; The hash is specified with a <gx-reference> object.
44;;;
45;;; Code:
46
47(define-record-type* <gx-reference>
48 gx-reference make-gx-reference
49 gx-reference?
50 (hash gx-reference-hash))
51
52(define (gx-package)
53 "Return the default gx package."
54 (let ((distro (resolve-interface '(gnu packages ipfs))))
55 (module-ref distro 'gx)))
56
57(define* (gx-fetch ref hash-algo hash
58 #:optional name
59 #:key (system (%current-system)) (guile (default-guile))
60 (gx (gx-package)))
61 "Return a fixed-output derivation that fetches REF, a <gx-reference>
62object. The output is expected to have recursive hash HASH of type
63HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
64 ;; (define inputs
65 ;; ;; When doing 'git clone --recursive', we need sed, grep, etc. to be
66 ;; ;; available so that 'git submodule' works.
67 ;; ;; (if (git-reference-recursive? ref)
68 ;; ;; (standard-packages)
69 ;; ;; '())
70 ;; )
71
72 ;; (define zlib
73 ;; (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
74
75 ;; (define config.scm
76 ;; (scheme-file "config.scm"
77 ;; #~(begin
78 ;; (define-module (guix config)
79 ;; #:export (%libz))
80
81 ;; (define %libz
82 ;; #+(file-append zlib "/lib/libz")))))
83
84 ;; (define modules
85 ;; (cons `((guix config) => ,config.scm)
86 ;; (delete '(guix config)
87 ;; (source-module-closure '((guix build git)
88 ;; (guix build utils)
89 ;; (guix build download-nar))))))
90
91 (define build
92 (with-imported-modules '((guix build gx)
93 (guix build utils))
94 #~(begin
95 (use-modules (guix build gx)
96 ;; (guix build utils)
97 ;; (guix build download-nar)
98 ;; (ice-9 match)
99 )
100
101 ;; The 'git submodule' commands expects Coreutils, sed,
102 ;; grep, etc. to be in $PATH.
103 ;; (set-path-environment-variable "PATH" '("bin")
104 ;; (match '#+inputs
105 ;; (((names dirs outputs ...) ...)
106 ;; dirs)))
107
108 (or (gx-fetch '#$(gx-reference-hash ref)
109 #$output
110 #:gx-command (string-append #+gx "/bin/gx"))
111 ;; (download-nar #$output)
112 ))))
113
114 (mlet %store-monad ((guile (package->derivation guile system)))
115 (gexp->derivation (or name "gx-checkout") build
116 #:system system
117 #:local-build? #t
118 #:hash-algo hash-algo
119 #:hash hash
120 #:recursive? #t
121 #:guile-for-build guile)))
122
123(define (gx-version version revision hash)
124 "Return the version string for packages using gx-download."
125 (string-append version "-" revision "." (string-take hash 7)))
126
127(define (gx-file-name name version)
128 "Return the file-name for packages using gx-download."
129 (string-append name "-" version "-checkout"))
130
131;;; gx-download.scm ends here