1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019, 2020 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 (srfi srfi-1)
32 #:use-module (srfi srfi-9)
33 #:use-module (srfi srfi-35)
34 #:use-module (ice-9 match)
35 #:export (make-config.scm
36 whole-package ;for internal use in 'guix pull'
42 ;;; Dependency handling.
45 (define specification->package
46 ;; Use our own variant of that procedure because that of (gnu packages)
47 ;; would traverse all the .scm files, which is wasteful.
48 (let ((ref (lambda (module variable)
49 (module-ref (resolve-interface module) variable))))
51 ("guile" (ref '(gnu packages commencement) 'guile-final))
52 ("guile-json" (ref '(gnu packages guile) 'guile-json-3))
53 ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh))
54 ("guile-git" (ref '(gnu packages guile) 'guile-git))
55 ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3))
56 ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
57 ("gnutls" (ref '(gnu packages tls) 'gnutls))
58 ("zlib" (ref '(gnu packages compression) 'zlib))
59 ("lzlib" (ref '(gnu packages compression) 'lzlib))
60 ("gzip" (ref '(gnu packages compression) 'gzip))
61 ("bzip2" (ref '(gnu packages compression) 'bzip2))
62 ("xz" (ref '(gnu packages compression) 'xz))
63 ("po4a" (ref '(gnu packages gettext) 'po4a))
64 ("gettext" (ref '(gnu packages gettext) 'gettext-minimal))
65 (_ #f)))) ;no such package
72 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
73 ;; easier to express things this way.
74 (define-record-type <node>
75 (node name modules source dependencies compiled)
77 (name node-name) ;string
78 (modules node-modules) ;list of module names
79 (source node-source) ;list of source files
80 (dependencies node-dependencies) ;list of nodes
81 (compiled node-compiled)) ;node -> lowerable object
83 ;; File mappings are essentially an alist as passed to 'imported-files'.
84 (define-record-type <file-mapping>
85 (file-mapping name alist)
87 (name file-mapping-name)
88 (alist file-mapping-alist))
90 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
92 ;; Here we use 'imported-files', which can arrange to directly import all
93 ;; the files instead of creating a derivation, when possible.
94 (imported-files (map (match-lambda
95 ((destination (? local-file? file))
97 (local-file-absolute-file-name file)))
99 (cons destination source))) ;silliness
100 (file-mapping-alist mapping))
101 #:name (file-mapping-name mapping)
104 (define (node-source+compiled node)
105 "Return a \"bundle\" containing both the source code and object files for
106 NODE's modules, under their FHS directories: share/guile/site and lib/guile."
108 (with-imported-modules '((guix build utils))
110 (use-modules (guix build utils))
113 (string-append #$output "/share/guile/site/"
114 (effective-version)))
117 (string-append #$output "/lib/guile/" (effective-version)
120 (mkdir-p (dirname source))
121 (symlink #$(node-source node) source)
122 (mkdir-p (dirname object))
123 (symlink #$(node-compiled node) object))))
125 (computed-file (string-append (node-name node) "-modules")
127 #:options '(#:local-build? #t
129 ;; "Building" it locally is faster.
130 #:substitutable? #f)))
132 (define (node-fold proc init nodes)
133 (let loop ((nodes nodes)
139 (if (set-contains? visited head)
140 (loop tail visited result)
141 (loop tail (set-insert head visited)
142 (proc head result)))))))
144 (define (node-modules/recursive nodes)
145 (node-fold (lambda (node modules)
146 (append (node-modules node) modules))
150 (define* (closure modules #:optional (except '()))
151 (source-module-closure modules
157 (or ('guix _ ...) ('gnu _ ...)))
158 (not (member module except)))
161 (define module->import
162 ;; Return a file-name/file-like object pair for the specified module and
163 ;; suitable for 'imported-files'.
166 (let ((file (module-name->file-name module)))
169 (let ((file (module-name->file-name module)))
171 (local-file (search-path %load-path file)))))))
173 (define* (scheme-node name modules #:optional (dependencies '())
174 #:key (extra-modules '()) (extra-files '())
176 parallel? guile-for-build)
177 "Return a node that builds the given Scheme MODULES, and depends on
178 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
179 added to the source, and EXTRA-FILES is a list of additional files.
180 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
181 must be present in the search path."
182 (let* ((modules (append extra-modules
184 (node-modules/recursive dependencies))))
185 (module-files (map module->import modules))
186 (source (file-mapping (string-append name "-source")
187 (append module-files extra-files))))
188 (node name modules source dependencies
189 (compiled-modules name source
190 (map car module-files)
191 (map node-source dependencies)
192 (map node-compiled dependencies)
193 #:extensions extensions
194 #:parallel? parallel?
195 #:guile-for-build guile-for-build))))
197 (define (file-imports directory sub-directory pred)
198 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
199 list of file-name/file-like objects suitable as inputs to 'imported-files'."
201 (list (string-drop file (+ 1 (string-length directory)))
202 (local-file file #:recursive? #t)))
203 (find-files (string-append directory "/" sub-directory) pred)))
205 (define* (file-append* item file #:key (recursive? #t))
206 "Return FILE within ITEM, which may be a file name or a file-like object.
207 When ITEM is a plain file name (a string), simply return a 'local-file'
208 record with the new file name."
211 ;; This is the optimal case: we return a new "source". Thus, a
212 ;; derivation that depends on this sub-directory does not depend on ITEM
214 (local-file (string-append item "/" file)
215 #:recursive? recursive?))
216 ;; TODO: Add 'local-file?' case.
218 ;; In this case, anything that refers to the result also depends on ITEM,
219 ;; which isn't great.
220 (file-append item "/" file))))
222 (define* (locale-data source domain
223 #:optional (directory domain))
224 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
225 DOMAIN, a gettext domain."
227 (module-ref (resolve-interface '(gnu packages gettext))
231 (with-imported-modules '((guix build utils))
233 (use-modules (guix build utils)
235 (ice-9 match) (ice-9 ftw))
238 #+(file-append* source (string-append "po/" directory)))
240 (define (compile language)
241 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
243 (mkdir-p (dirname gmo))
244 (invoke #+(file-append gettext "/bin/msgfmt")
245 "-c" "--statistics" "--verbose"
247 (string-append po-directory "/" language ".po"))))
250 ;; Return the list of languages. Note: don't read 'LINGUAS'
251 ;; because it contains things like 'en@boldquot' that do not have
252 ;; a corresponding .po file.
253 (map (cut basename <> ".po")
254 (scandir po-directory
255 (cut string-suffix? ".po" <>))))
257 (for-each compile (linguas)))))
259 (computed-file (string-append "guix-locale-" domain)
262 (define (translate-texi-manuals source)
263 "Return the translated texinfo manuals built from SOURCE."
265 (specification->package "po4a"))
268 (specification->package "gettext"))
270 (define glibc-utf8-locales
271 (module-ref (resolve-interface '(gnu packages base))
272 'glibc-utf8-locales))
274 (define documentation
275 (file-append* source "doc"))
277 (define documentation-po
278 (file-append* source "po/doc"))
281 (with-imported-modules '((guix build utils) (guix build po))
283 (use-modules (guix build utils) (guix build po)
284 (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
289 (copy-recursively #$documentation "."
290 #:log (%make-void-port "w"))
294 (copy-file file (basename file)))
295 (find-files #$documentation-po ".*.po$"))
297 (setenv "GUIX_LOCPATH"
298 #+(file-append glibc-utf8-locales "/lib/locale"))
299 (setenv "PATH" #+(file-append gettext "/bin"))
300 (setenv "LC_ALL" "en_US.UTF-8")
301 (setlocale LC_ALL "en_US.UTF-8")
303 (define (translate-tmp-texi po source output)
304 "Translate Texinfo file SOURCE using messages from PO, and write
305 the result to OUTPUT."
306 (invoke #+(file-append po4a "/bin/po4a-translate")
307 "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
308 "-m" source "-p" po "-l" output))
310 (define (make-ref-regex msgid end)
311 (make-regexp (string-append
313 (string-join (string-split (regexp-quote msgid) #\ )
317 (define (translate-cross-references content translations)
318 "Take CONTENT, a string representing a .texi file and translate any
319 cross-reference in it (@ref, @xref and @pxref) that have a translation in
320 TRANSLATIONS, an alist of msgid and msgstr."
322 (lambda (elem content)
325 ;; Empty translations and strings containing some special characters
326 ;; cannot be the name of a section.
327 (if (or (equal? msgstr "")
328 (string-any (lambda (chr)
329 (member chr '(#\{ #\} #\( #\) #\newline #\,)))
332 ;; Otherwise, they might be the name of a section, so we
333 ;; need to translate any occurence in @(p?x?)ref{...}.
334 (let ((regexp1 (make-ref-regex msgid ","))
335 (regexp2 (make-ref-regex msgid "\\}")))
336 (regexp-substitute/global
338 (regexp-substitute/global
339 #f regexp1 content 'pre "ref{" msgstr "," 'post)
340 'pre "ref{" msgstr "}" 'post))))))
341 content translations))
343 (define (translate-texi po lang)
344 "Translate the manual for one language LANG using the PO file."
345 (let ((translations (call-with-input-file po read-po-file)))
346 (translate-tmp-texi po "guix.texi"
347 (string-append "guix." lang ".texi.tmp"))
348 (translate-tmp-texi po "contributing.texi"
349 (string-append "contributing." lang ".texi.tmp"))
350 (let* ((texi-name (string-append "guix." lang ".texi"))
351 (tmp-name (string-append texi-name ".tmp")))
352 (with-output-to-file texi-name
355 (translate-cross-references
356 (call-with-input-file tmp-name get-string-all)
358 (let* ((texi-name (string-append "contributing." lang ".texi"))
359 (tmp-name (string-append texi-name ".tmp")))
360 (with-output-to-file texi-name
363 (translate-cross-references
364 (call-with-input-file tmp-name get-string-all)
367 (for-each (lambda (po)
368 (match (reverse (string-split po #\.))
370 (translate-texi po lang))))
371 (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$"))
375 (copy-file file (string-append #$output "/" file)))
377 (find-files "." "contributing\\..*\\.texi$")
378 (find-files "." "guix\\..*\\.texi$"))))))
380 (computed-file "guix-translated-texinfo" build))
382 (define (info-manual source)
383 "Return the Info manual built from SOURCE."
385 (module-ref (resolve-interface '(gnu packages texinfo))
389 (module-ref (resolve-interface '(gnu packages graphviz))
392 (define glibc-utf8-locales
393 (module-ref (resolve-interface '(gnu packages base))
394 'glibc-utf8-locales))
396 (define documentation
397 (file-append* source "doc"))
400 (file-append* source "gnu/system/examples"))
403 (with-imported-modules '((guix build utils))
405 (use-modules (guix build utils))
409 ;; Create 'version.texi'.
410 ;; XXX: Can we use a more meaningful version string yet one that
411 ;; doesn't change at each commit?
412 (call-with-output-file "version.texi"
414 (let ((version "0.0-git"))
416 @set UPDATED 1 January 1970
417 @set UPDATED-MONTH January 1970
419 @set VERSION ~a\n" version version))))
421 ;; Copy configuration templates that the manual includes.
422 (for-each (lambda (template)
426 (basename template ".tmpl")
428 (find-files #$examples "\\.tmpl$"))
431 (mkdir-p (string-append #$output "/images"))
432 (for-each (lambda (dot-file)
433 (invoke #+(file-append graphviz "/bin/dot")
434 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
435 "-Granksep=.00005" "-Nfontsize=9"
436 "-Nheight=.1" "-Nwidth=.1"
437 "-o" (string-append #$output "/images/"
438 (basename dot-file ".dot")
441 (find-files (string-append #$documentation "/images")
445 (for-each (lambda (png-file)
446 (install-file png-file
447 (string-append #$output "/images")))
448 (find-files (string-append #$documentation "/images")
451 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
452 ;; add a symlink to the 'images' directory so that 'makeinfo' can
453 ;; see those images and produce image references in the Info output.
454 (copy-recursively #$documentation "."
455 #:log (%make-void-port "w"))
456 (copy-recursively #+(translate-texi-manuals source) "."
457 #:log (%make-void-port "w"))
458 (delete-file-recursively "images")
459 (symlink (string-append #$output "/images") "images")
461 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
462 (setenv "GUIX_LOCPATH"
463 #+(file-append glibc-utf8-locales "/lib/locale"))
465 (for-each (lambda (texi)
466 (unless (string=? "guix.texi" texi)
467 ;; Create 'version-LL.texi'.
468 (let* ((base (basename texi ".texi"))
469 (dot (string-index base #\.))
470 (tag (string-drop base (+ 1 dot))))
471 (symlink "version.texi"
472 (string-append "version-" tag ".texi"))))
474 (invoke #+(file-append texinfo "/bin/makeinfo")
475 texi "-I" #$documentation
477 "-o" (string-append #$output "/"
478 (basename texi ".texi")
481 (find-files "." "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")))
483 ;; Compress Info files.
485 #+(file-append (specification->package "gzip") "/bin"))
486 (for-each (lambda (file)
487 (invoke "gzip" "-9n" file))
488 (find-files #$output "\\.info(-[0-9]+)?$")))))
490 (computed-file "guix-manual" build))
492 (define* (guile-module-union things #:key (name "guix-module-union"))
493 "Return the union of the subset of THINGS (packages, computed files, etc.)
494 that provide Guile modules."
496 (with-imported-modules '((guix build union))
498 (use-modules (guix build union))
500 (define (modules directory)
501 (string-append directory "/share/guile/site"))
503 (define (objects directory)
504 (string-append directory "/lib/guile"))
506 (union-build #$output
507 (filter (lambda (directory)
508 (or (file-exists? (modules directory))
509 (file-exists? (objects directory))))
512 #:log-port (%make-void-port "w")))))
514 (computed-file name build))
516 (define* (guix-command modules
517 #:key source (dependencies '())
518 guile (guile-version (effective-version)))
519 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
521 (define glibc-utf8-locales
522 (module-ref (resolve-interface '(gnu packages base))
523 'glibc-utf8-locales))
525 (define module-directory
526 ;; To minimize the number of 'stat' calls needed to locate a module,
527 ;; create the union of all the module directories.
528 (guile-module-union (cons modules dependencies)))
530 (program-file "guix-command"
533 (cons (string-append #$module-directory
538 (set! %load-compiled-path
539 (cons (string-append #$module-directory
543 %load-compiled-path))
545 ;; To maximize the chances that locales are set up right
546 ;; out-of-the-box, bundle "common" UTF-8 locales.
547 (let ((locpath (getenv "GUIX_LOCPATH")))
548 (setenv "GUIX_LOCPATH"
549 (string-append (if locpath
550 (string-append locpath ":")
552 #$(file-append glibc-utf8-locales
555 (let ((guix-main (module-ref (resolve-interface '(guix ui))
559 (bindtextdomain "guix"
560 #$(locale-data source "guix"))
561 (bindtextdomain "guix-packages"
562 #$(locale-data source
567 ;; XXX: It would be more convenient to change it to:
568 ;; (exit (apply guix-main (command-line)))
569 (apply guix-main (command-line))))
572 (define (miscellaneous-files source)
573 "Return data files taken from SOURCE."
574 (file-mapping "guix-misc"
575 `(("etc/bash_completion.d/guix"
576 ,(file-append* source "/etc/completion/bash/guix"))
577 ("etc/bash_completion.d/guix-daemon"
578 ,(file-append* source "/etc/completion/bash/guix-daemon"))
579 ("share/zsh/site-functions/_guix"
580 ,(file-append* source "/etc/completion/zsh/_guix"))
581 ("share/fish/vendor_completions.d/guix.fish"
582 ,(file-append* source "/etc/completion/fish/guix.fish"))
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)
735 (('guix 'tests _ ...) #f)
737 (scheme-modules* source "guix"))
738 (list *core-modules*)
739 #:extensions dependencies
740 #:guile-for-build guile-for-build))
742 (define *core-package-modules*
743 (scheme-node "guix-packages-base"
746 (list *core-modules* *extra-modules*)
747 #:extensions dependencies
749 ;; Add all the non-Scheme files here. We must do it here so
750 ;; that 'search-patches' & co. can find them. Ideally we'd
751 ;; keep them next to the .scm files that use them but it's
752 ;; difficult to do (XXX).
754 (file-imports source "gnu/packages"
756 (and (eq? 'regular (stat:type stat))
757 (not (string-suffix? ".scm" file))
758 (not (string-suffix? ".go" file))
759 (not (string-prefix? ".#" file))
760 (not (string-suffix? "~" file)))))
761 #:guile-for-build guile-for-build))
763 (define *package-modules*
764 (scheme-node "guix-packages"
765 (scheme-modules* source "gnu/packages")
766 (list *core-modules* *extra-modules* *core-package-modules*)
767 #:extensions dependencies
768 #:guile-for-build guile-for-build))
770 (define *system-modules*
771 (scheme-node "guix-system"
774 ,@(scheme-modules* source "gnu/bootloader")
775 ,@(scheme-modules* source "gnu/system")
776 ,@(scheme-modules* source "gnu/services")
777 ,@(scheme-modules* source "gnu/machine"))
778 (list *core-package-modules* *package-modules*
779 *extra-modules* *core-modules*)
780 #:extensions dependencies
782 (append (file-imports source "gnu/system/examples"
785 ;; All the installer code is on the build-side.
786 (file-imports source "gnu/installer/"
788 ;; Build-side code that we don't build. Some of
789 ;; these depend on guile-rsvg, the Shepherd, etc.
790 (file-imports source "gnu/build" (const #t)))
794 (define *cli-modules*
795 (scheme-node "guix-cli"
796 (append (scheme-modules* source "/guix/scripts")
798 (list *core-modules* *extra-modules*
799 *core-package-modules* *package-modules*
801 #:extensions dependencies
802 #:guile-for-build guile-for-build))
804 (define *system-test-modules*
805 ;; Ship these modules mostly so (gnu ci) can discover them.
806 (scheme-node "guix-system-tests"
808 ,@(scheme-modules* source "gnu/tests"))
809 (list *core-package-modules* *package-modules*
810 *extra-modules* *system-modules* *core-modules*
811 *cli-modules*) ;for (guix scripts pack), etc.
812 #:extensions dependencies
813 #:guile-for-build guile-for-build))
816 (scheme-node "guix-config"
820 => ,(make-config.scm #:zlib zlib
830 %guix-bug-report-address
832 %guix-home-page-url)))
833 #:guile-for-build guile-for-build))
835 (define (built-modules node-subset)
836 (directory-union (string-append name "-modules")
837 (append-map node-subset
839 ;; Note: *CONFIG* comes first so that it
840 ;; overrides the (guix config) module that
841 ;; comes with *CORE-MODULES*.
844 *system-test-modules*
847 *core-package-modules*
851 ;; Silently choose the first entry upon collision so that
852 ;; we choose *CONFIG*.
853 #:resolve-collision 'first
855 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
856 ;; be a regular file, not a symlink. Thus, arrange so that
857 ;; regular files appear as regular files in the final
862 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
863 ;; Version 1 is when we return the full package.
864 (cond ((= 1 pull-version)
865 ;; The whole package, with a standard file hierarchy.
866 (let* ((modules (built-modules (compose list node-source+compiled)))
867 (command (guix-command modules
869 #:dependencies dependencies
870 #:guile guile-for-build
871 #:guile-version guile-version)))
872 (whole-package name modules dependencies
874 #:guile guile-for-build
876 ;; Include 'guix-daemon'. XXX: Here we inject an
877 ;; older snapshot of guix-daemon, but that's a good
878 ;; enough approximation for now.
879 #:daemon (module-ref (resolve-interface
884 #:info (info-manual source)
885 #:miscellany (miscellaneous-files source)
886 #:guile-version guile-version)))
888 ;; Legacy 'guix pull': return the .scm and .go files as one
890 (built-modules (lambda (node)
891 (list (node-source node)
892 (node-compiled node)))))
894 ;; Unsupported 'guix pull' version.
899 ;;; Generating (guix config).
902 (define %persona-variables
903 ;; (guix config) variables that define Guix's persona.
906 %guix-bug-report-address
907 %guix-home-page-url))
909 (define %config-variables
910 ;; (guix config) variables corresponding to Guix configuration.
911 (letrec-syntax ((variables (syntax-rules ()
914 ((_ variable rest ...)
915 (cons `(variable . ,variable)
916 (variables rest ...))))))
917 (variables %localstatedir %storedir %sysconfdir)))
919 (define* (make-config.scm #:key zlib lzlib gzip xz bzip2
920 (package-name "GNU Guix")
921 (package-version "0")
922 (bug-report-address "bug-guix@gnu.org")
923 (home-page-url "https://guix.gnu.org"))
925 ;; Hack so that Geiser is not confused.
926 (define defmod 'define-module)
928 (scheme-file "config.scm"
929 #~(;; The following expressions get spliced.
930 (#$defmod (guix config)
931 #:export (%guix-package-name
933 %guix-bug-report-address
938 %store-database-directory
949 #$@(map (match-lambda
951 #~(define-public #$name #$value)))
954 (define %store-directory
955 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
958 (define %state-directory
959 ;; This must match `NIX_STATE_DIR' as defined in
961 (or (getenv "GUIX_STATE_DIRECTORY")
962 (string-append %localstatedir "/guix")))
964 (define %store-database-directory
965 (or (getenv "GUIX_DATABASE_DIRECTORY")
966 (string-append %state-directory "/db")))
968 (define %config-directory
969 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
970 ;; defined in `nix/local.mk'.
971 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
972 (string-append %sysconfdir "/guix")))
974 (define %guix-package-name #$package-name)
975 (define %guix-version #$package-version)
976 (define %guix-bug-report-address #$bug-report-address)
977 (define %guix-home-page-url #$home-page-url)
980 #+(and gzip (file-append gzip "/bin/gzip")))
982 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
984 #+(and xz (file-append xz "/bin/xz")))
988 (file-append zlib "/lib/libz")))
992 (file-append lzlib "/lib/liblz"))))
994 ;; Guile 2.0 *requires* the 'define-module' to be at the
995 ;; top-level or the 'toplevel-ref' in the resulting .go file are
996 ;; made relative to a nonexistent anonymous module.
1004 (define* (compiled-modules name module-tree module-files
1007 (dependencies-compiled '())
1009 (extensions '()) ;full-blown Guile packages
1012 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
1013 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
1014 containing MODULE-FILES and possibly other files as well."
1015 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1018 (with-imported-modules (source-module-closure
1019 '((guix build compile)
1020 (guix build utils)))
1022 (use-modules (srfi srfi-26)
1026 (guix build compile)
1029 (define (regular? file)
1030 (not (member file '("." ".."))))
1032 (define (report-load file total completed)
1035 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1037 ;; Note: Multiply TOTAL by two to account for the
1038 ;; compilation phase that follows.
1039 completed (* total 2)
1041 (* 100. (/ completed total)) total)
1044 (define (report-compilation file total completed)
1046 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1048 ;; Add TOTAL to account for the load phase that came
1050 (+ total completed) (* total 2)
1052 (* 100. (/ completed total)) total)
1055 (define (process-directory directory files output)
1056 ;; Hide compilation warnings.
1057 (parameterize ((current-warning-port (%make-void-port "w")))
1058 (compile-files directory #$output files
1059 #:workers (parallel-job-count)
1060 #:report-load report-load
1061 #:report-compilation report-compilation)))
1063 (setvbuf (current-output-port) 'line)
1064 (setvbuf (current-error-port) 'line)
1066 (set! %load-path (cons #+module-tree %load-path))
1068 (append '#+dependencies
1069 (map (lambda (extension)
1070 (string-append extension "/share/guile/site/"
1071 (effective-version)))
1075 (set! %load-compiled-path
1076 (append '#+dependencies-compiled
1077 (map (lambda (extension)
1078 (string-append extension "/lib/guile/"
1082 %load-compiled-path))
1084 ;; Load the compiler modules upfront.
1088 (chdir #+module-tree)
1089 (process-directory "." '#+module-files #$output)
1092 (computed-file name build
1093 #:guile guile-for-build
1095 `(#:local-build? #f ;allow substitutes
1097 ;; Don't annoy people about _IONBF deprecation.
1098 ;; Initialize 'terminal-width' in (system repl debug)
1099 ;; to a large-enough value to make backtrace more
1101 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1102 ("COLUMNS" . "200")))))
1109 (define* (guix-derivation source version
1110 #:optional (guile-version (effective-version))
1111 #:key (pull-version 0))
1112 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1113 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
1114 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
1116 (define (shorten version)
1117 (if (and (string-every char-set:hex-digit version)
1118 (> (string-length version) 9))
1119 (string-take version 9) ;Git commit
1123 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2
1127 (when (and (< pull-version 1)
1128 (not (string=? (package-version guile) guile-version)))
1129 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1130 ;; can be any version. When that happens and Guile is not current (e.g.,
1131 ;; it's Guile 2.0), just bail out.
1134 (message "Guix is too old and cannot be upgraded")))))
1136 (mbegin %store-monad
1137 (set-guile-for-build guile)
1138 (let ((guix (compiled-guix source
1140 #:name (string-append "guix-"
1142 #:pull-version pull-version
1143 #:guile-version (if (>= pull-version 1)
1144 "2.2" guile-version)
1145 #:guile-for-build guile)))