pull: Install (guix config) module to override the user's one.
[jackhill/guix/guix.git] / build-aux / build-self.scm
CommitLineData
f81ac34d 1;;; GNU Guix --- Functional package management for GNU
13cee334 2;;; Copyright © 2014, 2016 Ludovic Courtès <ludo@gnu.org>
f81ac34d
LC
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)
13cee334 22 #:use-module (guix config)
f81ac34d
LC
23 #:use-module (srfi srfi-1)
24 #:export (build))
25
26;;; Commentary:
27;;;
28;;; When loaded, this module returns a monadic procedure of at least one
29;;; argument: the source tree to build. It returns a derivation that
30;;; builds it.
31;;;
32;;; This file uses modules provided by the already-installed Guix. Those
33;;; modules may be arbitrarily old compared to the version we want to
34;;; build. Because of that, it must rely on the smallest set of features
35;;; that are likely to be provided by the (guix) and (gnu) modules, and by
36;;; Guile itself, forever and ever.
37;;;
38;;; Code:
39
40\f
41;; The dependencies. Don't refer explicitly to the variables because they
42;; could be renamed or shuffled around in modules over time. Conversely,
43;; 'find-best-packages-by-name' is expected to always have the same semantics.
44
45(define libgcrypt
46 (first (find-best-packages-by-name "libgcrypt" #f)))
47
13cee334
LC
48(define zlib
49 (first (find-best-packages-by-name "zlib" #f)))
50
51(define gzip
52 (first (find-best-packages-by-name "gzip" #f)))
53
54(define bzip2
55 (first (find-best-packages-by-name "bzip2" #f)))
56
57(define xz
58 (first (find-best-packages-by-name "xz" #f)))
59
f81ac34d
LC
60(define guile-json
61 (first (find-best-packages-by-name "guile-json" #f)))
62
63
64\f
65;; The actual build procedure.
66
67(define (top-source-directory)
68 "Return the name of the top-level directory of this source tree."
69 (and=> (assoc-ref (current-source-location) 'filename)
70 (lambda (file)
71 (string-append (dirname file) "/.."))))
72
73;; The procedure below is our return value.
74(define* (build source #:key verbose?
75 #:allow-other-keys
76 #:rest rest)
77 "Return a derivation that unpacks SOURCE into STORE and compiles Scheme
78files."
13cee334
LC
79 ;; The '%xxxdir' variables were added to (guix config) in July 2016 so we
80 ;; cannot assume that they are defined. Try to guess their value when
81 ;; they're undefined (XXX: we get an incorrect guess when environment
82 ;; variables such as 'NIX_STATE_DIR' are defined!).
83 (define storedir
84 (if (defined? '%storedir) %storedir %store-directory))
85 (define localstatedir
86 (if (defined? '%localstatedir) %localstatedir (dirname %state-directory)))
87 (define sysconfdir
88 (if (defined? '%sysconfdir) %sysconfdir (dirname %config-directory)))
89 (define sbindir
90 (if (defined? '%sbindir) %sbindir (dirname %guix-register-program)))
91
f81ac34d
LC
92 (define builder
93 #~(begin
94 (use-modules (guix build pull))
95
96 (let ((json (string-append #$guile-json "/share/guile/site/2.0")))
97 (set! %load-path (cons json %load-path))
98 (set! %load-compiled-path (cons json %load-compiled-path)))
99
100 (build-guix #$output #$source
101
13cee334
LC
102 #:system #$%system
103 #:storedir #$storedir
104 #:localstatedir #$localstatedir
105 #:sysconfdir #$sysconfdir
106 #:sbindir #$sbindir
107
108 #:package-name #$%guix-package-name
109 #:package-version #$%guix-version
110 #:bug-report-address #$%guix-bug-report-address
111 #:home-page-url #$%guix-home-page-url
112
113 #:libgcrypt #$libgcrypt
114 #:zlib #$zlib
115 #:gzip #$gzip
116 #:bzip2 #$bzip2
117 #:xz #$xz
118
f81ac34d
LC
119 ;; XXX: This is not perfect, enabling VERBOSE? means
120 ;; building a different derivation.
121 #:debug-port (if #$verbose?
122 (current-error-port)
13cee334 123 (%make-void-port "w")))))
f81ac34d
LC
124
125 (gexp->derivation "guix-latest" builder
126 #:modules '((guix build pull)
127 (guix build utils))
128
129 ;; Arrange so that our own (guix build …) modules are
130 ;; used.
131 #:module-path (list (top-source-directory))))
132
133;; This file is loaded by 'guix pull'; return it the build procedure.
134build
135
136;; Local Variables:
137;; eval: (put 'with-load-path 'scheme-indent-function 1)
138;; End:
139
140;;; build-self.scm ends here