Add (guix zlib).
[jackhill/guix/guix.git] / build-aux / build-self.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
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 (build-self)
20 #:use-module (gnu)
21 #:use-module (guix)
22 #:use-module (srfi srfi-1)
23 #:export (build))
24
25 ;;; Commentary:
26 ;;;
27 ;;; When loaded, this module returns a monadic procedure of at least one
28 ;;; argument: the source tree to build. It returns a derivation that
29 ;;; builds it.
30 ;;;
31 ;;; This file uses modules provided by the already-installed Guix. Those
32 ;;; modules may be arbitrarily old compared to the version we want to
33 ;;; build. Because of that, it must rely on the smallest set of features
34 ;;; that are likely to be provided by the (guix) and (gnu) modules, and by
35 ;;; Guile itself, forever and ever.
36 ;;;
37 ;;; Code:
38
39 \f
40 ;; The dependencies. Don't refer explicitly to the variables because they
41 ;; could be renamed or shuffled around in modules over time. Conversely,
42 ;; 'find-best-packages-by-name' is expected to always have the same semantics.
43
44 (define libgcrypt
45 (first (find-best-packages-by-name "libgcrypt" #f)))
46
47 (define guile-json
48 (first (find-best-packages-by-name "guile-json" #f)))
49
50
51 \f
52 ;; The actual build procedure.
53
54 (define (top-source-directory)
55 "Return the name of the top-level directory of this source tree."
56 (and=> (assoc-ref (current-source-location) 'filename)
57 (lambda (file)
58 (string-append (dirname file) "/.."))))
59
60 ;; The procedure below is our return value.
61 (define* (build source #:key verbose?
62 #:allow-other-keys
63 #:rest rest)
64 "Return a derivation that unpacks SOURCE into STORE and compiles Scheme
65 files."
66 (define builder
67 #~(begin
68 (use-modules (guix build pull))
69
70 (let ((json (string-append #$guile-json "/share/guile/site/2.0")))
71 (set! %load-path (cons json %load-path))
72 (set! %load-compiled-path (cons json %load-compiled-path)))
73
74 (build-guix #$output #$source
75
76 ;; XXX: This is not perfect, enabling VERBOSE? means
77 ;; building a different derivation.
78 #:debug-port (if #$verbose?
79 (current-error-port)
80 (%make-void-port "w"))
81 #:gcrypt #$libgcrypt)))
82
83 (gexp->derivation "guix-latest" builder
84 #:modules '((guix build pull)
85 (guix build utils))
86
87 ;; Arrange so that our own (guix build …) modules are
88 ;; used.
89 #:module-path (list (top-source-directory))))
90
91 ;; This file is loaded by 'guix pull'; return it the build procedure.
92 build
93
94 ;; Local Variables:
95 ;; eval: (put 'with-load-path 'scheme-indent-function 1)
96 ;; End:
97
98 ;;; build-self.scm ends here