1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (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)
29 #:use-module (guix modules)
30 #:use-module ((guix build utils) #:select (find-files))
31 #:use-module ((guix build compile) #:select (%lightweight-optimizations))
32 #:use-module (srfi srfi-1)
33 #:use-module (srfi srfi-9)
34 #:use-module (srfi srfi-35)
35 #:use-module (ice-9 match)
36 #:export (make-config.scm
37 whole-package ;for internal use in 'guix pull'
43 ;;; Dependency handling.
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))))
52 ("guile" (ref '(gnu packages commencement) 'guile-final))
53 ("guile-json" (ref '(gnu packages guile) 'guile-json))
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))
57 ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
58 ("gnutls" (ref '(gnu packages tls) 'gnutls))
59 ("zlib" (ref '(gnu packages compression) 'zlib))
60 ("gzip" (ref '(gnu packages compression) 'gzip))
61 ("bzip2" (ref '(gnu packages compression) 'bzip2))
62 ("xz" (ref '(gnu packages compression) 'xz))
63 (_ #f)))) ;no such package
70 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
71 ;; easier to express things this way.
72 (define-record-type <node>
73 (node name modules source dependencies compiled)
75 (name node-name) ;string
76 (modules node-modules) ;list of module names
77 (source node-source) ;list of source files
78 (dependencies node-dependencies) ;list of nodes
79 (compiled node-compiled)) ;node -> lowerable object
81 ;; File mappings are essentially an alist as passed to 'imported-files'.
82 (define-record-type <file-mapping>
83 (file-mapping name alist)
85 (name file-mapping-name)
86 (alist file-mapping-alist))
88 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
90 ;; Here we use 'imported-files', which can arrange to directly import all
91 ;; the files instead of creating a derivation, when possible.
92 (imported-files (map (match-lambda
93 ((destination (? local-file? file))
95 (local-file-absolute-file-name file)))
97 (cons destination source))) ;silliness
98 (file-mapping-alist mapping))
99 #:name (file-mapping-name mapping)
102 (define (node-source+compiled node)
103 "Return a \"bundle\" containing both the source code and object files for
104 NODE's modules, under their FHS directories: share/guile/site and lib/guile."
106 (with-imported-modules '((guix build utils))
108 (use-modules (guix build utils))
111 (string-append #$output "/share/guile/site/"
112 (effective-version)))
115 (string-append #$output "/lib/guile/" (effective-version)
118 (mkdir-p (dirname source))
119 (symlink #$(node-source node) source)
120 (mkdir-p (dirname object))
121 (symlink #$(node-compiled node) object))))
123 (computed-file (string-append (node-name node) "-modules")
126 (define (node-fold proc init nodes)
127 (let loop ((nodes nodes)
133 (if (set-contains? visited head)
134 (loop tail visited result)
135 (loop tail (set-insert head visited)
136 (proc head result)))))))
138 (define (node-modules/recursive nodes)
139 (node-fold (lambda (node modules)
140 (append (node-modules node) modules))
144 (define* (closure modules #:optional (except '()))
145 (source-module-closure modules
151 (or ('guix _ ...) ('gnu _ ...)))
152 (not (member module except)))
155 (define module->import
156 ;; Return a file-name/file-like object pair for the specified module and
157 ;; suitable for 'imported-files'.
160 (let ((file (module-name->file-name module)))
163 (let ((file (module-name->file-name module)))
165 (local-file (search-path %load-path file)))))))
167 (define* (scheme-node name modules #:optional (dependencies '())
168 #:key (extra-modules '()) (extra-files '())
170 parallel? guile-for-build)
171 "Return a node that builds the given Scheme MODULES, and depends on
172 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
173 added to the source, and EXTRA-FILES is a list of additional files.
174 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
175 must be present in the search path."
176 (let* ((modules (append extra-modules
178 (node-modules/recursive dependencies))))
179 (module-files (map module->import modules))
180 (source (file-mapping (string-append name "-source")
181 (append module-files extra-files))))
182 (node name modules source dependencies
183 (compiled-modules name source
184 (map car module-files)
185 (map node-source dependencies)
186 (map node-compiled dependencies)
187 #:extensions extensions
188 #:parallel? parallel?
189 #:guile-for-build guile-for-build))))
191 (define (file-imports directory sub-directory pred)
192 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
193 list of file-name/file-like objects suitable as inputs to 'imported-files'."
195 (list (string-drop file (+ 1 (string-length directory)))
196 (local-file file #:recursive? #t)))
197 (find-files (string-append directory "/" sub-directory) pred)))
199 (define* (file-append* item file #:key (recursive? #t))
200 "Return FILE within ITEM, which may be a file name or a file-like object.
201 When ITEM is a plain file name (a string), simply return a 'local-file'
202 record with the new file name."
205 ;; This is the optimal case: we return a new "source". Thus, a
206 ;; derivation that depends on this sub-directory does not depend on ITEM
208 (local-file (string-append item "/" file)
209 #:recursive? recursive?))
210 ;; TODO: Add 'local-file?' case.
212 ;; In this case, anything that refers to the result also depends on ITEM,
213 ;; which isn't great.
214 (file-append item "/" file))))
216 (define* (locale-data source domain
217 #:optional (directory domain))
218 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
219 DOMAIN, a gettext domain."
221 (module-ref (resolve-interface '(gnu packages gettext))
225 (with-imported-modules '((guix build utils))
227 (use-modules (guix build utils)
229 (ice-9 match) (ice-9 ftw))
232 #+(file-append* source (string-append "po/" directory)))
234 (define (compile language)
235 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
237 (mkdir-p (dirname gmo))
238 (invoke #+(file-append gettext "/bin/msgfmt")
239 "-c" "--statistics" "--verbose"
241 (string-append po-directory "/" language ".po"))))
244 ;; Return the list of languages. Note: don't read 'LINGUAS'
245 ;; because it contains things like 'en@boldquot' that do not have
246 ;; a corresponding .po file.
247 (map (cut basename <> ".po")
248 (scandir po-directory
249 (cut string-suffix? ".po" <>))))
251 (for-each compile (linguas)))))
253 (computed-file (string-append "guix-locale-" domain)
256 (define (info-manual source)
257 "Return the Info manual built from SOURCE."
259 (module-ref (resolve-interface '(gnu packages texinfo))
263 (module-ref (resolve-interface '(gnu packages graphviz))
266 (define glibc-utf8-locales
267 (module-ref (resolve-interface '(gnu packages base))
268 'glibc-utf8-locales))
270 (define documentation
271 (file-append* source "doc"))
274 (file-append* source "gnu/system/examples"))
277 (with-imported-modules '((guix build utils))
279 (use-modules (guix build utils))
283 ;; Create 'version.texi'.
284 ;; XXX: Can we use a more meaningful version string yet one that
285 ;; doesn't change at each commit?
286 (call-with-output-file "version.texi"
288 (let ((version "0.0-git"))
290 @set UPDATED 1 January 1970
291 @set UPDATED-MONTH January 1970
293 @set VERSION ~a\n" version version))))
295 ;; Copy configuration templates that the manual includes.
296 (for-each (lambda (template)
300 (basename template ".tmpl")
302 (find-files #$examples "\\.tmpl$"))
305 (mkdir-p (string-append #$output "/images"))
306 (for-each (lambda (dot-file)
307 (invoke #+(file-append graphviz "/bin/dot")
308 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
309 "-Granksep=.00005" "-Nfontsize=9"
310 "-Nheight=.1" "-Nwidth=.1"
311 "-o" (string-append #$output "/images/"
312 (basename dot-file ".dot")
315 (find-files (string-append #$documentation "/images")
319 (for-each (lambda (png-file)
320 (install-file png-file
321 (string-append #$output "/images")))
322 (find-files (string-append #$documentation "/images")
325 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
326 ;; add a symlink to the 'images' directory so that 'makeinfo' can
327 ;; see those images and produce image references in the Info output.
328 (copy-recursively #$documentation "."
329 #:log (%make-void-port "w"))
330 (delete-file-recursively "images")
331 (symlink (string-append #$output "/images") "images")
333 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
334 (setenv "GUIX_LOCPATH"
335 #+(file-append glibc-utf8-locales "/lib/locale"))
337 (for-each (lambda (texi)
338 (unless (string=? "guix.texi" texi)
339 ;; Create 'version-LL.texi'.
340 (let* ((base (basename texi ".texi"))
341 (dot (string-index base #\.))
342 (tag (string-drop base (+ 1 dot))))
343 (symlink "version.texi"
344 (string-append "version-" tag ".texi"))))
346 (invoke #+(file-append texinfo "/bin/makeinfo")
347 texi "-I" #$documentation
349 "-o" (string-append #$output "/"
350 (basename texi ".texi")
353 (find-files "." "^guix\\.[a-z]{2}\\.texi$")))
355 ;; Compress Info files.
357 #+(file-append (specification->package "gzip") "/bin"))
358 (for-each (lambda (file)
359 (invoke "gzip" "-9n" file))
360 (find-files #$output "\\.info(-[0-9]+)?$")))))
362 (computed-file "guix-manual" build))
364 (define* (guile-module-union things #:key (name "guix-module-union"))
365 "Return the union of the subset of THINGS (packages, computed files, etc.)
366 that provide Guile modules."
368 (with-imported-modules '((guix build union))
370 (use-modules (guix build union))
372 (define (modules directory)
373 (string-append directory "/share/guile/site"))
375 (define (objects directory)
376 (string-append directory "/lib/guile"))
378 (union-build #$output
379 (filter (lambda (directory)
380 (or (file-exists? (modules directory))
381 (file-exists? (objects directory))))
384 #:log-port (%make-void-port "w")))))
386 (computed-file name build))
388 (define* (guix-command modules
389 #:key source (dependencies '())
390 guile (guile-version (effective-version)))
391 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
393 (define glibc-utf8-locales
394 (module-ref (resolve-interface '(gnu packages base))
395 'glibc-utf8-locales))
397 (define module-directory
398 ;; To minimize the number of 'stat' calls needed to locate a module,
399 ;; create the union of all the module directories.
400 (guile-module-union (cons modules dependencies)))
402 (program-file "guix-command"
405 (cons (string-append #$module-directory
410 (set! %load-compiled-path
411 (cons (string-append #$module-directory
415 %load-compiled-path))
417 ;; To maximize the chances that locales are set up right
418 ;; out-of-the-box, bundle "common" UTF-8 locales.
419 (let ((locpath (getenv "GUIX_LOCPATH")))
420 (setenv "GUIX_LOCPATH"
421 (string-append (if locpath
422 (string-append locpath ":")
424 #$(file-append glibc-utf8-locales
427 (let ((guix-main (module-ref (resolve-interface '(guix ui))
431 (bindtextdomain "guix"
432 #$(locale-data source "guix"))
433 (bindtextdomain "guix-packages"
434 #$(locale-data source
439 ;; XXX: It would be more convenient to change it to:
440 ;; (exit (apply guix-main (command-line)))
441 (apply guix-main (command-line))))
444 (define (miscellaneous-files source)
445 "Return data files taken from SOURCE."
446 (file-mapping "guix-misc"
447 `(("etc/bash_completion.d/guix"
448 ,(file-append* source "/etc/completion/bash/guix"))
449 ("etc/bash_completion.d/guix-daemon"
450 ,(file-append* source "/etc/completion/bash/guix-daemon"))
451 ("share/zsh/site-functions/_guix"
452 ,(file-append* source "/etc/completion/zsh/_guix"))
453 ("share/fish/vendor_completions.d/guix.fish"
454 ,(file-append* source "/etc/completion/fish/guix.fish"))
455 ("share/guix/hydra.gnu.org.pub"
456 ,(file-append* source
457 "/etc/substitutes/hydra.gnu.org.pub"))
458 ("share/guix/berlin.guixsd.org.pub"
459 ,(file-append* source
460 "/etc/substitutes/berlin.guixsd.org.pub"))
461 ("share/guix/ci.guix.info.pub" ;alias
462 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub")))))
464 (define* (whole-package name modules dependencies
466 (guile-version (effective-version))
467 info daemon miscellany
469 (command (guix-command modules
470 #:dependencies dependencies
472 #:guile-version guile-version)))
473 "Return the whole Guix package NAME that uses MODULES, a derivation of all
474 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
475 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
477 (define (wrap daemon)
478 (program-file "guix-daemon"
480 (setenv "GUIX" #$command)
481 (apply execl #$(file-append daemon "/bin/guix-daemon")
482 "guix-daemon" (cdr (command-line))))))
485 (with-imported-modules '((guix build utils))
487 (use-modules (guix build utils))
490 #$(and daemon (wrap daemon)))
492 (mkdir-p (string-append #$output "/bin"))
494 (string-append #$output "/bin/guix"))
498 (string-append #$output "/bin/guix-daemon")))
500 (let ((share (string-append #$output "/share"))
501 (lib (string-append #$output "/lib"))
504 (symlink #$(file-append modules "/share/guile")
505 (string-append share "/guile"))
507 (symlink #$info (string-append share "/info")))
510 (symlink #$(file-append modules "/lib/guile")
511 (string-append lib "/guile")))
514 (copy-recursively #$miscellany #$output
515 #:log (%make-void-port "w")))))))
517 (define* (compiled-guix source #:key (version %guix-version)
519 (name (string-append "guix-" version))
520 (guile-version (effective-version))
521 (guile-for-build (default-guile))
522 (zlib (specification->package "zlib"))
523 (gzip (specification->package "gzip"))
524 (bzip2 (specification->package "bzip2"))
525 (xz (specification->package "xz"))
526 (guix (specification->package "guix")))
527 "Return a file-like object that contains a compiled Guix."
529 (specification->package "guile-json"))
532 (specification->package "guile-ssh"))
535 (specification->package "guile-git"))
537 (define guile-sqlite3
538 (specification->package "guile-sqlite3"))
541 (specification->package "guile-gcrypt"))
544 (specification->package "gnutls"))
547 (match (append-map (lambda (package)
548 (cons (list "x" package)
549 (package-transitive-propagated-inputs package)))
550 (list guile-gcrypt gnutls guile-git guile-json
551 guile-ssh guile-sqlite3))
552 (((labels packages _ ...) ...)
555 (define *core-modules*
556 (scheme-node "guix-core"
563 (guix build-system gnu)
564 (guix build-system trivial)
565 (guix build profiles)
566 (guix build gnu-build-system))
568 ;; Provide a dummy (guix config) with the default version
569 ;; number, storedir, etc. This is so that "guix-core" is the
570 ;; same across all installations and doesn't need to be
571 ;; rebuilt when the version changes, which in turn means we
572 ;; can have substitutes for it.
574 `(((guix config) => ,(make-config.scm)))
576 ;; (guix man-db) is needed at build-time by (guix profiles)
577 ;; but we don't need to compile it; not compiling it allows
578 ;; us to avoid an extra dependency on guile-gdbm-ffi.
580 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
581 ("guix/store/schema.sql"
582 ,(local-file "../guix/store/schema.sql")))
584 #:extensions (list guile-gcrypt)
585 #:guile-for-build guile-for-build))
587 (define *extra-modules*
588 (scheme-node "guix-extra"
589 (filter-map (match-lambda
590 (('guix 'scripts _ ..1) #f)
593 (scheme-modules* source "guix"))
594 (list *core-modules*)
595 #:extensions dependencies
596 #:guile-for-build guile-for-build))
598 (define *core-package-modules*
599 (scheme-node "guix-packages-base"
602 (list *core-modules* *extra-modules*)
603 #:extensions dependencies
605 ;; Add all the non-Scheme files here. We must do it here so
606 ;; that 'search-patches' & co. can find them. Ideally we'd
607 ;; keep them next to the .scm files that use them but it's
608 ;; difficult to do (XXX).
610 (file-imports source "gnu/packages"
612 (and (eq? 'regular (stat:type stat))
613 (not (string-suffix? ".scm" file))
614 (not (string-suffix? ".go" file))
615 (not (string-prefix? ".#" file))
616 (not (string-suffix? "~" file)))))
617 #:guile-for-build guile-for-build))
619 (define *package-modules*
620 (scheme-node "guix-packages"
621 (scheme-modules* source "gnu/packages")
622 (list *core-modules* *extra-modules* *core-package-modules*)
623 #:extensions dependencies
624 #:guile-for-build guile-for-build))
626 (define *system-modules*
627 (scheme-node "guix-system"
630 ,@(scheme-modules* source "gnu/bootloader")
631 ,@(scheme-modules* source "gnu/system")
632 ,@(scheme-modules* source "gnu/services"))
633 (list *core-package-modules* *package-modules*
634 *extra-modules* *core-modules*)
635 #:extensions dependencies
637 (append (file-imports source "gnu/system/examples"
640 ;; All the installer code is on the build-side.
641 (file-imports source "gnu/installer/"
643 ;; Build-side code that we don't build. Some of
644 ;; these depend on guile-rsvg, the Shepherd, etc.
645 (file-imports source "gnu/build" (const #t)))
649 (define *cli-modules*
650 (scheme-node "guix-cli"
651 (append (scheme-modules* source "/guix/scripts")
653 (list *core-modules* *extra-modules*
654 *core-package-modules* *package-modules*
656 #:extensions dependencies
657 #:guile-for-build guile-for-build))
659 (define *system-test-modules*
660 ;; Ship these modules mostly so (gnu ci) can discover them.
661 (scheme-node "guix-system-tests"
663 ,@(scheme-modules* source "gnu/tests"))
664 (list *core-package-modules* *package-modules*
665 *extra-modules* *system-modules* *core-modules*
666 *cli-modules*) ;for (guix scripts pack), etc.
667 #:extensions dependencies
668 #:guile-for-build guile-for-build))
671 (scheme-node "guix-config"
675 => ,(make-config.scm #:zlib zlib
684 %guix-bug-report-address
686 %guix-home-page-url)))
687 #:guile-for-build guile-for-build))
689 (define (built-modules node-subset)
690 (directory-union (string-append name "-modules")
691 (append-map node-subset
693 ;; Note: *CONFIG* comes first so that it
694 ;; overrides the (guix config) module that
695 ;; comes with *CORE-MODULES*.
698 *system-test-modules*
701 *core-package-modules*
705 ;; Silently choose the first entry upon collision so that
706 ;; we choose *CONFIG*.
707 #:resolve-collision 'first
709 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
710 ;; be a regular file, not a symlink. Thus, arrange so that
711 ;; regular files appear as regular files in the final
716 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
717 ;; Version 1 is when we return the full package.
718 (cond ((= 1 pull-version)
719 ;; The whole package, with a standard file hierarchy.
720 (let* ((modules (built-modules (compose list node-source+compiled)))
721 (command (guix-command modules
723 #:dependencies dependencies
724 #:guile guile-for-build
725 #:guile-version guile-version)))
726 (whole-package name modules dependencies
728 #:guile guile-for-build
730 ;; Include 'guix-daemon'. XXX: Here we inject an
731 ;; older snapshot of guix-daemon, but that's a good
732 ;; enough approximation for now.
733 #:daemon (module-ref (resolve-interface
738 #:info (info-manual source)
739 #:miscellany (miscellaneous-files source)
740 #:guile-version guile-version)))
742 ;; Legacy 'guix pull': return the .scm and .go files as one
744 (built-modules (lambda (node)
745 (list (node-source node)
746 (node-compiled node)))))
748 ;; Unsupported 'guix pull' version.
753 ;;; Generating (guix config).
756 (define %dependency-variables
757 ;; (guix config) variables corresponding to dependencies.
758 '(%libz %xz %gzip %bzip2))
760 (define %persona-variables
761 ;; (guix config) variables that define Guix's persona.
764 %guix-bug-report-address
765 %guix-home-page-url))
767 (define %config-variables
768 ;; (guix config) variables corresponding to Guix configuration.
769 (letrec-syntax ((variables (syntax-rules ()
772 ((_ variable rest ...)
773 (cons `(variable . ,variable)
774 (variables rest ...))))))
775 (variables %localstatedir %storedir %sysconfdir)))
777 (define* (make-config.scm #:key zlib gzip xz bzip2
778 (package-name "GNU Guix")
779 (package-version "0")
780 (bug-report-address "bug-guix@gnu.org")
781 (home-page-url "https://gnu.org/s/guix"))
783 ;; Hack so that Geiser is not confused.
784 (define defmod 'define-module)
786 (scheme-file "config.scm"
787 #~(;; The following expressions get spliced.
788 (#$defmod (guix config)
789 #:export (%guix-package-name
791 %guix-bug-report-address
796 %store-database-directory
806 #$@(map (match-lambda
808 #~(define-public #$name #$value)))
811 (define %store-directory
812 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
815 (define %state-directory
816 ;; This must match `NIX_STATE_DIR' as defined in
818 (or (getenv "GUIX_STATE_DIRECTORY")
819 (string-append %localstatedir "/guix")))
821 (define %store-database-directory
822 (or (getenv "GUIX_DATABASE_DIRECTORY")
823 (string-append %state-directory "/db")))
825 (define %config-directory
826 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
827 ;; defined in `nix/local.mk'.
828 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
829 (string-append %sysconfdir "/guix")))
831 (define %guix-package-name #$package-name)
832 (define %guix-version #$package-version)
833 (define %guix-bug-report-address #$bug-report-address)
834 (define %guix-home-page-url #$home-page-url)
837 #+(and gzip (file-append gzip "/bin/gzip")))
839 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
841 #+(and xz (file-append xz "/bin/xz")))
845 (file-append zlib "/lib/libz"))))
847 ;; Guile 2.0 *requires* the 'define-module' to be at the
848 ;; top-level or the 'toplevel-ref' in the resulting .go file are
849 ;; made relative to a nonexistent anonymous module.
857 (define* (compiled-modules name module-tree module-files
860 (dependencies-compiled '())
862 (extensions '()) ;full-blown Guile packages
865 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
866 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
867 containing MODULE-FILES and possibly other files as well."
868 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
871 (with-imported-modules (source-module-closure
872 '((guix build compile)
875 (use-modules (srfi srfi-26)
882 (define (regular? file)
883 (not (member file '("." ".."))))
885 (define (report-load file total completed)
888 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
890 ;; Note: Multiply TOTAL by two to account for the
891 ;; compilation phase that follows.
892 completed (* total 2)
894 (* 100. (/ completed total)) total)
897 (define (report-compilation file total completed)
899 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
901 ;; Add TOTAL to account for the load phase that came
903 (+ total completed) (* total 2)
905 (* 100. (/ completed total)) total)
908 (define (process-directory directory files output)
909 ;; Hide compilation warnings.
910 (parameterize ((current-warning-port (%make-void-port "w")))
911 (compile-files directory #$output files
912 #:workers (parallel-job-count)
913 #:report-load report-load
914 #:report-compilation report-compilation)))
916 (setvbuf (current-output-port) 'line)
917 (setvbuf (current-error-port) 'line)
919 (set! %load-path (cons #+module-tree %load-path))
921 (append '#+dependencies
922 (map (lambda (extension)
923 (string-append extension "/share/guile/site/"
924 (effective-version)))
928 (set! %load-compiled-path
929 (append '#+dependencies-compiled
930 (map (lambda (extension)
931 (string-append extension "/lib/guile/"
935 %load-compiled-path))
937 ;; Load the compiler modules upfront.
941 (chdir #+module-tree)
942 (process-directory "." '#+module-files #$output)
945 (computed-file name build
946 #:guile guile-for-build
948 `(#:local-build? #f ;allow substitutes
950 ;; Don't annoy people about _IONBF deprecation.
951 ;; Initialize 'terminal-width' in (system repl debug)
952 ;; to a large-enough value to make backtrace more
954 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
955 ("COLUMNS" . "200")))))
962 (define* (guix-derivation source version
963 #:optional (guile-version (effective-version))
964 #:key (pull-version 0))
965 "Return, as a monadic value, the derivation to build the Guix from SOURCE
966 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
967 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
969 (define (shorten version)
970 (if (and (string-every char-set:hex-digit version)
971 (> (string-length version) 9))
972 (string-take version 9) ;Git commit
976 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2
980 (when (and (< pull-version 1)
981 (not (string=? (package-version guile) guile-version)))
982 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
983 ;; can be any version. When that happens and Guile is not current (e.g.,
984 ;; it's Guile 2.0), just bail out.
987 (message "Guix is too old and cannot be upgraded")))))
990 (set-guile-for-build guile)
991 (let ((guix (compiled-guix source
993 #:name (string-append "guix-"
995 #:pull-version pull-version
996 #:guile-version (if (>= pull-version 1)
998 #:guile-for-build guile)))