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 ("lzlib" (ref '(gnu packages compression) 'lzlib))
61 ("gzip" (ref '(gnu packages compression) 'gzip))
62 ("bzip2" (ref '(gnu packages compression) 'bzip2))
63 ("xz" (ref '(gnu packages compression) 'xz))
64 ("po4a" (ref '(gnu packages gettext) 'po4a))
65 ("gettext" (ref '(gnu packages gettext) 'gettext-minimal))
66 (_ #f)))) ;no such package
73 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
74 ;; easier to express things this way.
75 (define-record-type <node>
76 (node name modules source dependencies compiled)
78 (name node-name) ;string
79 (modules node-modules) ;list of module names
80 (source node-source) ;list of source files
81 (dependencies node-dependencies) ;list of nodes
82 (compiled node-compiled)) ;node -> lowerable object
84 ;; File mappings are essentially an alist as passed to 'imported-files'.
85 (define-record-type <file-mapping>
86 (file-mapping name alist)
88 (name file-mapping-name)
89 (alist file-mapping-alist))
91 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
93 ;; Here we use 'imported-files', which can arrange to directly import all
94 ;; the files instead of creating a derivation, when possible.
95 (imported-files (map (match-lambda
96 ((destination (? local-file? file))
98 (local-file-absolute-file-name file)))
100 (cons destination source))) ;silliness
101 (file-mapping-alist mapping))
102 #:name (file-mapping-name mapping)
105 (define (node-source+compiled node)
106 "Return a \"bundle\" containing both the source code and object files for
107 NODE's modules, under their FHS directories: share/guile/site and lib/guile."
109 (with-imported-modules '((guix build utils))
111 (use-modules (guix build utils))
114 (string-append #$output "/share/guile/site/"
115 (effective-version)))
118 (string-append #$output "/lib/guile/" (effective-version)
121 (mkdir-p (dirname source))
122 (symlink #$(node-source node) source)
123 (mkdir-p (dirname object))
124 (symlink #$(node-compiled node) object))))
126 (computed-file (string-append (node-name node) "-modules")
129 (define (node-fold proc init nodes)
130 (let loop ((nodes nodes)
136 (if (set-contains? visited head)
137 (loop tail visited result)
138 (loop tail (set-insert head visited)
139 (proc head result)))))))
141 (define (node-modules/recursive nodes)
142 (node-fold (lambda (node modules)
143 (append (node-modules node) modules))
147 (define* (closure modules #:optional (except '()))
148 (source-module-closure modules
154 (or ('guix _ ...) ('gnu _ ...)))
155 (not (member module except)))
158 (define module->import
159 ;; Return a file-name/file-like object pair for the specified module and
160 ;; suitable for 'imported-files'.
163 (let ((file (module-name->file-name module)))
166 (let ((file (module-name->file-name module)))
168 (local-file (search-path %load-path file)))))))
170 (define* (scheme-node name modules #:optional (dependencies '())
171 #:key (extra-modules '()) (extra-files '())
173 parallel? guile-for-build)
174 "Return a node that builds the given Scheme MODULES, and depends on
175 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
176 added to the source, and EXTRA-FILES is a list of additional files.
177 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
178 must be present in the search path."
179 (let* ((modules (append extra-modules
181 (node-modules/recursive dependencies))))
182 (module-files (map module->import modules))
183 (source (file-mapping (string-append name "-source")
184 (append module-files extra-files))))
185 (node name modules source dependencies
186 (compiled-modules name source
187 (map car module-files)
188 (map node-source dependencies)
189 (map node-compiled dependencies)
190 #:extensions extensions
191 #:parallel? parallel?
192 #:guile-for-build guile-for-build))))
194 (define (file-imports directory sub-directory pred)
195 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
196 list of file-name/file-like objects suitable as inputs to 'imported-files'."
198 (list (string-drop file (+ 1 (string-length directory)))
199 (local-file file #:recursive? #t)))
200 (find-files (string-append directory "/" sub-directory) pred)))
202 (define* (file-append* item file #:key (recursive? #t))
203 "Return FILE within ITEM, which may be a file name or a file-like object.
204 When ITEM is a plain file name (a string), simply return a 'local-file'
205 record with the new file name."
208 ;; This is the optimal case: we return a new "source". Thus, a
209 ;; derivation that depends on this sub-directory does not depend on ITEM
211 (local-file (string-append item "/" file)
212 #:recursive? recursive?))
213 ;; TODO: Add 'local-file?' case.
215 ;; In this case, anything that refers to the result also depends on ITEM,
216 ;; which isn't great.
217 (file-append item "/" file))))
219 (define* (locale-data source domain
220 #:optional (directory domain))
221 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
222 DOMAIN, a gettext domain."
224 (module-ref (resolve-interface '(gnu packages gettext))
228 (with-imported-modules '((guix build utils))
230 (use-modules (guix build utils)
232 (ice-9 match) (ice-9 ftw))
235 #+(file-append* source (string-append "po/" directory)))
237 (define (compile language)
238 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
240 (mkdir-p (dirname gmo))
241 (invoke #+(file-append gettext "/bin/msgfmt")
242 "-c" "--statistics" "--verbose"
244 (string-append po-directory "/" language ".po"))))
247 ;; Return the list of languages. Note: don't read 'LINGUAS'
248 ;; because it contains things like 'en@boldquot' that do not have
249 ;; a corresponding .po file.
250 (map (cut basename <> ".po")
251 (scandir po-directory
252 (cut string-suffix? ".po" <>))))
254 (for-each compile (linguas)))))
256 (computed-file (string-append "guix-locale-" domain)
259 (define (translate-texi-manuals source)
260 "Return the translated texinfo manuals built from SOURCE."
262 (specification->package "po4a"))
265 (specification->package "gettext"))
267 (define glibc-utf8-locales
268 (module-ref (resolve-interface '(gnu packages base))
269 'glibc-utf8-locales))
271 (define documentation
272 (file-append* source "doc"))
274 (define documentation-po
275 (file-append* source "po/doc"))
278 (with-imported-modules '((guix build utils) (guix build po))
280 (use-modules (guix build utils) (guix build po)
281 (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
286 (copy-recursively #$documentation "."
287 #:log (%make-void-port "w"))
291 (copy-file file (basename file)))
292 (find-files #$documentation-po ".*.po$"))
294 (setenv "GUIX_LOCPATH"
295 #+(file-append glibc-utf8-locales "/lib/locale"))
296 (setenv "PATH" #+(file-append gettext "/bin"))
297 (setenv "LC_ALL" "en_US.UTF-8")
298 (setlocale LC_ALL "en_US.UTF-8")
300 (define (translate-tmp-texi po source output)
301 "Translate Texinfo file SOURCE using messages from PO, and write
302 the result to OUTPUT."
303 (invoke #+(file-append po4a "/bin/po4a-translate")
304 "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
305 "-m" source "-p" po "-l" output))
307 (define (make-ref-regex msgid end)
308 (make-regexp (string-append
310 (string-join (string-split (regexp-quote msgid) #\ )
314 (define (translate-cross-references content translations)
315 "Take CONTENT, a string representing a .texi file and translate any
316 cross-reference in it (@ref, @xref and @pxref) that have a translation in
317 TRANSLATIONS, an alist of msgid and msgstr."
319 (lambda (elem content)
322 ;; Empty translations and strings containing some special characters
323 ;; cannot be the name of a section.
324 (if (or (equal? msgstr "")
325 (string-any (lambda (chr)
326 (member chr '(#\{ #\} #\( #\) #\newline #\,)))
329 ;; Otherwise, they might be the name of a section, so we
330 ;; need to translate any occurence in @(p?x?)ref{...}.
331 (let ((regexp1 (make-ref-regex msgid ","))
332 (regexp2 (make-ref-regex msgid "\\}")))
333 (regexp-substitute/global
335 (regexp-substitute/global
336 #f regexp1 content 'pre "ref{" msgstr "," 'post)
337 'pre "ref{" msgstr "}" 'post))))))
338 content translations))
340 (define (translate-texi po lang)
341 "Translate the manual for one language LANG using the PO file."
342 (let ((translations (call-with-input-file po read-po-file)))
343 (translate-tmp-texi po "guix.texi"
344 (string-append "guix." lang ".texi.tmp"))
345 (translate-tmp-texi po "contributing.texi"
346 (string-append "contributing." lang ".texi.tmp"))
347 (let* ((texi-name (string-append "guix." lang ".texi"))
348 (tmp-name (string-append texi-name ".tmp")))
349 (with-output-to-file texi-name
352 (translate-cross-references
353 (call-with-input-file tmp-name get-string-all)
355 (let* ((texi-name (string-append "contributing." lang ".texi"))
356 (tmp-name (string-append texi-name ".tmp")))
357 (with-output-to-file texi-name
360 (translate-cross-references
361 (call-with-input-file tmp-name get-string-all)
364 (for-each (lambda (po)
365 (match (reverse (string-split po #\.))
367 (translate-texi po lang))))
368 (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$"))
372 (copy-file file (string-append #$output "/" file)))
374 (find-files "." "contributing\\..*\\.texi$")
375 (find-files "." "guix\\..*\\.texi$"))))))
377 (computed-file "guix-translated-texinfo" build))
379 (define (info-manual source)
380 "Return the Info manual built from SOURCE."
382 (module-ref (resolve-interface '(gnu packages texinfo))
386 (module-ref (resolve-interface '(gnu packages graphviz))
389 (define glibc-utf8-locales
390 (module-ref (resolve-interface '(gnu packages base))
391 'glibc-utf8-locales))
393 (define documentation
394 (file-append* source "doc"))
397 (file-append* source "gnu/system/examples"))
400 (with-imported-modules '((guix build utils))
402 (use-modules (guix build utils))
406 ;; Create 'version.texi'.
407 ;; XXX: Can we use a more meaningful version string yet one that
408 ;; doesn't change at each commit?
409 (call-with-output-file "version.texi"
411 (let ((version "0.0-git"))
413 @set UPDATED 1 January 1970
414 @set UPDATED-MONTH January 1970
416 @set VERSION ~a\n" version version))))
418 ;; Copy configuration templates that the manual includes.
419 (for-each (lambda (template)
423 (basename template ".tmpl")
425 (find-files #$examples "\\.tmpl$"))
428 (mkdir-p (string-append #$output "/images"))
429 (for-each (lambda (dot-file)
430 (invoke #+(file-append graphviz "/bin/dot")
431 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
432 "-Granksep=.00005" "-Nfontsize=9"
433 "-Nheight=.1" "-Nwidth=.1"
434 "-o" (string-append #$output "/images/"
435 (basename dot-file ".dot")
438 (find-files (string-append #$documentation "/images")
442 (for-each (lambda (png-file)
443 (install-file png-file
444 (string-append #$output "/images")))
445 (find-files (string-append #$documentation "/images")
448 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
449 ;; add a symlink to the 'images' directory so that 'makeinfo' can
450 ;; see those images and produce image references in the Info output.
451 (copy-recursively #$documentation "."
452 #:log (%make-void-port "w"))
453 (copy-recursively #+(translate-texi-manuals source) "."
454 #:log (%make-void-port "w"))
455 (delete-file-recursively "images")
456 (symlink (string-append #$output "/images") "images")
458 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
459 (setenv "GUIX_LOCPATH"
460 #+(file-append glibc-utf8-locales "/lib/locale"))
462 (for-each (lambda (texi)
463 (unless (string=? "guix.texi" texi)
464 ;; Create 'version-LL.texi'.
465 (let* ((base (basename texi ".texi"))
466 (dot (string-index base #\.))
467 (tag (string-drop base (+ 1 dot))))
468 (symlink "version.texi"
469 (string-append "version-" tag ".texi"))))
471 (invoke #+(file-append texinfo "/bin/makeinfo")
472 texi "-I" #$documentation
474 "-o" (string-append #$output "/"
475 (basename texi ".texi")
478 (find-files "." "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")))
480 ;; Compress Info files.
482 #+(file-append (specification->package "gzip") "/bin"))
483 (for-each (lambda (file)
484 (invoke "gzip" "-9n" file))
485 (find-files #$output "\\.info(-[0-9]+)?$")))))
487 (computed-file "guix-manual" build))
489 (define* (guile-module-union things #:key (name "guix-module-union"))
490 "Return the union of the subset of THINGS (packages, computed files, etc.)
491 that provide Guile modules."
493 (with-imported-modules '((guix build union))
495 (use-modules (guix build union))
497 (define (modules directory)
498 (string-append directory "/share/guile/site"))
500 (define (objects directory)
501 (string-append directory "/lib/guile"))
503 (union-build #$output
504 (filter (lambda (directory)
505 (or (file-exists? (modules directory))
506 (file-exists? (objects directory))))
509 #:log-port (%make-void-port "w")))))
511 (computed-file name build))
513 (define* (guix-command modules
514 #:key source (dependencies '())
515 guile (guile-version (effective-version)))
516 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
518 (define glibc-utf8-locales
519 (module-ref (resolve-interface '(gnu packages base))
520 'glibc-utf8-locales))
522 (define module-directory
523 ;; To minimize the number of 'stat' calls needed to locate a module,
524 ;; create the union of all the module directories.
525 (guile-module-union (cons modules dependencies)))
527 (program-file "guix-command"
530 (cons (string-append #$module-directory
535 (set! %load-compiled-path
536 (cons (string-append #$module-directory
540 %load-compiled-path))
542 ;; To maximize the chances that locales are set up right
543 ;; out-of-the-box, bundle "common" UTF-8 locales.
544 (let ((locpath (getenv "GUIX_LOCPATH")))
545 (setenv "GUIX_LOCPATH"
546 (string-append (if locpath
547 (string-append locpath ":")
549 #$(file-append glibc-utf8-locales
552 (let ((guix-main (module-ref (resolve-interface '(guix ui))
556 (bindtextdomain "guix"
557 #$(locale-data source "guix"))
558 (bindtextdomain "guix-packages"
559 #$(locale-data source
564 ;; XXX: It would be more convenient to change it to:
565 ;; (exit (apply guix-main (command-line)))
566 (apply guix-main (command-line))))
569 (define (miscellaneous-files source)
570 "Return data files taken from SOURCE."
571 (file-mapping "guix-misc"
572 `(("etc/bash_completion.d/guix"
573 ,(file-append* source "/etc/completion/bash/guix"))
574 ("etc/bash_completion.d/guix-daemon"
575 ,(file-append* source "/etc/completion/bash/guix-daemon"))
576 ("share/zsh/site-functions/_guix"
577 ,(file-append* source "/etc/completion/zsh/_guix"))
578 ("share/fish/vendor_completions.d/guix.fish"
579 ,(file-append* source "/etc/completion/fish/guix.fish"))
580 ("share/guix/hydra.gnu.org.pub"
581 ,(file-append* source
582 "/etc/substitutes/hydra.gnu.org.pub"))
583 ("share/guix/berlin.guixsd.org.pub"
584 ,(file-append* source
585 "/etc/substitutes/berlin.guixsd.org.pub"))
586 ("share/guix/ci.guix.gnu.org.pub" ;alias
587 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub"))
588 ("share/guix/ci.guix.info.pub" ;alias
589 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub")))))
591 (define* (whole-package name modules dependencies
593 (guile-version (effective-version))
594 info daemon miscellany
596 (command (guix-command modules
597 #:dependencies dependencies
599 #:guile-version guile-version)))
600 "Return the whole Guix package NAME that uses MODULES, a derivation of all
601 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
602 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
604 (define (wrap daemon)
605 (program-file "guix-daemon"
607 ;; Refer to the right 'guix' command for 'guix
609 (setenv "GUIX" #$command)
611 ;; Honor the user's settings rather than those hardcoded
612 ;; in the 'guix-daemon' package.
613 (unless (getenv "GUIX_STATE_DIRECTORY")
614 (setenv "GUIX_STATE_DIRECTORY"
615 #$(string-append %localstatedir "/guix")))
616 (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
617 (setenv "GUIX_CONFIGURATION_DIRECTORY"
618 #$(string-append %sysconfdir "/guix")))
619 (unless (getenv "NIX_STORE_DIR")
620 (setenv "NIX_STORE_DIR" #$%storedir))
622 (apply execl #$(file-append daemon "/bin/guix-daemon")
623 "guix-daemon" (cdr (command-line))))))
626 (with-imported-modules '((guix build utils))
628 (use-modules (guix build utils))
631 #$(and daemon (wrap daemon)))
633 (mkdir-p (string-append #$output "/bin"))
635 (string-append #$output "/bin/guix"))
639 (string-append #$output "/bin/guix-daemon")))
641 (let ((share (string-append #$output "/share"))
642 (lib (string-append #$output "/lib"))
645 (symlink #$(file-append modules "/share/guile")
646 (string-append share "/guile"))
648 (symlink #$info (string-append share "/info")))
651 (symlink #$(file-append modules "/lib/guile")
652 (string-append lib "/guile")))
655 (copy-recursively #$miscellany #$output
656 #:log (%make-void-port "w")))))))
658 (define* (compiled-guix source #:key (version %guix-version)
660 (name (string-append "guix-" version))
661 (guile-version (effective-version))
662 (guile-for-build (default-guile))
663 (zlib (specification->package "zlib"))
664 (lzlib (specification->package "lzlib"))
665 (gzip (specification->package "gzip"))
666 (bzip2 (specification->package "bzip2"))
667 (xz (specification->package "xz"))
668 (guix (specification->package "guix")))
669 "Return a file-like object that contains a compiled Guix."
671 (specification->package "guile-json"))
674 (specification->package "guile-ssh"))
677 (specification->package "guile-git"))
679 (define guile-sqlite3
680 (specification->package "guile-sqlite3"))
683 (specification->package "guile-gcrypt"))
686 (specification->package "gnutls"))
689 (match (append-map (lambda (package)
690 (cons (list "x" package)
691 (package-transitive-propagated-inputs package)))
692 (list guile-gcrypt gnutls guile-git guile-json
693 guile-ssh guile-sqlite3))
694 (((labels packages _ ...) ...)
697 (define *core-modules*
698 (scheme-node "guix-core"
705 (guix build-system gnu)
706 (guix build-system trivial)
707 (guix build profiles)
708 (guix build gnu-build-system))
710 ;; Provide a dummy (guix config) with the default version
711 ;; number, storedir, etc. This is so that "guix-core" is the
712 ;; same across all installations and doesn't need to be
713 ;; rebuilt when the version changes, which in turn means we
714 ;; can have substitutes for it.
716 `(((guix config) => ,(make-config.scm)))
718 ;; (guix man-db) is needed at build-time by (guix profiles)
719 ;; but we don't need to compile it; not compiling it allows
720 ;; us to avoid an extra dependency on guile-gdbm-ffi.
722 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
723 ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
724 ("guix/store/schema.sql"
725 ,(local-file "../guix/store/schema.sql")))
727 #:extensions (list guile-gcrypt)
728 #:guile-for-build guile-for-build))
730 (define *extra-modules*
731 (scheme-node "guix-extra"
732 (filter-map (match-lambda
733 (('guix 'scripts _ ..1) #f)
736 (scheme-modules* source "guix"))
737 (list *core-modules*)
738 #:extensions dependencies
739 #:guile-for-build guile-for-build))
741 (define *core-package-modules*
742 (scheme-node "guix-packages-base"
745 (list *core-modules* *extra-modules*)
746 #:extensions dependencies
748 ;; Add all the non-Scheme files here. We must do it here so
749 ;; that 'search-patches' & co. can find them. Ideally we'd
750 ;; keep them next to the .scm files that use them but it's
751 ;; difficult to do (XXX).
753 (file-imports source "gnu/packages"
755 (and (eq? 'regular (stat:type stat))
756 (not (string-suffix? ".scm" file))
757 (not (string-suffix? ".go" file))
758 (not (string-prefix? ".#" file))
759 (not (string-suffix? "~" file)))))
760 #:guile-for-build guile-for-build))
762 (define *package-modules*
763 (scheme-node "guix-packages"
764 (scheme-modules* source "gnu/packages")
765 (list *core-modules* *extra-modules* *core-package-modules*)
766 #:extensions dependencies
767 #:guile-for-build guile-for-build))
769 (define *system-modules*
770 (scheme-node "guix-system"
773 ,@(scheme-modules* source "gnu/bootloader")
774 ,@(scheme-modules* source "gnu/system")
775 ,@(scheme-modules* source "gnu/services"))
776 (list *core-package-modules* *package-modules*
777 *extra-modules* *core-modules*)
778 #:extensions dependencies
780 (append (file-imports source "gnu/system/examples"
783 ;; All the installer code is on the build-side.
784 (file-imports source "gnu/installer/"
786 ;; Build-side code that we don't build. Some of
787 ;; these depend on guile-rsvg, the Shepherd, etc.
788 (file-imports source "gnu/build" (const #t)))
792 (define *cli-modules*
793 (scheme-node "guix-cli"
794 (append (scheme-modules* source "/guix/scripts")
796 (list *core-modules* *extra-modules*
797 *core-package-modules* *package-modules*
799 #:extensions dependencies
800 #:guile-for-build guile-for-build))
802 (define *system-test-modules*
803 ;; Ship these modules mostly so (gnu ci) can discover them.
804 (scheme-node "guix-system-tests"
806 ,@(scheme-modules* source "gnu/tests"))
807 (list *core-package-modules* *package-modules*
808 *extra-modules* *system-modules* *core-modules*
809 *cli-modules*) ;for (guix scripts pack), etc.
810 #:extensions dependencies
811 #:guile-for-build guile-for-build))
814 (scheme-node "guix-config"
818 => ,(make-config.scm #:zlib zlib
828 %guix-bug-report-address
830 %guix-home-page-url)))
831 #:guile-for-build guile-for-build))
833 (define (built-modules node-subset)
834 (directory-union (string-append name "-modules")
835 (append-map node-subset
837 ;; Note: *CONFIG* comes first so that it
838 ;; overrides the (guix config) module that
839 ;; comes with *CORE-MODULES*.
842 *system-test-modules*
845 *core-package-modules*
849 ;; Silently choose the first entry upon collision so that
850 ;; we choose *CONFIG*.
851 #:resolve-collision 'first
853 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
854 ;; be a regular file, not a symlink. Thus, arrange so that
855 ;; regular files appear as regular files in the final
860 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
861 ;; Version 1 is when we return the full package.
862 (cond ((= 1 pull-version)
863 ;; The whole package, with a standard file hierarchy.
864 (let* ((modules (built-modules (compose list node-source+compiled)))
865 (command (guix-command modules
867 #:dependencies dependencies
868 #:guile guile-for-build
869 #:guile-version guile-version)))
870 (whole-package name modules dependencies
872 #:guile guile-for-build
874 ;; Include 'guix-daemon'. XXX: Here we inject an
875 ;; older snapshot of guix-daemon, but that's a good
876 ;; enough approximation for now.
877 #:daemon (module-ref (resolve-interface
882 #:info (info-manual source)
883 #:miscellany (miscellaneous-files source)
884 #:guile-version guile-version)))
886 ;; Legacy 'guix pull': return the .scm and .go files as one
888 (built-modules (lambda (node)
889 (list (node-source node)
890 (node-compiled node)))))
892 ;; Unsupported 'guix pull' version.
897 ;;; Generating (guix config).
900 (define %persona-variables
901 ;; (guix config) variables that define Guix's persona.
904 %guix-bug-report-address
905 %guix-home-page-url))
907 (define %config-variables
908 ;; (guix config) variables corresponding to Guix configuration.
909 (letrec-syntax ((variables (syntax-rules ()
912 ((_ variable rest ...)
913 (cons `(variable . ,variable)
914 (variables rest ...))))))
915 (variables %localstatedir %storedir %sysconfdir)))
917 (define* (make-config.scm #:key zlib lzlib gzip xz bzip2
918 (package-name "GNU Guix")
919 (package-version "0")
920 (bug-report-address "bug-guix@gnu.org")
921 (home-page-url "https://gnu.org/s/guix"))
923 ;; Hack so that Geiser is not confused.
924 (define defmod 'define-module)
926 (scheme-file "config.scm"
927 #~(;; The following expressions get spliced.
928 (#$defmod (guix config)
929 #:export (%guix-package-name
931 %guix-bug-report-address
936 %store-database-directory
947 #$@(map (match-lambda
949 #~(define-public #$name #$value)))
952 (define %store-directory
953 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
956 (define %state-directory
957 ;; This must match `NIX_STATE_DIR' as defined in
959 (or (getenv "GUIX_STATE_DIRECTORY")
960 (string-append %localstatedir "/guix")))
962 (define %store-database-directory
963 (or (getenv "GUIX_DATABASE_DIRECTORY")
964 (string-append %state-directory "/db")))
966 (define %config-directory
967 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
968 ;; defined in `nix/local.mk'.
969 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
970 (string-append %sysconfdir "/guix")))
972 (define %guix-package-name #$package-name)
973 (define %guix-version #$package-version)
974 (define %guix-bug-report-address #$bug-report-address)
975 (define %guix-home-page-url #$home-page-url)
978 #+(and gzip (file-append gzip "/bin/gzip")))
980 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
982 #+(and xz (file-append xz "/bin/xz")))
986 (file-append zlib "/lib/libz")))
990 (file-append lzlib "/lib/liblz"))))
992 ;; Guile 2.0 *requires* the 'define-module' to be at the
993 ;; top-level or the 'toplevel-ref' in the resulting .go file are
994 ;; made relative to a nonexistent anonymous module.
1002 (define* (compiled-modules name module-tree module-files
1005 (dependencies-compiled '())
1007 (extensions '()) ;full-blown Guile packages
1010 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
1011 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
1012 containing MODULE-FILES and possibly other files as well."
1013 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1016 (with-imported-modules (source-module-closure
1017 '((guix build compile)
1018 (guix build utils)))
1020 (use-modules (srfi srfi-26)
1024 (guix build compile)
1027 (define (regular? file)
1028 (not (member file '("." ".."))))
1030 (define (report-load file total completed)
1033 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1035 ;; Note: Multiply TOTAL by two to account for the
1036 ;; compilation phase that follows.
1037 completed (* total 2)
1039 (* 100. (/ completed total)) total)
1042 (define (report-compilation file total completed)
1044 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1046 ;; Add TOTAL to account for the load phase that came
1048 (+ total completed) (* total 2)
1050 (* 100. (/ completed total)) total)
1053 (define (process-directory directory files output)
1054 ;; Hide compilation warnings.
1055 (parameterize ((current-warning-port (%make-void-port "w")))
1056 (compile-files directory #$output files
1057 #:workers (parallel-job-count)
1058 #:report-load report-load
1059 #:report-compilation report-compilation)))
1061 (setvbuf (current-output-port) 'line)
1062 (setvbuf (current-error-port) 'line)
1064 (set! %load-path (cons #+module-tree %load-path))
1066 (append '#+dependencies
1067 (map (lambda (extension)
1068 (string-append extension "/share/guile/site/"
1069 (effective-version)))
1073 (set! %load-compiled-path
1074 (append '#+dependencies-compiled
1075 (map (lambda (extension)
1076 (string-append extension "/lib/guile/"
1080 %load-compiled-path))
1082 ;; Load the compiler modules upfront.
1086 (chdir #+module-tree)
1087 (process-directory "." '#+module-files #$output)
1090 (computed-file name build
1091 #:guile guile-for-build
1093 `(#:local-build? #f ;allow substitutes
1095 ;; Don't annoy people about _IONBF deprecation.
1096 ;; Initialize 'terminal-width' in (system repl debug)
1097 ;; to a large-enough value to make backtrace more
1099 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1100 ("COLUMNS" . "200")))))
1107 (define* (guix-derivation source version
1108 #:optional (guile-version (effective-version))
1109 #:key (pull-version 0))
1110 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1111 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
1112 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
1114 (define (shorten version)
1115 (if (and (string-every char-set:hex-digit version)
1116 (> (string-length version) 9))
1117 (string-take version 9) ;Git commit
1121 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2
1125 (when (and (< pull-version 1)
1126 (not (string=? (package-version guile) guile-version)))
1127 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1128 ;; can be any version. When that happens and Guile is not current (e.g.,
1129 ;; it's Guile 2.0), just bail out.
1132 (message "Guix is too old and cannot be upgraded")))))
1134 (mbegin %store-monad
1135 (set-guile-for-build guile)
1136 (let ((guix (compiled-guix source
1138 #:name (string-append "guix-"
1140 #:pull-version pull-version
1141 #:guile-version (if (>= pull-version 1)
1142 "2.2" guile-version)
1143 #:guile-for-build guile)))