1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (build-self)
22 #:use-module (guix config)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-19)
29 ;;; When loaded, this module returns a monadic procedure of at least one
30 ;;; argument: the source tree to build. It returns a derivation that
33 ;;; This file uses modules provided by the already-installed Guix. Those
34 ;;; modules may be arbitrarily old compared to the version we want to
35 ;;; build. Because of that, it must rely on the smallest set of features
36 ;;; that are likely to be provided by the (guix) and (gnu) modules, and by
37 ;;; Guile itself, forever and ever.
42 ;; The dependencies. Don't refer explicitly to the variables because they
43 ;; could be renamed or shuffled around in modules over time. Conversely,
44 ;; 'find-best-packages-by-name' is expected to always have the same semantics.
47 (first (find-best-packages-by-name "libgcrypt" #f)))
50 (first (find-best-packages-by-name "zlib" #f)))
53 (first (find-best-packages-by-name "gzip" #f)))
56 (first (find-best-packages-by-name "bzip2" #f)))
59 (first (find-best-packages-by-name "xz" #f)))
62 (first (find-best-packages-by-name "guile-json" #f)))
66 ;; The actual build procedure.
68 (define (top-source-directory)
69 "Return the name of the top-level directory of this source tree."
70 (and=> (assoc-ref (current-source-location) 'filename)
72 (string-append (dirname file) "/.."))))
75 (define (date-version-string)
76 "Return the current date and hour in UTC timezone, for use as a poor
77 person's version identifier."
78 ;; XXX: Replace with a Git commit id.
79 (date->string (current-date 0) "~Y~m~d.~H"))
81 ;; The procedure below is our return value.
82 (define* (build source
83 #:key verbose? (version (date-version-string))
86 "Return a derivation that unpacks SOURCE into STORE and compiles Scheme
88 ;; The '%xxxdir' variables were added to (guix config) in July 2016 so we
89 ;; cannot assume that they are defined. Try to guess their value when
90 ;; they're undefined (XXX: we get an incorrect guess when environment
91 ;; variables such as 'NIX_STATE_DIR' are defined!).
93 (if (defined? '%storedir) %storedir %store-directory))
95 (if (defined? '%localstatedir) %localstatedir (dirname %state-directory)))
97 (if (defined? '%sysconfdir) %sysconfdir (dirname %config-directory)))
99 (if (defined? '%sbindir) %sbindir (dirname %guix-register-program)))
103 (use-modules (guix build pull))
105 (let ((json (string-append #$guile-json "/share/guile/site/2.0")))
106 (set! %load-path (cons json %load-path))
107 (set! %load-compiled-path (cons json %load-compiled-path)))
109 (build-guix #$output #$source
112 #:storedir #$storedir
113 #:localstatedir #$localstatedir
114 #:sysconfdir #$sysconfdir
117 #:package-name #$%guix-package-name
118 #:package-version #$version
119 #:bug-report-address #$%guix-bug-report-address
120 #:home-page-url #$%guix-home-page-url
122 #:libgcrypt #$libgcrypt
128 ;; XXX: This is not perfect, enabling VERBOSE? means
129 ;; building a different derivation.
130 #:debug-port (if #$verbose?
132 (%make-void-port "w")))))
134 (gexp->derivation "guix-latest" builder
135 #:modules '((guix build pull)
138 ;; Arrange so that our own (guix build …) modules are
140 #:module-path (list (top-source-directory))))
142 ;; This file is loaded by 'guix pull'; return it the build procedure.
146 ;; eval: (put 'with-load-path 'scheme-indent-function 1)
149 ;;; build-self.scm ends here