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