1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 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 (ice-9 match)
35 #:export (make-config.scm
36 whole-package ;for internal use in 'guix pull'
43 ;;; Dependency handling.
46 (define* (false-if-wrong-guile package
47 #:optional (guile-version (effective-version)))
48 "Return #f if PACKAGE depends on the \"wrong\" major version of Guile (e.g.,
49 2.0 instead of 2.2), otherwise return PACKAGE."
50 (let ((guile (any (match-lambda
51 ((label (? package? dep) _ ...)
52 (and (string=? (package-name dep) "guile")
54 (package-direct-inputs package))))
56 (string-prefix? guile-version
57 (package-version guile)))
60 (define (package-for-guile guile-version . names)
61 "Return the package with one of the given NAMES that depends on
62 GUILE-VERSION (\"2.0\" or \"2.2\"), or #f if none of the packages matches."
63 (let loop ((names names))
68 (match (specification->package name)
72 (or (false-if-wrong-guile package guile-version)
75 (define specification->package
76 ;; Use our own variant of that procedure because that of (gnu packages)
77 ;; would traverse all the .scm files, which is wasteful.
78 (let ((ref (lambda (module variable)
79 (module-ref (resolve-interface module) variable))))
81 ("guile" (ref '(gnu packages commencement) 'guile-final))
82 ("guile-json" (ref '(gnu packages guile) 'guile-json))
83 ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh))
84 ("guile-git" (ref '(gnu packages guile) 'guile-git))
85 ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3))
86 ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
87 ("gnutls" (ref '(gnu packages tls) 'gnutls))
88 ("zlib" (ref '(gnu packages compression) 'zlib))
89 ("gzip" (ref '(gnu packages compression) 'gzip))
90 ("bzip2" (ref '(gnu packages compression) 'bzip2))
91 ("xz" (ref '(gnu packages compression) 'xz))
92 ("guile2.0-json" (ref '(gnu packages guile) 'guile2.0-json))
93 ("guile2.0-ssh" (ref '(gnu packages ssh) 'guile2.0-ssh))
94 ("guile2.0-git" (ref '(gnu packages guile) 'guile2.0-git))
95 ;; XXX: No "guile2.0-sqlite3".
96 ("guile2.0-gnutls" (ref '(gnu packages tls) 'gnutls/guile-2.0))
97 (_ #f)))) ;no such package
104 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
105 ;; easier to express things this way.
106 (define-record-type <node>
107 (node name modules source dependencies compiled)
109 (name node-name) ;string
110 (modules node-modules) ;list of module names
111 (source node-source) ;list of source files
112 (dependencies node-dependencies) ;list of nodes
113 (compiled node-compiled)) ;node -> lowerable object
115 ;; File mappings are essentially an alist as passed to 'imported-files'.
116 (define-record-type <file-mapping>
117 (file-mapping name alist)
119 (name file-mapping-name)
120 (alist file-mapping-alist))
122 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
124 ;; Here we use 'imported-files', which can arrange to directly import all
125 ;; the files instead of creating a derivation, when possible.
126 (imported-files (map (match-lambda
127 ((destination (? local-file? file))
129 (local-file-absolute-file-name file)))
130 ((destination source)
131 (cons destination source))) ;silliness
132 (file-mapping-alist mapping))
133 #:name (file-mapping-name mapping)
136 (define (node-fold proc init nodes)
137 (let loop ((nodes nodes)
143 (if (set-contains? visited head)
144 (loop tail visited result)
145 (loop tail (set-insert head visited)
146 (proc head result)))))))
148 (define (node-modules/recursive nodes)
149 (node-fold (lambda (node modules)
150 (append (node-modules node) modules))
154 (define* (closure modules #:optional (except '()))
155 (source-module-closure modules
161 (or ('guix _ ...) ('gnu _ ...)))
162 (not (member module except)))
165 (define module->import
166 ;; Return a file-name/file-like object pair for the specified module and
167 ;; suitable for 'imported-files'.
170 (let ((file (module-name->file-name module)))
173 (let ((file (module-name->file-name module)))
175 (local-file (search-path %load-path file)))))))
177 (define* (scheme-node name modules #:optional (dependencies '())
178 #:key (extra-modules '()) (extra-files '())
180 parallel? guile-for-build)
181 "Return a node that builds the given Scheme MODULES, and depends on
182 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
183 added to the source, and EXTRA-FILES is a list of additional files.
184 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
185 must be present in the search path."
186 (let* ((modules (append extra-modules
188 (node-modules/recursive dependencies))))
189 (module-files (map module->import modules))
190 (source (file-mapping (string-append name "-source")
191 (append module-files extra-files))))
192 (node name modules source dependencies
193 (compiled-modules name source
194 (map car module-files)
195 (map node-source dependencies)
196 (map node-compiled dependencies)
197 #:extensions extensions
198 #:parallel? parallel?
199 #:guile-for-build guile-for-build))))
201 (define (file-imports directory sub-directory pred)
202 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
203 list of file-name/file-like objects suitable as inputs to 'imported-files'."
205 (list (string-drop file (+ 1 (string-length directory)))
206 (local-file file #:recursive? #t)))
207 (find-files (string-append directory "/" sub-directory) pred)))
209 (define* (file-append* item file #:key (recursive? #t))
210 "Return FILE within ITEM, which may be a file name or a file-like object.
211 When ITEM is a plain file name (a string), simply return a 'local-file'
212 record with the new file name."
215 ;; This is the optimal case: we return a new "source". Thus, a
216 ;; derivation that depends on this sub-directory does not depend on ITEM
218 (local-file (string-append item "/" file)
219 #:recursive? recursive?))
220 ;; TODO: Add 'local-file?' case.
222 ;; In this case, anything that refers to the result also depends on ITEM,
223 ;; which isn't great.
224 (file-append item "/" file))))
226 (define* (locale-data source domain
227 #:optional (directory domain))
228 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
229 DOMAIN, a gettext domain."
231 (module-ref (resolve-interface '(gnu packages gettext))
235 (with-imported-modules '((guix build utils))
237 (use-modules (guix build utils)
239 (ice-9 match) (ice-9 ftw))
242 #+(file-append* source (string-append "po/" directory)))
244 (define (compile language)
245 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
247 (mkdir-p (dirname gmo))
248 (invoke #+(file-append gettext "/bin/msgfmt")
249 "-c" "--statistics" "--verbose"
251 (string-append po-directory "/" language ".po"))))
254 ;; Return the list of languages. Note: don't read 'LINGUAS'
255 ;; because it contains things like 'en@boldquot' that do not have
256 ;; a corresponding .po file.
257 (map (cut basename <> ".po")
258 (scandir po-directory
259 (cut string-suffix? ".po" <>))))
261 (for-each compile (linguas)))))
263 (computed-file (string-append "guix-locale-" domain)
266 (define (info-manual source)
267 "Return the Info manual built from SOURCE."
269 (module-ref (resolve-interface '(gnu packages texinfo))
273 (module-ref (resolve-interface '(gnu packages graphviz))
276 (define glibc-utf8-locales
277 (module-ref (resolve-interface '(gnu packages base))
278 'glibc-utf8-locales))
280 (define documentation
281 (file-append* source "doc"))
284 (file-append* source "gnu/system/examples"))
287 (with-imported-modules '((guix build utils))
289 (use-modules (guix build utils))
293 ;; Create 'version.texi'.
294 ;; XXX: Can we use a more meaningful version string yet one that
295 ;; doesn't change at each commit?
296 (call-with-output-file "version.texi"
298 (let ((version "0.0-git"))
300 @set UPDATED 1 January 1970
301 @set UPDATED-MONTH January 1970
303 @set VERSION ~a\n" version version))))
305 ;; Copy configuration templates that the manual includes.
306 (for-each (lambda (template)
310 (basename template ".tmpl")
312 (find-files #$examples "\\.tmpl$"))
315 (mkdir-p (string-append #$output "/images"))
316 (for-each (lambda (dot-file)
317 (invoke #+(file-append graphviz "/bin/dot")
318 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
319 "-Granksep=.00005" "-Nfontsize=9"
320 "-Nheight=.1" "-Nwidth=.1"
321 "-o" (string-append #$output "/images/"
322 (basename dot-file ".dot")
325 (find-files (string-append #$documentation "/images")
329 (for-each (lambda (png-file)
330 (install-file png-file
331 (string-append #$output "/images")))
332 (find-files (string-append #$documentation "/images")
335 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
336 ;; add a symlink to the 'images' directory so that 'makeinfo' can
337 ;; see those images and produce image references in the Info output.
338 (copy-recursively #$documentation "."
339 #:log (%make-void-port "w"))
340 (delete-file-recursively "images")
341 (symlink (string-append #$output "/images") "images")
343 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
344 (setenv "GUIX_LOCPATH"
345 #+(file-append glibc-utf8-locales "/lib/locale"))
347 (for-each (lambda (texi)
348 (unless (string=? "guix.texi" texi)
349 ;; Create 'version-LL.texi'.
350 (let* ((base (basename texi ".texi"))
351 (dot (string-index base #\.))
352 (tag (string-drop base (+ 1 dot))))
353 (symlink "version.texi"
354 (string-append "version-" tag ".texi"))))
356 (invoke #+(file-append texinfo "/bin/makeinfo")
357 texi "-I" #$documentation
359 "-o" (string-append #$output "/"
360 (basename texi ".texi")
363 (find-files "." "^guix\\.[a-z]{2}\\.texi$"))))))
365 (computed-file "guix-manual" build))
367 (define* (guix-command modules #:optional compiled-modules
368 #:key source (dependencies '())
369 guile (guile-version (effective-version)))
370 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
372 (define source-directories
373 (map (lambda (package)
374 (file-append package "/share/guile/site/"
378 (define object-directories
379 (map (lambda (package)
380 (file-append package "/lib/guile/"
381 guile-version "/site-ccache"))
384 (program-file "guix-command"
387 (append (filter file-exists? '#$source-directories)
390 (set! %load-compiled-path
391 (append (filter file-exists? '#$object-directories)
392 %load-compiled-path))
394 (set! %load-path (cons #$modules %load-path))
395 (set! %load-compiled-path
396 (cons (or #$compiled-modules #$modules)
397 %load-compiled-path))
399 (let ((guix-main (module-ref (resolve-interface '(guix ui))
403 (bindtextdomain "guix"
404 #$(locale-data source "guix"))
405 (bindtextdomain "guix-packages"
406 #$(locale-data source
411 ;; XXX: It would be more convenient to change it to:
412 ;; (exit (apply guix-main (command-line)))
413 (apply guix-main (command-line))))
416 (define (miscellaneous-files source)
417 "Return data files taken from SOURCE."
418 (file-mapping "guix-misc"
419 `(("etc/bash_completion.d/guix"
420 ,(file-append* source "/etc/completion/bash/guix"))
421 ("etc/bash_completion.d/guix-daemon"
422 ,(file-append* source "/etc/completion/bash/guix-daemon"))
423 ("share/zsh/site-functions/_guix"
424 ,(file-append* source "/etc/completion/zsh/_guix"))
425 ("share/fish/vendor_completions.d/guix.fish"
426 ,(file-append* source "/etc/completion/fish/guix.fish"))
427 ("share/guix/hydra.gnu.org.pub"
428 ,(file-append* source
429 "/etc/substitutes/hydra.gnu.org.pub"))
430 ("share/guix/berlin.guixsd.org.pub"
431 ,(file-append* source
432 "/etc/substitutes/berlin.guixsd.org.pub"))
433 ("share/guix/ci.guix.info.pub" ;alias
434 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub")))))
436 (define* (whole-package name modules dependencies
438 (guile-version (effective-version))
440 info daemon miscellany
442 (command (guix-command modules
443 #:dependencies dependencies
445 #:guile-version guile-version)))
446 "Return the whole Guix package NAME that uses MODULES, a derivation of all
447 the modules, and DEPENDENCIES, a list of packages depended on. COMMAND is the
448 'guix' program to use; INFO is the Info manual. When COMPILED-MODULES is
449 true, it is linked as 'lib/guile/X.Y/site-ccache'; otherwise, .go files are
450 assumed to be part of MODULES."
452 (with-imported-modules '((guix build utils))
454 (use-modules (guix build utils))
456 (mkdir-p (string-append #$output "/bin"))
458 (string-append #$output "/bin/guix"))
461 (symlink (string-append #$daemon "/bin/guix-daemon")
462 (string-append #$output "/bin/guix-daemon")))
464 (let ((modules (string-append #$output
466 (effective-version)))
468 (mkdir-p (dirname modules))
469 (symlink #$modules modules)
472 (string-append #$output
476 (copy-recursively #$miscellany #$output
477 #:log (%make-void-port "w")))
480 (when #$compiled-modules
481 (let ((modules (string-append #$output "/lib/guile/"
484 (mkdir-p (dirname modules))
485 (symlink #$compiled-modules modules)))))))
487 (define* (compiled-guix source #:key (version %guix-version)
489 (name (string-append "guix-" version))
490 (guile-version (effective-version))
491 (guile-for-build (guile-for-build guile-version))
492 (zlib (specification->package "zlib"))
493 (gzip (specification->package "gzip"))
494 (bzip2 (specification->package "bzip2"))
495 (xz (specification->package "xz"))
496 (guix (specification->package "guix")))
497 "Return a file-like object that contains a compiled Guix."
499 (package-for-guile guile-version
504 (package-for-guile guile-version
509 (package-for-guile guile-version
513 (define guile-sqlite3
514 (package-for-guile guile-version
519 (package-for-guile guile-version
523 (package-for-guile guile-version
524 "gnutls" "guile2.0-gnutls"))
527 (match (append-map (lambda (package)
528 (cons (list "x" package)
529 (package-transitive-propagated-inputs package)))
530 (list guile-gcrypt gnutls guile-git guile-json
531 guile-ssh guile-sqlite3))
532 (((labels packages _ ...) ...)
535 (define *core-modules*
536 (scheme-node "guix-core"
543 (guix build-system gnu)
544 (guix build-system trivial)
545 (guix build profiles)
546 (guix build gnu-build-system))
548 ;; Provide a dummy (guix config) with the default version
549 ;; number, storedir, etc. This is so that "guix-core" is the
550 ;; same across all installations and doesn't need to be
551 ;; rebuilt when the version changes, which in turn means we
552 ;; can have substitutes for it.
554 `(((guix config) => ,(make-config.scm)))
556 ;; (guix man-db) is needed at build-time by (guix profiles)
557 ;; but we don't need to compile it; not compiling it allows
558 ;; us to avoid an extra dependency on guile-gdbm-ffi.
560 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
561 ("guix/store/schema.sql"
562 ,(local-file "../guix/store/schema.sql")))
564 #:extensions (list guile-gcrypt)
565 #:guile-for-build guile-for-build))
567 (define *extra-modules*
568 (scheme-node "guix-extra"
569 (filter-map (match-lambda
570 (('guix 'scripts _ ..1) #f)
573 (scheme-modules* source "guix"))
574 (list *core-modules*)
575 #:extensions dependencies
576 #:guile-for-build guile-for-build))
578 (define *core-package-modules*
579 (scheme-node "guix-packages-base"
582 (list *core-modules* *extra-modules*)
583 #:extensions dependencies
585 ;; Add all the non-Scheme files here. We must do it here so
586 ;; that 'search-patches' & co. can find them. Ideally we'd
587 ;; keep them next to the .scm files that use them but it's
588 ;; difficult to do (XXX).
590 (file-imports source "gnu/packages"
592 (and (eq? 'regular (stat:type stat))
593 (not (string-suffix? ".scm" file))
594 (not (string-suffix? ".go" file))
595 (not (string-prefix? ".#" file))
596 (not (string-suffix? "~" file)))))
597 #:guile-for-build guile-for-build))
599 (define *package-modules*
600 (scheme-node "guix-packages"
601 (scheme-modules* source "gnu/packages")
602 (list *core-modules* *extra-modules* *core-package-modules*)
603 #:extensions dependencies
604 #:guile-for-build guile-for-build))
606 (define *system-modules*
607 (scheme-node "guix-system"
610 ,@(scheme-modules* source "gnu/system")
611 ,@(scheme-modules* source "gnu/services"))
612 (list *core-package-modules* *package-modules*
613 *extra-modules* *core-modules*)
614 #:extensions dependencies
616 (append (file-imports source "gnu/system/examples"
619 ;; Build-side code that we don't build. Some of
620 ;; these depend on guile-rsvg, the Shepherd, etc.
621 (file-imports source "gnu/build" (const #t)))
625 (define *cli-modules*
626 (scheme-node "guix-cli"
627 (scheme-modules* source "/guix/scripts")
628 (list *core-modules* *extra-modules*
629 *core-package-modules* *package-modules*
631 #:extensions dependencies
632 #:guile-for-build guile-for-build))
635 (scheme-node "guix-config"
639 => ,(make-config.scm #:zlib zlib
648 %guix-bug-report-address
650 %guix-home-page-url)))
651 #:guile-for-build guile-for-build))
653 (define (built-modules node-subset)
654 (directory-union (string-append name "-modules")
655 (append-map node-subset
657 ;; Note: *CONFIG* comes first so that it
658 ;; overrides the (guix config) module that
659 ;; comes with *CORE-MODULES*.
664 *core-package-modules*
668 ;; Silently choose the first entry upon collision so that
669 ;; we choose *CONFIG*.
670 #:resolve-collision 'first
672 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
673 ;; be a regular file, not a symlink. Thus, arrange so that
674 ;; regular files appear as regular files in the final
679 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
680 ;; Version 1 is when we return the full package.
681 (cond ((= 1 pull-version)
682 ;; The whole package, with a standard file hierarchy.
683 (let* ((modules (built-modules (compose list node-source)))
684 (compiled (built-modules (compose list node-compiled)))
685 (command (guix-command modules compiled
687 #:dependencies dependencies
688 #:guile guile-for-build
689 #:guile-version guile-version)))
690 (whole-package name modules dependencies
691 #:compiled-modules compiled
693 #:guile guile-for-build
695 ;; Include 'guix-daemon'. XXX: Here we inject an
696 ;; older snapshot of guix-daemon, but that's a good
697 ;; enough approximation for now.
698 #:daemon (module-ref (resolve-interface
703 #:info (info-manual source)
704 #:miscellany (miscellaneous-files source)
705 #:guile-version guile-version)))
707 ;; Legacy 'guix pull': return the .scm and .go files as one
709 (built-modules (lambda (node)
710 (list (node-source node)
711 (node-compiled node)))))
713 ;; Unsupported 'guix pull' version.
718 ;;; Generating (guix config).
721 (define %dependency-variables
722 ;; (guix config) variables corresponding to dependencies.
723 '(%libz %xz %gzip %bzip2))
725 (define %persona-variables
726 ;; (guix config) variables that define Guix's persona.
729 %guix-bug-report-address
730 %guix-home-page-url))
732 (define %config-variables
733 ;; (guix config) variables corresponding to Guix configuration.
734 (letrec-syntax ((variables (syntax-rules ()
737 ((_ variable rest ...)
738 (cons `(variable . ,variable)
739 (variables rest ...))))))
740 (variables %localstatedir %storedir %sysconfdir %system)))
742 (define* (make-config.scm #:key zlib gzip xz bzip2
743 (package-name "GNU Guix")
744 (package-version "0")
745 (bug-report-address "bug-guix@gnu.org")
746 (home-page-url "https://gnu.org/s/guix"))
748 ;; Hack so that Geiser is not confused.
749 (define defmod 'define-module)
751 (scheme-file "config.scm"
752 #~(;; The following expressions get spliced.
753 (#$defmod (guix config)
754 #:export (%guix-package-name
756 %guix-bug-report-address
760 %store-database-directory
767 #$@(map (match-lambda
769 #~(define-public #$name #$value)))
772 (define %store-directory
773 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
776 (define %state-directory
777 ;; This must match `NIX_STATE_DIR' as defined in
779 (or (getenv "NIX_STATE_DIR")
780 (string-append %localstatedir "/guix")))
782 (define %store-database-directory
783 (or (getenv "NIX_DB_DIR")
784 (string-append %state-directory "/db")))
786 (define %config-directory
787 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
788 ;; defined in `nix/local.mk'.
789 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
790 (string-append %sysconfdir "/guix")))
792 (define %guix-package-name #$package-name)
793 (define %guix-version #$package-version)
794 (define %guix-bug-report-address #$bug-report-address)
795 (define %guix-home-page-url #$home-page-url)
798 #+(and gzip (file-append gzip "/bin/gzip")))
800 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
802 #+(and xz (file-append xz "/bin/xz")))
806 (file-append zlib "/lib/libz"))))
808 ;; Guile 2.0 *requires* the 'define-module' to be at the
809 ;; top-level or the 'toplevel-ref' in the resulting .go file are
810 ;; made relative to a nonexistent anonymous module.
819 (define* (compiled-modules name module-tree module-files
822 (dependencies-compiled '())
824 (extensions '()) ;full-blown Guile packages
827 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
828 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
829 containing MODULE-FILES and possibly other files as well."
830 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
833 (with-imported-modules (source-module-closure
834 '((guix build compile)
837 (use-modules (srfi srfi-26)
844 (define (regular? file)
845 (not (member file '("." ".."))))
847 (define (report-load file total completed)
850 "loading...\t~5,1f% of ~d files" ;FIXME: i18n
851 (* 100. (/ completed total)) total)
854 (define (report-compilation file total completed)
856 (format #t "compiling...\t~5,1f% of ~d files" ;FIXME: i18n
857 (* 100. (/ completed total)) total)
860 (define (process-directory directory files output)
861 ;; Hide compilation warnings.
862 (parameterize ((current-warning-port (%make-void-port "w")))
863 (compile-files directory #$output files
864 #:workers (parallel-job-count)
865 #:report-load report-load
866 #:report-compilation report-compilation)))
868 (setvbuf (current-output-port) _IONBF)
869 (setvbuf (current-error-port) _IONBF)
871 (set! %load-path (cons #+module-tree %load-path))
873 (append '#+dependencies
874 (map (lambda (extension)
875 (string-append extension "/share/guile/site/"
876 (effective-version)))
880 (set! %load-compiled-path
881 (append '#+dependencies-compiled
882 (map (lambda (extension)
883 (string-append extension "/lib/guile/"
887 %load-compiled-path))
889 ;; Load the compiler modules upfront.
893 (chdir #+module-tree)
894 (process-directory "." '#+module-files #$output)
897 (computed-file name build
898 #:guile guile-for-build
900 `(#:local-build? #f ;allow substitutes
902 ;; Don't annoy people about _IONBF deprecation.
903 ;; Initialize 'terminal-width' in (system repl debug)
904 ;; to a large-enough value to make backtrace more
906 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
907 ("COLUMNS" . "200")))))
914 (define (guile-for-build version)
915 "Return a derivation for Guile 2.0 or 2.2, whichever matches the currently
917 (define canonical-package ;soft reference
918 (module-ref (resolve-interface '(gnu packages base))
923 (canonical-package (module-ref (resolve-interface '(gnu packages guile))
926 (module-ref (resolve-interface '(gnu packages guile))
929 (define* (guix-derivation source version
930 #:optional (guile-version (effective-version))
931 #:key (pull-version 0))
932 "Return, as a monadic value, the derivation to build the Guix from SOURCE
933 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
934 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
936 (define (shorten version)
937 (if (and (string-every char-set:hex-digit version)
938 (> (string-length version) 9))
939 (string-take version 9) ;Git commit
943 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2
945 (guile-for-build (if (>= pull-version 1)
950 (set-guile-for-build guile)
951 (let ((guix (compiled-guix source
953 #:name (string-append "guix-"
955 #:pull-version pull-version
956 #:guile-version (if (>= pull-version 1)
958 #:guile-for-build guile)))