gnu: openssh: Enable kerberos features.
[jackhill/guix/guix.git] / build-aux / build-self.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2016 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 (guix config)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-19)
25 #:export (build))
26
27 ;;; Commentary:
28 ;;;
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
31 ;;; builds it.
32 ;;;
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.
38 ;;;
39 ;;; Code:
40
41 \f
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.
45
46 (define libgcrypt
47 (first (find-best-packages-by-name "libgcrypt" #f)))
48
49 (define zlib
50 (first (find-best-packages-by-name "zlib" #f)))
51
52 (define gzip
53 (first (find-best-packages-by-name "gzip" #f)))
54
55 (define bzip2
56 (first (find-best-packages-by-name "bzip2" #f)))
57
58 (define xz
59 (first (find-best-packages-by-name "xz" #f)))
60
61 (define guile-json
62 (first (find-best-packages-by-name "guile-json" #f)))
63
64
65 \f
66 ;; The actual build procedure.
67
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)
71 (lambda (file)
72 (string-append (dirname file) "/.."))))
73
74
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"))
80
81 ;; The procedure below is our return value.
82 (define* (build source
83 #:key verbose? (version (date-version-string))
84 #:allow-other-keys
85 #:rest rest)
86 "Return a derivation that unpacks SOURCE into STORE and compiles Scheme
87 files."
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!).
92 (define storedir
93 (if (defined? '%storedir) %storedir %store-directory))
94 (define localstatedir
95 (if (defined? '%localstatedir) %localstatedir (dirname %state-directory)))
96 (define sysconfdir
97 (if (defined? '%sysconfdir) %sysconfdir (dirname %config-directory)))
98 (define sbindir
99 (if (defined? '%sbindir) %sbindir (dirname %guix-register-program)))
100
101 (define builder
102 #~(begin
103 (use-modules (guix build pull))
104
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)))
108
109 (build-guix #$output #$source
110
111 #:system #$%system
112 #:storedir #$storedir
113 #:localstatedir #$localstatedir
114 #:sysconfdir #$sysconfdir
115 #:sbindir #$sbindir
116
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
121
122 #:libgcrypt #$libgcrypt
123 #:zlib #$zlib
124 #:gzip #$gzip
125 #:bzip2 #$bzip2
126 #:xz #$xz
127
128 ;; XXX: This is not perfect, enabling VERBOSE? means
129 ;; building a different derivation.
130 #:debug-port (if #$verbose?
131 (current-error-port)
132 (%make-void-port "w")))))
133
134 (gexp->derivation "guix-latest" builder
135 #:modules '((guix build pull)
136 (guix build utils))
137
138 ;; Arrange so that our own (guix build …) modules are
139 ;; used.
140 #:module-path (list (top-source-directory))))
141
142 ;; This file is loaded by 'guix pull'; return it the build procedure.
143 build
144
145 ;; Local Variables:
146 ;; eval: (put 'with-load-path 'scheme-indent-function 1)
147 ;; End:
148
149 ;;; build-self.scm ends here