Commit | Line | Data |
---|---|---|
eaae07ec | 1 | ;;; GNU Guix --- Functional package management for GNU |
76832d34 | 2 | ;;; Copyright © 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
eaae07ec 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 (guix self) | |
20 | #:use-module (guix config) | |
21 | #:use-module (guix i18n) | |
22 | #:use-module (guix modules) | |
23 | #:use-module (guix gexp) | |
24 | #:use-module (guix store) | |
25 | #:use-module (guix monads) | |
26 | #:use-module (guix discovery) | |
27 | #:use-module (guix packages) | |
28 | #:use-module (guix sets) | |
eaae07ec | 29 | #:use-module (guix modules) |
45779fa6 | 30 | #:use-module ((guix build utils) #:select (find-files)) |
eaae07ec LC |
31 | #:use-module ((guix build compile) #:select (%lightweight-optimizations)) |
32 | #:use-module (srfi srfi-1) | |
33 | #:use-module (srfi srfi-9) | |
6e54e488 | 34 | #:use-module (srfi srfi-35) |
eaae07ec LC |
35 | #:use-module (ice-9 match) |
36 | #:export (make-config.scm | |
8a0d9bc8 | 37 | whole-package ;for internal use in 'guix pull' |
eaae07ec | 38 | compiled-guix |
567f0d25 | 39 | guix-derivation)) |
eaae07ec LC |
40 | |
41 | \f | |
42 | ;;; | |
43 | ;;; Dependency handling. | |
44 | ;;; | |
45 | ||
eaae07ec LC |
46 | (define specification->package |
47 | ;; Use our own variant of that procedure because that of (gnu packages) | |
48 | ;; would traverse all the .scm files, which is wasteful. | |
49 | (let ((ref (lambda (module variable) | |
50 | (module-ref (resolve-interface module) variable)))) | |
51 | (match-lambda | |
52 | ("guile" (ref '(gnu packages commencement) 'guile-final)) | |
81c3dc32 | 53 | ("guile-json" (ref '(gnu packages guile) 'guile-json-3)) |
eaae07ec LC |
54 | ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh)) |
55 | ("guile-git" (ref '(gnu packages guile) 'guile-git)) | |
d59e75f3 | 56 | ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3)) |
ca719424 | 57 | ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt)) |
108015df | 58 | ("gnutls" (ref '(gnu packages tls) 'gnutls)) |
eaae07ec | 59 | ("zlib" (ref '(gnu packages compression) 'zlib)) |
73ac9098 | 60 | ("lzlib" (ref '(gnu packages compression) 'lzlib)) |
eaae07ec LC |
61 | ("gzip" (ref '(gnu packages compression) 'gzip)) |
62 | ("bzip2" (ref '(gnu packages compression) 'bzip2)) | |
63 | ("xz" (ref '(gnu packages compression) 'xz)) | |
554b30d2 JL |
64 | ("po4a" (ref '(gnu packages gettext) 'po4a)) |
65 | ("gettext" (ref '(gnu packages gettext) 'gettext-minimal)) | |
6e54e488 | 66 | (_ #f)))) ;no such package |
eaae07ec LC |
67 | |
68 | \f | |
69 | ;;; | |
70 | ;;; Derivations. | |
71 | ;;; | |
72 | ||
73 | ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's | |
74 | ;; easier to express things this way. | |
75 | (define-record-type <node> | |
76 | (node name modules source dependencies compiled) | |
77 | node? | |
78 | (name node-name) ;string | |
79 | (modules node-modules) ;list of module names | |
80 | (source node-source) ;list of source files | |
81 | (dependencies node-dependencies) ;list of nodes | |
82 | (compiled node-compiled)) ;node -> lowerable object | |
83 | ||
f5db54ea LC |
84 | ;; File mappings are essentially an alist as passed to 'imported-files'. |
85 | (define-record-type <file-mapping> | |
86 | (file-mapping name alist) | |
87 | file-mapping? | |
88 | (name file-mapping-name) | |
89 | (alist file-mapping-alist)) | |
90 | ||
91 | (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>) | |
92 | system target) | |
93 | ;; Here we use 'imported-files', which can arrange to directly import all | |
94 | ;; the files instead of creating a derivation, when possible. | |
95 | (imported-files (map (match-lambda | |
96 | ((destination (? local-file? file)) | |
97 | (cons destination | |
98 | (local-file-absolute-file-name file))) | |
99 | ((destination source) | |
100 | (cons destination source))) ;silliness | |
101 | (file-mapping-alist mapping)) | |
102 | #:name (file-mapping-name mapping) | |
103 | #:system system)) | |
104 | ||
49c35bbb LC |
105 | (define (node-source+compiled node) |
106 | "Return a \"bundle\" containing both the source code and object files for | |
107 | NODE's modules, under their FHS directories: share/guile/site and lib/guile." | |
108 | (define build | |
109 | (with-imported-modules '((guix build utils)) | |
110 | #~(begin | |
111 | (use-modules (guix build utils)) | |
112 | ||
113 | (define source | |
114 | (string-append #$output "/share/guile/site/" | |
115 | (effective-version))) | |
116 | ||
117 | (define object | |
118 | (string-append #$output "/lib/guile/" (effective-version) | |
119 | "/site-ccache")) | |
120 | ||
121 | (mkdir-p (dirname source)) | |
122 | (symlink #$(node-source node) source) | |
123 | (mkdir-p (dirname object)) | |
124 | (symlink #$(node-compiled node) object)))) | |
125 | ||
126 | (computed-file (string-append (node-name node) "-modules") | |
8727e030 LC |
127 | build |
128 | #:options '(#:local-build? #t | |
129 | ||
130 | ;; "Building" it locally is faster. | |
131 | #:substitutable? #f))) | |
49c35bbb | 132 | |
eaae07ec LC |
133 | (define (node-fold proc init nodes) |
134 | (let loop ((nodes nodes) | |
135 | (visited (setq)) | |
136 | (result init)) | |
137 | (match nodes | |
138 | (() result) | |
139 | ((head tail ...) | |
140 | (if (set-contains? visited head) | |
141 | (loop tail visited result) | |
142 | (loop tail (set-insert head visited) | |
143 | (proc head result))))))) | |
144 | ||
145 | (define (node-modules/recursive nodes) | |
146 | (node-fold (lambda (node modules) | |
147 | (append (node-modules node) modules)) | |
148 | '() | |
149 | nodes)) | |
150 | ||
151 | (define* (closure modules #:optional (except '())) | |
152 | (source-module-closure modules | |
153 | #:select? | |
154 | (match-lambda | |
155 | (('guix 'config) | |
156 | #f) | |
157 | ((and module | |
158 | (or ('guix _ ...) ('gnu _ ...))) | |
159 | (not (member module except))) | |
160 | (rest #f)))) | |
161 | ||
162 | (define module->import | |
163 | ;; Return a file-name/file-like object pair for the specified module and | |
164 | ;; suitable for 'imported-files'. | |
165 | (match-lambda | |
166 | ((module '=> thing) | |
167 | (let ((file (module-name->file-name module))) | |
168 | (list file thing))) | |
169 | (module | |
170 | (let ((file (module-name->file-name module))) | |
171 | (list file | |
172 | (local-file (search-path %load-path file))))))) | |
173 | ||
174 | (define* (scheme-node name modules #:optional (dependencies '()) | |
175 | #:key (extra-modules '()) (extra-files '()) | |
176 | (extensions '()) | |
177 | parallel? guile-for-build) | |
178 | "Return a node that builds the given Scheme MODULES, and depends on | |
179 | DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules | |
180 | added to the source, and EXTRA-FILES is a list of additional files. | |
181 | EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that | |
182 | must be present in the search path." | |
183 | (let* ((modules (append extra-modules | |
184 | (closure modules | |
185 | (node-modules/recursive dependencies)))) | |
186 | (module-files (map module->import modules)) | |
f5db54ea LC |
187 | (source (file-mapping (string-append name "-source") |
188 | (append module-files extra-files)))) | |
eaae07ec | 189 | (node name modules source dependencies |
8031b3fa LC |
190 | (compiled-modules name source |
191 | (map car module-files) | |
eaae07ec LC |
192 | (map node-source dependencies) |
193 | (map node-compiled dependencies) | |
194 | #:extensions extensions | |
195 | #:parallel? parallel? | |
196 | #:guile-for-build guile-for-build)))) | |
197 | ||
198 | (define (file-imports directory sub-directory pred) | |
199 | "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a | |
200 | list of file-name/file-like objects suitable as inputs to 'imported-files'." | |
201 | (map (lambda (file) | |
202 | (list (string-drop file (+ 1 (string-length directory))) | |
203 | (local-file file #:recursive? #t))) | |
204 | (find-files (string-append directory "/" sub-directory) pred))) | |
205 | ||
6cf502d1 LC |
206 | (define* (file-append* item file #:key (recursive? #t)) |
207 | "Return FILE within ITEM, which may be a file name or a file-like object. | |
208 | When ITEM is a plain file name (a string), simply return a 'local-file' | |
209 | record with the new file name." | |
9f1c3559 LC |
210 | (match item |
211 | ((? string?) | |
212 | ;; This is the optimal case: we return a new "source". Thus, a | |
213 | ;; derivation that depends on this sub-directory does not depend on ITEM | |
214 | ;; itself. | |
6cf502d1 LC |
215 | (local-file (string-append item "/" file) |
216 | #:recursive? recursive?)) | |
9f1c3559 LC |
217 | ;; TODO: Add 'local-file?' case. |
218 | (_ | |
219 | ;; In this case, anything that refers to the result also depends on ITEM, | |
220 | ;; which isn't great. | |
6cf502d1 | 221 | (file-append item "/" file)))) |
9f1c3559 LC |
222 | |
223 | (define* (locale-data source domain | |
224 | #:optional (directory domain)) | |
225 | "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to | |
226 | DOMAIN, a gettext domain." | |
227 | (define gettext | |
228 | (module-ref (resolve-interface '(gnu packages gettext)) | |
229 | 'gettext-minimal)) | |
230 | ||
231 | (define build | |
232 | (with-imported-modules '((guix build utils)) | |
233 | #~(begin | |
234 | (use-modules (guix build utils) | |
235 | (srfi srfi-26) | |
236 | (ice-9 match) (ice-9 ftw)) | |
237 | ||
238 | (define po-directory | |
6cf502d1 | 239 | #+(file-append* source (string-append "po/" directory))) |
9f1c3559 LC |
240 | |
241 | (define (compile language) | |
242 | (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/" | |
243 | #$domain ".mo"))) | |
244 | (mkdir-p (dirname gmo)) | |
245 | (invoke #+(file-append gettext "/bin/msgfmt") | |
246 | "-c" "--statistics" "--verbose" | |
247 | "-o" gmo | |
248 | (string-append po-directory "/" language ".po")))) | |
249 | ||
250 | (define (linguas) | |
251 | ;; Return the list of languages. Note: don't read 'LINGUAS' | |
252 | ;; because it contains things like 'en@boldquot' that do not have | |
253 | ;; a corresponding .po file. | |
254 | (map (cut basename <> ".po") | |
255 | (scandir po-directory | |
256 | (cut string-suffix? ".po" <>)))) | |
257 | ||
258 | (for-each compile (linguas))))) | |
259 | ||
260 | (computed-file (string-append "guix-locale-" domain) | |
261 | build)) | |
262 | ||
554b30d2 JL |
263 | (define (translate-texi-manuals source) |
264 | "Return the translated texinfo manuals built from SOURCE." | |
265 | (define po4a | |
266 | (specification->package "po4a")) | |
267 | ||
268 | (define gettext | |
269 | (specification->package "gettext")) | |
270 | ||
271 | (define glibc-utf8-locales | |
272 | (module-ref (resolve-interface '(gnu packages base)) | |
273 | 'glibc-utf8-locales)) | |
274 | ||
275 | (define documentation | |
276 | (file-append* source "doc")) | |
277 | ||
278 | (define documentation-po | |
279 | (file-append* source "po/doc")) | |
280 | ||
281 | (define build | |
282 | (with-imported-modules '((guix build utils) (guix build po)) | |
283 | #~(begin | |
284 | (use-modules (guix build utils) (guix build po) | |
285 | (ice-9 match) (ice-9 regex) (ice-9 textual-ports) | |
286 | (srfi srfi-1)) | |
287 | ||
288 | (mkdir #$output) | |
289 | ||
290 | (copy-recursively #$documentation "." | |
291 | #:log (%make-void-port "w")) | |
292 | ||
293 | (for-each | |
294 | (lambda (file) | |
295 | (copy-file file (basename file))) | |
296 | (find-files #$documentation-po ".*.po$")) | |
297 | ||
298 | (setenv "GUIX_LOCPATH" | |
299 | #+(file-append glibc-utf8-locales "/lib/locale")) | |
300 | (setenv "PATH" #+(file-append gettext "/bin")) | |
301 | (setenv "LC_ALL" "en_US.UTF-8") | |
302 | (setlocale LC_ALL "en_US.UTF-8") | |
303 | ||
304 | (define (translate-tmp-texi po source output) | |
305 | "Translate Texinfo file SOURCE using messages from PO, and write | |
306 | the result to OUTPUT." | |
307 | (invoke #+(file-append po4a "/bin/po4a-translate") | |
308 | "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo" | |
309 | "-m" source "-p" po "-l" output)) | |
310 | ||
311 | (define (make-ref-regex msgid end) | |
312 | (make-regexp (string-append | |
313 | "ref\\{" | |
314 | (string-join (string-split (regexp-quote msgid) #\ ) | |
315 | "[ \n]+") | |
316 | end))) | |
317 | ||
318 | (define (translate-cross-references content translations) | |
319 | "Take CONTENT, a string representing a .texi file and translate any | |
320 | cross-reference in it (@ref, @xref and @pxref) that have a translation in | |
321 | TRANSLATIONS, an alist of msgid and msgstr." | |
322 | (fold | |
323 | (lambda (elem content) | |
324 | (match elem | |
325 | ((msgid . msgstr) | |
326 | ;; Empty translations and strings containing some special characters | |
327 | ;; cannot be the name of a section. | |
328 | (if (or (equal? msgstr "") | |
329 | (string-any (lambda (chr) | |
330 | (member chr '(#\{ #\} #\( #\) #\newline #\,))) | |
331 | msgid)) | |
332 | content | |
333 | ;; Otherwise, they might be the name of a section, so we | |
334 | ;; need to translate any occurence in @(p?x?)ref{...}. | |
335 | (let ((regexp1 (make-ref-regex msgid ",")) | |
336 | (regexp2 (make-ref-regex msgid "\\}"))) | |
337 | (regexp-substitute/global | |
338 | #f regexp2 | |
339 | (regexp-substitute/global | |
340 | #f regexp1 content 'pre "ref{" msgstr "," 'post) | |
341 | 'pre "ref{" msgstr "}" 'post)))))) | |
342 | content translations)) | |
343 | ||
344 | (define (translate-texi po lang) | |
345 | "Translate the manual for one language LANG using the PO file." | |
346 | (let ((translations (call-with-input-file po read-po-file))) | |
347 | (translate-tmp-texi po "guix.texi" | |
348 | (string-append "guix." lang ".texi.tmp")) | |
349 | (translate-tmp-texi po "contributing.texi" | |
350 | (string-append "contributing." lang ".texi.tmp")) | |
351 | (let* ((texi-name (string-append "guix." lang ".texi")) | |
352 | (tmp-name (string-append texi-name ".tmp"))) | |
353 | (with-output-to-file texi-name | |
354 | (lambda _ | |
355 | (format #t "~a" | |
356 | (translate-cross-references | |
357 | (call-with-input-file tmp-name get-string-all) | |
358 | translations))))) | |
359 | (let* ((texi-name (string-append "contributing." lang ".texi")) | |
360 | (tmp-name (string-append texi-name ".tmp"))) | |
361 | (with-output-to-file texi-name | |
362 | (lambda _ | |
363 | (format #t "~a" | |
364 | (translate-cross-references | |
365 | (call-with-input-file tmp-name get-string-all) | |
366 | translations))))))) | |
367 | ||
368 | (for-each (lambda (po) | |
369 | (match (reverse (string-split po #\.)) | |
370 | ((_ lang _ ...) | |
371 | (translate-texi po lang)))) | |
372 | (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$")) | |
373 | ||
374 | (for-each | |
375 | (lambda (file) | |
376 | (copy-file file (string-append #$output "/" file))) | |
377 | (append | |
378 | (find-files "." "contributing\\..*\\.texi$") | |
379 | (find-files "." "guix\\..*\\.texi$")))))) | |
380 | ||
381 | (computed-file "guix-translated-texinfo" build)) | |
382 | ||
4554d4c8 LC |
383 | (define (info-manual source) |
384 | "Return the Info manual built from SOURCE." | |
385 | (define texinfo | |
386 | (module-ref (resolve-interface '(gnu packages texinfo)) | |
387 | 'texinfo)) | |
388 | ||
389 | (define graphviz | |
390 | (module-ref (resolve-interface '(gnu packages graphviz)) | |
391 | 'graphviz)) | |
392 | ||
2d337760 LC |
393 | (define glibc-utf8-locales |
394 | (module-ref (resolve-interface '(gnu packages base)) | |
395 | 'glibc-utf8-locales)) | |
396 | ||
4554d4c8 | 397 | (define documentation |
6cf502d1 | 398 | (file-append* source "doc")) |
4554d4c8 LC |
399 | |
400 | (define examples | |
6cf502d1 | 401 | (file-append* source "gnu/system/examples")) |
4554d4c8 LC |
402 | |
403 | (define build | |
404 | (with-imported-modules '((guix build utils)) | |
405 | #~(begin | |
406 | (use-modules (guix build utils)) | |
407 | ||
408 | (mkdir #$output) | |
409 | ||
410 | ;; Create 'version.texi'. | |
411 | ;; XXX: Can we use a more meaningful version string yet one that | |
412 | ;; doesn't change at each commit? | |
413 | (call-with-output-file "version.texi" | |
414 | (lambda (port) | |
cbe7387c | 415 | (let ((version "0.0-git")) |
4554d4c8 LC |
416 | (format port " |
417 | @set UPDATED 1 January 1970 | |
418 | @set UPDATED-MONTH January 1970 | |
419 | @set EDITION ~a | |
420 | @set VERSION ~a\n" version version)))) | |
421 | ||
422 | ;; Copy configuration templates that the manual includes. | |
423 | (for-each (lambda (template) | |
424 | (copy-file template | |
425 | (string-append | |
426 | "os-config-" | |
427 | (basename template ".tmpl") | |
428 | ".texi"))) | |
429 | (find-files #$examples "\\.tmpl$")) | |
430 | ||
431 | ;; Build graphs. | |
432 | (mkdir-p (string-append #$output "/images")) | |
433 | (for-each (lambda (dot-file) | |
434 | (invoke #+(file-append graphviz "/bin/dot") | |
435 | "-Tpng" "-Gratio=.9" "-Gnodesep=.005" | |
436 | "-Granksep=.00005" "-Nfontsize=9" | |
437 | "-Nheight=.1" "-Nwidth=.1" | |
438 | "-o" (string-append #$output "/images/" | |
439 | (basename dot-file ".dot") | |
440 | ".png") | |
441 | dot-file)) | |
442 | (find-files (string-append #$documentation "/images") | |
443 | "\\.dot$")) | |
444 | ||
445 | ;; Copy other PNGs. | |
446 | (for-each (lambda (png-file) | |
447 | (install-file png-file | |
448 | (string-append #$output "/images"))) | |
449 | (find-files (string-append #$documentation "/images") | |
450 | "\\.png$")) | |
451 | ||
452 | ;; Finally build the manual. Copy it the Texinfo files to $PWD and | |
453 | ;; add a symlink to the 'images' directory so that 'makeinfo' can | |
454 | ;; see those images and produce image references in the Info output. | |
455 | (copy-recursively #$documentation "." | |
456 | #:log (%make-void-port "w")) | |
554b30d2 JL |
457 | (copy-recursively #+(translate-texi-manuals source) "." |
458 | #:log (%make-void-port "w")) | |
4554d4c8 LC |
459 | (delete-file-recursively "images") |
460 | (symlink (string-append #$output "/images") "images") | |
461 | ||
2d337760 LC |
462 | ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo. |
463 | (setenv "GUIX_LOCPATH" | |
464 | #+(file-append glibc-utf8-locales "/lib/locale")) | |
465 | ||
4554d4c8 LC |
466 | (for-each (lambda (texi) |
467 | (unless (string=? "guix.texi" texi) | |
468 | ;; Create 'version-LL.texi'. | |
469 | (let* ((base (basename texi ".texi")) | |
470 | (dot (string-index base #\.)) | |
471 | (tag (string-drop base (+ 1 dot)))) | |
472 | (symlink "version.texi" | |
473 | (string-append "version-" tag ".texi")))) | |
474 | ||
475 | (invoke #+(file-append texinfo "/bin/makeinfo") | |
476 | texi "-I" #$documentation | |
477 | "-I" "." | |
478 | "-o" (string-append #$output "/" | |
479 | (basename texi ".texi") | |
480 | ".info"))) | |
481 | (cons "guix.texi" | |
17503ea8 | 482 | (find-files "." "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$"))) |
08fdee39 LC |
483 | |
484 | ;; Compress Info files. | |
485 | (setenv "PATH" | |
486 | #+(file-append (specification->package "gzip") "/bin")) | |
487 | (for-each (lambda (file) | |
488 | (invoke "gzip" "-9n" file)) | |
489 | (find-files #$output "\\.info(-[0-9]+)?$"))))) | |
4554d4c8 LC |
490 | |
491 | (computed-file "guix-manual" build)) | |
492 | ||
49c35bbb LC |
493 | (define* (guile-module-union things #:key (name "guix-module-union")) |
494 | "Return the union of the subset of THINGS (packages, computed files, etc.) | |
495 | that provide Guile modules." | |
496 | (define build | |
497 | (with-imported-modules '((guix build union)) | |
498 | #~(begin | |
499 | (use-modules (guix build union)) | |
500 | ||
501 | (define (modules directory) | |
502 | (string-append directory "/share/guile/site")) | |
503 | ||
504 | (define (objects directory) | |
505 | (string-append directory "/lib/guile")) | |
506 | ||
507 | (union-build #$output | |
508 | (filter (lambda (directory) | |
509 | (or (file-exists? (modules directory)) | |
510 | (file-exists? (objects directory)))) | |
511 | '#$things) | |
512 | ||
513 | #:log-port (%make-void-port "w"))))) | |
514 | ||
515 | (computed-file name build)) | |
516 | ||
517 | (define* (guix-command modules | |
a89faa3f | 518 | #:key source (dependencies '()) |
8970a886 | 519 | guile (guile-version (effective-version))) |
8a0d9bc8 LC |
520 | "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its |
521 | load path." | |
ba488958 LC |
522 | (define glibc-utf8-locales |
523 | (module-ref (resolve-interface '(gnu packages base)) | |
524 | 'glibc-utf8-locales)) | |
525 | ||
49c35bbb LC |
526 | (define module-directory |
527 | ;; To minimize the number of 'stat' calls needed to locate a module, | |
528 | ;; create the union of all the module directories. | |
529 | (guile-module-union (cons modules dependencies))) | |
f2d0a2cf | 530 | |
8a0d9bc8 LC |
531 | (program-file "guix-command" |
532 | #~(begin | |
533 | (set! %load-path | |
49c35bbb LC |
534 | (cons (string-append #$module-directory |
535 | "/share/guile/site/" | |
536 | (effective-version)) | |
537 | %load-path)) | |
8a0d9bc8 | 538 | |
8a0d9bc8 | 539 | (set! %load-compiled-path |
49c35bbb LC |
540 | (cons (string-append #$module-directory |
541 | "/lib/guile/" | |
542 | (effective-version) | |
543 | "/site-ccache") | |
a89faa3f | 544 | %load-compiled-path)) |
8a0d9bc8 | 545 | |
ba488958 LC |
546 | ;; To maximize the chances that locales are set up right |
547 | ;; out-of-the-box, bundle "common" UTF-8 locales. | |
548 | (let ((locpath (getenv "GUIX_LOCPATH"))) | |
549 | (setenv "GUIX_LOCPATH" | |
550 | (string-append (if locpath | |
551 | (string-append locpath ":") | |
552 | "") | |
553 | #$(file-append glibc-utf8-locales | |
554 | "/lib/locale")))) | |
555 | ||
8a0d9bc8 LC |
556 | (let ((guix-main (module-ref (resolve-interface '(guix ui)) |
557 | 'guix-main))) | |
9f1c3559 LC |
558 | #$(if source |
559 | #~(begin | |
560 | (bindtextdomain "guix" | |
561 | #$(locale-data source "guix")) | |
562 | (bindtextdomain "guix-packages" | |
563 | #$(locale-data source | |
564 | "guix-packages" | |
565 | "packages"))) | |
566 | #t) | |
8a0d9bc8 LC |
567 | |
568 | ;; XXX: It would be more convenient to change it to: | |
569 | ;; (exit (apply guix-main (command-line))) | |
8970a886 LC |
570 | (apply guix-main (command-line)))) |
571 | #:guile guile)) | |
8a0d9bc8 | 572 | |
e3744779 LC |
573 | (define (miscellaneous-files source) |
574 | "Return data files taken from SOURCE." | |
575 | (file-mapping "guix-misc" | |
576 | `(("etc/bash_completion.d/guix" | |
577 | ,(file-append* source "/etc/completion/bash/guix")) | |
578 | ("etc/bash_completion.d/guix-daemon" | |
579 | ,(file-append* source "/etc/completion/bash/guix-daemon")) | |
580 | ("share/zsh/site-functions/_guix" | |
581 | ,(file-append* source "/etc/completion/zsh/_guix")) | |
582 | ("share/fish/vendor_completions.d/guix.fish" | |
583 | ,(file-append* source "/etc/completion/fish/guix.fish")) | |
e3744779 | 584 | ("share/guix/berlin.guixsd.org.pub" |
6a837b60 LC |
585 | ,(file-append* source |
586 | "/etc/substitutes/berlin.guixsd.org.pub")) | |
757e633d LC |
587 | ("share/guix/ci.guix.gnu.org.pub" ;alias |
588 | ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub")) | |
6a837b60 | 589 | ("share/guix/ci.guix.info.pub" ;alias |
e3744779 LC |
590 | ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub"))))) |
591 | ||
8a0d9bc8 | 592 | (define* (whole-package name modules dependencies |
9f1c3559 LC |
593 | #:key |
594 | (guile-version (effective-version)) | |
e3744779 | 595 | info daemon miscellany |
8d3beb3a | 596 | guile |
9f1c3559 LC |
597 | (command (guix-command modules |
598 | #:dependencies dependencies | |
8970a886 | 599 | #:guile guile |
9f1c3559 | 600 | #:guile-version guile-version))) |
8a0d9bc8 | 601 | "Return the whole Guix package NAME that uses MODULES, a derivation of all |
49c35bbb LC |
602 | the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list |
603 | of packages depended on. COMMAND is the 'guix' program to use; INFO is the | |
604 | Info manual." | |
765a5bf1 LC |
605 | (define (wrap daemon) |
606 | (program-file "guix-daemon" | |
607 | #~(begin | |
dfc69e4b LC |
608 | ;; Refer to the right 'guix' command for 'guix |
609 | ;; substitute' & co. | |
765a5bf1 | 610 | (setenv "GUIX" #$command) |
dfc69e4b LC |
611 | |
612 | ;; Honor the user's settings rather than those hardcoded | |
613 | ;; in the 'guix-daemon' package. | |
614 | (unless (getenv "GUIX_STATE_DIRECTORY") | |
615 | (setenv "GUIX_STATE_DIRECTORY" | |
616 | #$(string-append %localstatedir "/guix"))) | |
617 | (unless (getenv "GUIX_CONFIGURATION_DIRECTORY") | |
618 | (setenv "GUIX_CONFIGURATION_DIRECTORY" | |
619 | #$(string-append %sysconfdir "/guix"))) | |
620 | (unless (getenv "NIX_STORE_DIR") | |
fa866548 | 621 | (setenv "NIX_STORE_DIR" #$%storedir)) |
dfc69e4b | 622 | |
765a5bf1 LC |
623 | (apply execl #$(file-append daemon "/bin/guix-daemon") |
624 | "guix-daemon" (cdr (command-line)))))) | |
625 | ||
9f1c3559 LC |
626 | (computed-file name |
627 | (with-imported-modules '((guix build utils)) | |
628 | #~(begin | |
629 | (use-modules (guix build utils)) | |
e3744779 | 630 | |
765a5bf1 LC |
631 | (define daemon |
632 | #$(and daemon (wrap daemon))) | |
633 | ||
9f1c3559 LC |
634 | (mkdir-p (string-append #$output "/bin")) |
635 | (symlink #$command | |
636 | (string-append #$output "/bin/guix")) | |
637 | ||
765a5bf1 LC |
638 | (when daemon |
639 | (symlink daemon | |
baed9236 LC |
640 | (string-append #$output "/bin/guix-daemon"))) |
641 | ||
49c35bbb LC |
642 | (let ((share (string-append #$output "/share")) |
643 | (lib (string-append #$output "/lib")) | |
644 | (info #$info)) | |
645 | (mkdir-p share) | |
646 | (symlink #$(file-append modules "/share/guile") | |
647 | (string-append share "/guile")) | |
4554d4c8 | 648 | (when info |
49c35bbb LC |
649 | (symlink #$info (string-append share "/info"))) |
650 | ||
651 | (mkdir-p lib) | |
652 | (symlink #$(file-append modules "/lib/guile") | |
653 | (string-append lib "/guile"))) | |
a89faa3f | 654 | |
e3744779 LC |
655 | (when #$miscellany |
656 | (copy-recursively #$miscellany #$output | |
49c35bbb | 657 | #:log (%make-void-port "w"))))))) |
8a0d9bc8 | 658 | |
eaae07ec | 659 | (define* (compiled-guix source #:key (version %guix-version) |
8a0d9bc8 | 660 | (pull-version 1) |
eaae07ec LC |
661 | (name (string-append "guix-" version)) |
662 | (guile-version (effective-version)) | |
6e54e488 | 663 | (guile-for-build (default-guile)) |
eaae07ec | 664 | (zlib (specification->package "zlib")) |
73ac9098 | 665 | (lzlib (specification->package "lzlib")) |
eaae07ec LC |
666 | (gzip (specification->package "gzip")) |
667 | (bzip2 (specification->package "bzip2")) | |
668 | (xz (specification->package "xz")) | |
669 | (guix (specification->package "guix"))) | |
670 | "Return a file-like object that contains a compiled Guix." | |
671 | (define guile-json | |
6e54e488 | 672 | (specification->package "guile-json")) |
eaae07ec LC |
673 | |
674 | (define guile-ssh | |
6e54e488 | 675 | (specification->package "guile-ssh")) |
eaae07ec LC |
676 | |
677 | (define guile-git | |
6e54e488 | 678 | (specification->package "guile-git")) |
eaae07ec | 679 | |
d59e75f3 | 680 | (define guile-sqlite3 |
6e54e488 | 681 | (specification->package "guile-sqlite3")) |
d59e75f3 | 682 | |
ca719424 | 683 | (define guile-gcrypt |
6e54e488 | 684 | (specification->package "guile-gcrypt")) |
ca719424 | 685 | |
108015df | 686 | (define gnutls |
6e54e488 | 687 | (specification->package "gnutls")) |
108015df | 688 | |
eaae07ec LC |
689 | (define dependencies |
690 | (match (append-map (lambda (package) | |
691 | (cons (list "x" package) | |
e13240f5 | 692 | (package-transitive-propagated-inputs package))) |
ca719424 | 693 | (list guile-gcrypt gnutls guile-git guile-json |
108015df | 694 | guile-ssh guile-sqlite3)) |
eaae07ec LC |
695 | (((labels packages _ ...) ...) |
696 | packages))) | |
697 | ||
698 | (define *core-modules* | |
699 | (scheme-node "guix-core" | |
700 | '((guix) | |
701 | (guix monad-repl) | |
702 | (guix packages) | |
703 | (guix download) | |
704 | (guix discovery) | |
705 | (guix profiles) | |
706 | (guix build-system gnu) | |
707 | (guix build-system trivial) | |
708 | (guix build profiles) | |
709 | (guix build gnu-build-system)) | |
710 | ||
711 | ;; Provide a dummy (guix config) with the default version | |
712 | ;; number, storedir, etc. This is so that "guix-core" is the | |
713 | ;; same across all installations and doesn't need to be | |
714 | ;; rebuilt when the version changes, which in turn means we | |
715 | ;; can have substitutes for it. | |
716 | #:extra-modules | |
ca719424 | 717 | `(((guix config) => ,(make-config.scm))) |
eaae07ec | 718 | |
8292f5a9 LC |
719 | ;; (guix man-db) is needed at build-time by (guix profiles) |
720 | ;; but we don't need to compile it; not compiling it allows | |
721 | ;; us to avoid an extra dependency on guile-gdbm-ffi. | |
722 | #:extra-files | |
3931c761 | 723 | `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm")) |
554b30d2 | 724 | ("guix/build/po.scm" ,(local-file "../guix/build/po.scm")) |
3931c761 LC |
725 | ("guix/store/schema.sql" |
726 | ,(local-file "../guix/store/schema.sql"))) | |
8292f5a9 | 727 | |
ca719424 | 728 | #:extensions (list guile-gcrypt) |
eaae07ec LC |
729 | #:guile-for-build guile-for-build)) |
730 | ||
731 | (define *extra-modules* | |
732 | (scheme-node "guix-extra" | |
733 | (filter-map (match-lambda | |
734 | (('guix 'scripts _ ..1) #f) | |
8292f5a9 | 735 | (('guix 'man-db) #f) |
852d30a6 | 736 | (('guix 'tests _ ...) #f) |
eaae07ec LC |
737 | (name name)) |
738 | (scheme-modules* source "guix")) | |
739 | (list *core-modules*) | |
740 | #:extensions dependencies | |
741 | #:guile-for-build guile-for-build)) | |
742 | ||
f2e66663 LC |
743 | (define *core-package-modules* |
744 | (scheme-node "guix-packages-base" | |
eaae07ec | 745 | `((gnu packages) |
f2e66663 | 746 | (gnu packages base)) |
eaae07ec LC |
747 | (list *core-modules* *extra-modules*) |
748 | #:extensions dependencies | |
f2e66663 LC |
749 | |
750 | ;; Add all the non-Scheme files here. We must do it here so | |
751 | ;; that 'search-patches' & co. can find them. Ideally we'd | |
752 | ;; keep them next to the .scm files that use them but it's | |
753 | ;; difficult to do (XXX). | |
754 | #:extra-files | |
eaae07ec LC |
755 | (file-imports source "gnu/packages" |
756 | (lambda (file stat) | |
757 | (and (eq? 'regular (stat:type stat)) | |
758 | (not (string-suffix? ".scm" file)) | |
759 | (not (string-suffix? ".go" file)) | |
760 | (not (string-prefix? ".#" file)) | |
761 | (not (string-suffix? "~" file))))) | |
762 | #:guile-for-build guile-for-build)) | |
763 | ||
f2e66663 LC |
764 | (define *package-modules* |
765 | (scheme-node "guix-packages" | |
766 | (scheme-modules* source "gnu/packages") | |
767 | (list *core-modules* *extra-modules* *core-package-modules*) | |
768 | #:extensions dependencies | |
769 | #:guile-for-build guile-for-build)) | |
770 | ||
eaae07ec LC |
771 | (define *system-modules* |
772 | (scheme-node "guix-system" | |
773 | `((gnu system) | |
774 | (gnu services) | |
5a6e04c5 | 775 | ,@(scheme-modules* source "gnu/bootloader") |
a49d633c | 776 | ,@(scheme-modules* source "gnu/system") |
079c93e1 MW |
777 | ,@(scheme-modules* source "gnu/services") |
778 | ,@(scheme-modules* source "gnu/machine")) | |
f2e66663 LC |
779 | (list *core-package-modules* *package-modules* |
780 | *extra-modules* *core-modules*) | |
eaae07ec LC |
781 | #:extensions dependencies |
782 | #:extra-files | |
1458f768 LC |
783 | (append (file-imports source "gnu/system/examples" |
784 | (const #t)) | |
8bb62ae1 | 785 | |
a49d633c MO |
786 | ;; All the installer code is on the build-side. |
787 | (file-imports source "gnu/installer/" | |
788 | (const #t)) | |
1458f768 LC |
789 | ;; Build-side code that we don't build. Some of |
790 | ;; these depend on guile-rsvg, the Shepherd, etc. | |
791 | (file-imports source "gnu/build" (const #t))) | |
eaae07ec LC |
792 | #:guile-for-build |
793 | guile-for-build)) | |
794 | ||
795 | (define *cli-modules* | |
796 | (scheme-node "guix-cli" | |
b5f8c2c8 LC |
797 | (append (scheme-modules* source "/guix/scripts") |
798 | `((gnu ci))) | |
f2e66663 LC |
799 | (list *core-modules* *extra-modules* |
800 | *core-package-modules* *package-modules* | |
eaae07ec LC |
801 | *system-modules*) |
802 | #:extensions dependencies | |
803 | #:guile-for-build guile-for-build)) | |
804 | ||
5f2daffe LC |
805 | (define *system-test-modules* |
806 | ;; Ship these modules mostly so (gnu ci) can discover them. | |
807 | (scheme-node "guix-system-tests" | |
808 | `((gnu tests) | |
809 | ,@(scheme-modules* source "gnu/tests")) | |
810 | (list *core-package-modules* *package-modules* | |
811 | *extra-modules* *system-modules* *core-modules* | |
812 | *cli-modules*) ;for (guix scripts pack), etc. | |
813 | #:extensions dependencies | |
814 | #:guile-for-build guile-for-build)) | |
815 | ||
eaae07ec LC |
816 | (define *config* |
817 | (scheme-node "guix-config" | |
818 | '() | |
819 | #:extra-modules | |
820 | `(((guix config) | |
ca719424 | 821 | => ,(make-config.scm #:zlib zlib |
73ac9098 | 822 | #:lzlib lzlib |
eaae07ec LC |
823 | #:gzip gzip |
824 | #:bzip2 bzip2 | |
825 | #:xz xz | |
eaae07ec LC |
826 | #:package-name |
827 | %guix-package-name | |
828 | #:package-version | |
829 | version | |
830 | #:bug-report-address | |
831 | %guix-bug-report-address | |
832 | #:home-page-url | |
833 | %guix-home-page-url))) | |
834 | #:guile-for-build guile-for-build)) | |
835 | ||
a89faa3f | 836 | (define (built-modules node-subset) |
8a0d9bc8 | 837 | (directory-union (string-append name "-modules") |
a89faa3f | 838 | (append-map node-subset |
8a0d9bc8 LC |
839 | |
840 | ;; Note: *CONFIG* comes first so that it | |
841 | ;; overrides the (guix config) module that | |
842 | ;; comes with *CORE-MODULES*. | |
843 | (list *config* | |
844 | *cli-modules* | |
54800977 | 845 | *system-test-modules* |
8a0d9bc8 LC |
846 | *system-modules* |
847 | *package-modules* | |
848 | *core-package-modules* | |
849 | *extra-modules* | |
850 | *core-modules*)) | |
851 | ||
852 | ;; Silently choose the first entry upon collision so that | |
853 | ;; we choose *CONFIG*. | |
854 | #:resolve-collision 'first | |
855 | ||
856 | ;; When we do (add-to-store "utils.scm"), "utils.scm" must | |
857 | ;; be a regular file, not a symlink. Thus, arrange so that | |
858 | ;; regular files appear as regular files in the final | |
859 | ;; output. | |
860 | #:copy? #t | |
861 | #:quiet? #t)) | |
862 | ||
863 | ;; Version 0 of 'guix pull' meant we'd just return Scheme modules. | |
864 | ;; Version 1 is when we return the full package. | |
865 | (cond ((= 1 pull-version) | |
866 | ;; The whole package, with a standard file hierarchy. | |
49c35bbb LC |
867 | (let* ((modules (built-modules (compose list node-source+compiled))) |
868 | (command (guix-command modules | |
a89faa3f LC |
869 | #:source source |
870 | #:dependencies dependencies | |
8970a886 | 871 | #:guile guile-for-build |
a89faa3f LC |
872 | #:guile-version guile-version))) |
873 | (whole-package name modules dependencies | |
9f1c3559 | 874 | #:command command |
8970a886 | 875 | #:guile guile-for-build |
baed9236 LC |
876 | |
877 | ;; Include 'guix-daemon'. XXX: Here we inject an | |
878 | ;; older snapshot of guix-daemon, but that's a good | |
879 | ;; enough approximation for now. | |
880 | #:daemon (module-ref (resolve-interface | |
881 | '(gnu packages | |
882 | package-management)) | |
883 | 'guix-daemon) | |
884 | ||
4554d4c8 | 885 | #:info (info-manual source) |
e3744779 | 886 | #:miscellany (miscellaneous-files source) |
9f1c3559 | 887 | #:guile-version guile-version))) |
8a0d9bc8 | 888 | ((= 0 pull-version) |
a89faa3f LC |
889 | ;; Legacy 'guix pull': return the .scm and .go files as one |
890 | ;; directory. | |
891 | (built-modules (lambda (node) | |
892 | (list (node-source node) | |
893 | (node-compiled node))))) | |
8a0d9bc8 LC |
894 | (else |
895 | ;; Unsupported 'guix pull' version. | |
896 | #f))) | |
eaae07ec LC |
897 | |
898 | \f | |
899 | ;;; | |
900 | ;;; Generating (guix config). | |
901 | ;;; | |
902 | ||
eaae07ec LC |
903 | (define %persona-variables |
904 | ;; (guix config) variables that define Guix's persona. | |
905 | '(%guix-package-name | |
906 | %guix-version | |
907 | %guix-bug-report-address | |
908 | %guix-home-page-url)) | |
909 | ||
910 | (define %config-variables | |
45779fa6 LC |
911 | ;; (guix config) variables corresponding to Guix configuration. |
912 | (letrec-syntax ((variables (syntax-rules () | |
913 | ((_) | |
914 | '()) | |
915 | ((_ variable rest ...) | |
916 | (cons `(variable . ,variable) | |
917 | (variables rest ...)))))) | |
54eadc42 | 918 | (variables %localstatedir %storedir %sysconfdir))) |
eaae07ec | 919 | |
73ac9098 | 920 | (define* (make-config.scm #:key zlib lzlib gzip xz bzip2 |
eaae07ec LC |
921 | (package-name "GNU Guix") |
922 | (package-version "0") | |
923 | (bug-report-address "bug-guix@gnu.org") | |
3fb3291e | 924 | (home-page-url "https://guix.gnu.org")) |
eaae07ec LC |
925 | |
926 | ;; Hack so that Geiser is not confused. | |
927 | (define defmod 'define-module) | |
928 | ||
929 | (scheme-file "config.scm" | |
eb72cdf0 | 930 | #~(;; The following expressions get spliced. |
eaae07ec LC |
931 | (#$defmod (guix config) |
932 | #:export (%guix-package-name | |
933 | %guix-version | |
934 | %guix-bug-report-address | |
935 | %guix-home-page-url | |
54eadc42 | 936 | %system |
7af5c2a2 LC |
937 | %store-directory |
938 | %state-directory | |
939 | %store-database-directory | |
940 | %config-directory | |
eaae07ec | 941 | %libz |
73ac9098 | 942 | %liblz |
eaae07ec LC |
943 | %gzip |
944 | %bzip2 | |
e8cb9c01 | 945 | %xz)) |
eaae07ec | 946 | |
54eadc42 LC |
947 | (define %system |
948 | #$(%current-system)) | |
949 | ||
63cab418 LC |
950 | #$@(map (match-lambda |
951 | ((name . value) | |
952 | #~(define-public #$name #$value))) | |
953 | %config-variables) | |
954 | ||
7af5c2a2 LC |
955 | (define %store-directory |
956 | (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path) | |
957 | %storedir)) | |
958 | ||
959 | (define %state-directory | |
960 | ;; This must match `NIX_STATE_DIR' as defined in | |
961 | ;; `nix/local.mk'. | |
a87d66f3 | 962 | (or (getenv "GUIX_STATE_DIRECTORY") |
7af5c2a2 LC |
963 | (string-append %localstatedir "/guix"))) |
964 | ||
965 | (define %store-database-directory | |
a87d66f3 | 966 | (or (getenv "GUIX_DATABASE_DIRECTORY") |
7af5c2a2 LC |
967 | (string-append %state-directory "/db"))) |
968 | ||
969 | (define %config-directory | |
970 | ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as | |
971 | ;; defined in `nix/local.mk'. | |
972 | (or (getenv "GUIX_CONFIGURATION_DIRECTORY") | |
973 | (string-append %sysconfdir "/guix"))) | |
974 | ||
63cab418 LC |
975 | (define %guix-package-name #$package-name) |
976 | (define %guix-version #$package-version) | |
977 | (define %guix-bug-report-address #$bug-report-address) | |
978 | (define %guix-home-page-url #$home-page-url) | |
979 | ||
63cab418 LC |
980 | (define %gzip |
981 | #+(and gzip (file-append gzip "/bin/gzip"))) | |
982 | (define %bzip2 | |
983 | #+(and bzip2 (file-append bzip2 "/bin/bzip2"))) | |
984 | (define %xz | |
985 | #+(and xz (file-append xz "/bin/xz"))) | |
986 | ||
63cab418 LC |
987 | (define %libz |
988 | #+(and zlib | |
73ac9098 LC |
989 | (file-append zlib "/lib/libz"))) |
990 | ||
991 | (define %liblz | |
992 | #+(and lzlib | |
993 | (file-append lzlib "/lib/liblz")))) | |
eb72cdf0 LC |
994 | |
995 | ;; Guile 2.0 *requires* the 'define-module' to be at the | |
e8cb9c01 | 996 | ;; top-level or the 'toplevel-ref' in the resulting .go file are |
eb72cdf0 LC |
997 | ;; made relative to a nonexistent anonymous module. |
998 | #:splice? #t)) | |
eaae07ec | 999 | |
eaae07ec LC |
1000 | \f |
1001 | ;;; | |
1002 | ;;; Building. | |
1003 | ;;; | |
1004 | ||
8031b3fa | 1005 | (define* (compiled-modules name module-tree module-files |
eaae07ec LC |
1006 | #:optional |
1007 | (dependencies '()) | |
1008 | (dependencies-compiled '()) | |
1009 | #:key | |
1010 | (extensions '()) ;full-blown Guile packages | |
1011 | parallel? | |
1012 | guile-for-build) | |
8031b3fa LC |
1013 | "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list |
1014 | like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory | |
1015 | containing MODULE-FILES and possibly other files as well." | |
eaae07ec LC |
1016 | ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix |
1017 | ;; gexp). | |
1018 | (define build | |
1019 | (with-imported-modules (source-module-closure | |
1020 | '((guix build compile) | |
1021 | (guix build utils))) | |
1022 | #~(begin | |
1023 | (use-modules (srfi srfi-26) | |
1024 | (ice-9 match) | |
1025 | (ice-9 format) | |
1026 | (ice-9 threads) | |
1027 | (guix build compile) | |
1028 | (guix build utils)) | |
1029 | ||
1030 | (define (regular? file) | |
1031 | (not (member file '("." "..")))) | |
1032 | ||
1033 | (define (report-load file total completed) | |
1034 | (display #\cr) | |
1035 | (format #t | |
35dcaa11 LC |
1036 | "[~3@a/~3@a] loading...\t~5,1f% of ~d files" |
1037 | ||
1038 | ;; Note: Multiply TOTAL by two to account for the | |
1039 | ;; compilation phase that follows. | |
1040 | completed (* total 2) | |
1041 | ||
eaae07ec LC |
1042 | (* 100. (/ completed total)) total) |
1043 | (force-output)) | |
1044 | ||
1045 | (define (report-compilation file total completed) | |
1046 | (display #\cr) | |
35dcaa11 LC |
1047 | (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files" |
1048 | ||
1049 | ;; Add TOTAL to account for the load phase that came | |
1050 | ;; before. | |
1051 | (+ total completed) (* total 2) | |
1052 | ||
eaae07ec LC |
1053 | (* 100. (/ completed total)) total) |
1054 | (force-output)) | |
1055 | ||
8031b3fa LC |
1056 | (define (process-directory directory files output) |
1057 | ;; Hide compilation warnings. | |
1058 | (parameterize ((current-warning-port (%make-void-port "w"))) | |
1059 | (compile-files directory #$output files | |
1060 | #:workers (parallel-job-count) | |
1061 | #:report-load report-load | |
1062 | #:report-compilation report-compilation))) | |
eaae07ec | 1063 | |
35dcaa11 LC |
1064 | (setvbuf (current-output-port) 'line) |
1065 | (setvbuf (current-error-port) 'line) | |
eaae07ec LC |
1066 | |
1067 | (set! %load-path (cons #+module-tree %load-path)) | |
1068 | (set! %load-path | |
1069 | (append '#+dependencies | |
1070 | (map (lambda (extension) | |
1071 | (string-append extension "/share/guile/site/" | |
1072 | (effective-version))) | |
1073 | '#+extensions) | |
1074 | %load-path)) | |
1075 | ||
1076 | (set! %load-compiled-path | |
1077 | (append '#+dependencies-compiled | |
1078 | (map (lambda (extension) | |
1079 | (string-append extension "/lib/guile/" | |
1080 | (effective-version) | |
1081 | "/site-ccache")) | |
1082 | '#+extensions) | |
1083 | %load-compiled-path)) | |
1084 | ||
1085 | ;; Load the compiler modules upfront. | |
1086 | (compile #f) | |
1087 | ||
1088 | (mkdir #$output) | |
1089 | (chdir #+module-tree) | |
8031b3fa | 1090 | (process-directory "." '#+module-files #$output) |
69447b63 | 1091 | (newline)))) |
eaae07ec LC |
1092 | |
1093 | (computed-file name build | |
1094 | #:guile guile-for-build | |
1095 | #:options | |
1096 | `(#:local-build? #f ;allow substitutes | |
1097 | ||
1098 | ;; Don't annoy people about _IONBF deprecation. | |
54be2b4d LC |
1099 | ;; Initialize 'terminal-width' in (system repl debug) |
1100 | ;; to a large-enough value to make backtrace more | |
1101 | ;; verbose. | |
1102 | #:env-vars (("GUILE_WARN_DEPRECATED" . "no") | |
1103 | ("COLUMNS" . "200"))))) | |
eaae07ec LC |
1104 | |
1105 | \f | |
1106 | ;;; | |
1107 | ;;; Building. | |
1108 | ;;; | |
1109 | ||
eaae07ec | 1110 | (define* (guix-derivation source version |
8a0d9bc8 LC |
1111 | #:optional (guile-version (effective-version)) |
1112 | #:key (pull-version 0)) | |
eaae07ec | 1113 | "Return, as a monadic value, the derivation to build the Guix from SOURCE |
8a0d9bc8 LC |
1114 | for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies |
1115 | the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value | |
1116 | is not supported." | |
eaae07ec LC |
1117 | (define (shorten version) |
1118 | (if (and (string-every char-set:hex-digit version) | |
1119 | (> (string-length version) 9)) | |
1120 | (string-take version 9) ;Git commit | |
1121 | version)) | |
1122 | ||
1123 | (define guile | |
099bb017 LC |
1124 | ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2 |
1125 | ;; unconditionally. | |
6e54e488 LC |
1126 | (default-guile)) |
1127 | ||
1128 | (when (and (< pull-version 1) | |
1129 | (not (string=? (package-version guile) guile-version))) | |
1130 | ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and | |
1131 | ;; can be any version. When that happens and Guile is not current (e.g., | |
1132 | ;; it's Guile 2.0), just bail out. | |
1133 | (raise (condition | |
1134 | (&message | |
1135 | (message "Guix is too old and cannot be upgraded"))))) | |
eaae07ec LC |
1136 | |
1137 | (mbegin %store-monad | |
1138 | (set-guile-for-build guile) | |
8a0d9bc8 LC |
1139 | (let ((guix (compiled-guix source |
1140 | #:version version | |
1141 | #:name (string-append "guix-" | |
1142 | (shorten version)) | |
1143 | #:pull-version pull-version | |
099bb017 | 1144 | #:guile-version (if (>= pull-version 1) |
d02bb02f | 1145 | "2.2" guile-version) |
8a0d9bc8 LC |
1146 | #:guile-for-build guile))) |
1147 | (if guix | |
1148 | (lower-object guix) | |
1149 | (return #f))))) |