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 ("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")
128 (define (node-fold proc init nodes)
129 (let loop ((nodes nodes)
135 (if (set-contains? visited head)
136 (loop tail visited result)
137 (loop tail (set-insert head visited)
138 (proc head result)))))))
140 (define (node-modules/recursive nodes)
141 (node-fold (lambda (node modules)
142 (append (node-modules node) modules))
146 (define* (closure modules #:optional (except '()))
147 (source-module-closure modules
153 (or ('guix _ ...) ('gnu _ ...)))
154 (not (member module except)))
157 (define module->import
158 ;; Return a file-name/file-like object pair for the specified module and
159 ;; suitable for 'imported-files'.
162 (let ((file (module-name->file-name module)))
165 (let ((file (module-name->file-name module)))
167 (local-file (search-path %load-path file)))))))
169 (define* (scheme-node name modules #:optional (dependencies '())
170 #:key (extra-modules '()) (extra-files '())
172 parallel? guile-for-build)
173 "Return a node that builds the given Scheme MODULES, and depends on
174 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
175 added to the source, and EXTRA-FILES is a list of additional files.
176 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
177 must be present in the search path."
178 (let* ((modules (append extra-modules
180 (node-modules/recursive dependencies))))
181 (module-files (map module->import modules))
182 (source (file-mapping (string-append name "-source")
183 (append module-files extra-files))))
184 (node name modules source dependencies
185 (compiled-modules name source
186 (map car module-files)
187 (map node-source dependencies)
188 (map node-compiled dependencies)
189 #:extensions extensions
190 #:parallel? parallel?
191 #:guile-for-build guile-for-build))))
193 (define (file-imports directory sub-directory pred)
194 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
195 list of file-name/file-like objects suitable as inputs to 'imported-files'."
197 (list (string-drop file (+ 1 (string-length directory)))
198 (local-file file #:recursive? #t)))
199 (find-files (string-append directory "/" sub-directory) pred)))
201 (define* (file-append* item file #:key (recursive? #t))
202 "Return FILE within ITEM, which may be a file name or a file-like object.
203 When ITEM is a plain file name (a string), simply return a 'local-file'
204 record with the new file name."
207 ;; This is the optimal case: we return a new "source". Thus, a
208 ;; derivation that depends on this sub-directory does not depend on ITEM
210 (local-file (string-append item "/" file)
211 #:recursive? recursive?))
212 ;; TODO: Add 'local-file?' case.
214 ;; In this case, anything that refers to the result also depends on ITEM,
215 ;; which isn't great.
216 (file-append item "/" file))))
218 (define* (locale-data source domain
219 #:optional (directory domain))
220 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
221 DOMAIN, a gettext domain."
223 (module-ref (resolve-interface '(gnu packages gettext))
227 (with-imported-modules '((guix build utils))
229 (use-modules (guix build utils)
231 (ice-9 match) (ice-9 ftw))
234 #+(file-append* source (string-append "po/" directory)))
236 (define (compile language)
237 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
239 (mkdir-p (dirname gmo))
240 (invoke #+(file-append gettext "/bin/msgfmt")
241 "-c" "--statistics" "--verbose"
243 (string-append po-directory "/" language ".po"))))
246 ;; Return the list of languages. Note: don't read 'LINGUAS'
247 ;; because it contains things like 'en@boldquot' that do not have
248 ;; a corresponding .po file.
249 (map (cut basename <> ".po")
250 (scandir po-directory
251 (cut string-suffix? ".po" <>))))
253 (for-each compile (linguas)))))
255 (computed-file (string-append "guix-locale-" domain)
258 (define (translate-texi-manuals source)
259 "Return the translated texinfo manuals built from SOURCE."
261 (specification->package "po4a"))
264 (specification->package "gettext"))
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"))
273 (define documentation-po
274 (file-append* source "po/doc"))
277 (with-imported-modules '((guix build utils) (guix build po))
279 (use-modules (guix build utils) (guix build po)
280 (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
285 (copy-recursively #$documentation "."
286 #:log (%make-void-port "w"))
290 (copy-file file (basename file)))
291 (find-files #$documentation-po ".*.po$"))
293 (setenv "GUIX_LOCPATH"
294 #+(file-append glibc-utf8-locales "/lib/locale"))
295 (setenv "PATH" #+(file-append gettext "/bin"))
296 (setenv "LC_ALL" "en_US.UTF-8")
297 (setlocale LC_ALL "en_US.UTF-8")
299 (define (translate-tmp-texi po source output)
300 "Translate Texinfo file SOURCE using messages from PO, and write
301 the result to OUTPUT."
302 (invoke #+(file-append po4a "/bin/po4a-translate")
303 "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
304 "-m" source "-p" po "-l" output))
306 (define (make-ref-regex msgid end)
307 (make-regexp (string-append
309 (string-join (string-split (regexp-quote msgid) #\ )
313 (define (translate-cross-references content translations)
314 "Take CONTENT, a string representing a .texi file and translate any
315 cross-reference in it (@ref, @xref and @pxref) that have a translation in
316 TRANSLATIONS, an alist of msgid and msgstr."
318 (lambda (elem content)
321 ;; Empty translations and strings containing some special characters
322 ;; cannot be the name of a section.
323 (if (or (equal? msgstr "")
324 (string-any (lambda (chr)
325 (member chr '(#\{ #\} #\( #\) #\newline #\,)))
328 ;; Otherwise, they might be the name of a section, so we
329 ;; need to translate any occurence in @(p?x?)ref{...}.
330 (let ((regexp1 (make-ref-regex msgid ","))
331 (regexp2 (make-ref-regex msgid "\\}")))
332 (regexp-substitute/global
334 (regexp-substitute/global
335 #f regexp1 content 'pre "ref{" msgstr "," 'post)
336 'pre "ref{" msgstr "}" 'post))))))
337 content translations))
339 (define (translate-texi po lang)
340 "Translate the manual for one language LANG using the PO file."
341 (let ((translations (call-with-input-file po read-po-file)))
342 (translate-tmp-texi po "guix.texi"
343 (string-append "guix." lang ".texi.tmp"))
344 (translate-tmp-texi po "contributing.texi"
345 (string-append "contributing." lang ".texi.tmp"))
346 (let* ((texi-name (string-append "guix." lang ".texi"))
347 (tmp-name (string-append texi-name ".tmp")))
348 (with-output-to-file texi-name
351 (translate-cross-references
352 (call-with-input-file tmp-name get-string-all)
354 (let* ((texi-name (string-append "contributing." lang ".texi"))
355 (tmp-name (string-append texi-name ".tmp")))
356 (with-output-to-file texi-name
359 (translate-cross-references
360 (call-with-input-file tmp-name get-string-all)
363 (for-each (lambda (po)
364 (match (reverse (string-split po #\.))
366 (translate-texi po lang))))
367 (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$"))
371 (copy-file file (string-append #$output "/" file)))
373 (find-files "." "contributing\\..*\\.texi$")
374 (find-files "." "guix\\..*\\.texi$"))))))
376 (computed-file "guix-translated-texinfo" build))
378 (define (info-manual source)
379 "Return the Info manual built from SOURCE."
381 (specification->package "po4a"))
384 (specification->package "gettext"))
387 (module-ref (resolve-interface '(gnu packages texinfo))
391 (module-ref (resolve-interface '(gnu packages graphviz))
394 (define glibc-utf8-locales
395 (module-ref (resolve-interface '(gnu packages base))
396 'glibc-utf8-locales))
398 (define documentation
399 (file-append* source "doc"))
402 (file-append* source "gnu/system/examples"))
405 (with-imported-modules '((guix build utils))
407 (use-modules (guix build utils))
411 ;; Create 'version.texi'.
412 ;; XXX: Can we use a more meaningful version string yet one that
413 ;; doesn't change at each commit?
414 (call-with-output-file "version.texi"
416 (let ((version "0.0-git"))
418 @set UPDATED 1 January 1970
419 @set UPDATED-MONTH January 1970
421 @set VERSION ~a\n" version version))))
423 ;; Copy configuration templates that the manual includes.
424 (for-each (lambda (template)
428 (basename template ".tmpl")
430 (find-files #$examples "\\.tmpl$"))
433 (mkdir-p (string-append #$output "/images"))
434 (for-each (lambda (dot-file)
435 (invoke #+(file-append graphviz "/bin/dot")
436 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
437 "-Granksep=.00005" "-Nfontsize=9"
438 "-Nheight=.1" "-Nwidth=.1"
439 "-o" (string-append #$output "/images/"
440 (basename dot-file ".dot")
443 (find-files (string-append #$documentation "/images")
447 (for-each (lambda (png-file)
448 (install-file png-file
449 (string-append #$output "/images")))
450 (find-files (string-append #$documentation "/images")
453 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
454 ;; add a symlink to the 'images' directory so that 'makeinfo' can
455 ;; see those images and produce image references in the Info output.
456 (copy-recursively #$documentation "."
457 #:log (%make-void-port "w"))
458 (copy-recursively #+(translate-texi-manuals source) "."
459 #:log (%make-void-port "w"))
460 (delete-file-recursively "images")
461 (symlink (string-append #$output "/images") "images")
463 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
464 (setenv "GUIX_LOCPATH"
465 #+(file-append glibc-utf8-locales "/lib/locale"))
467 (for-each (lambda (texi)
468 (unless (string=? "guix.texi" texi)
469 ;; Create 'version-LL.texi'.
470 (let* ((base (basename texi ".texi"))
471 (dot (string-index base #\.))
472 (tag (string-drop base (+ 1 dot))))
473 (symlink "version.texi"
474 (string-append "version-" tag ".texi"))))
476 (invoke #+(file-append texinfo "/bin/makeinfo")
477 texi "-I" #$documentation
479 "-o" (string-append #$output "/"
480 (basename texi ".texi")
483 (find-files "." "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")))
485 ;; Compress Info files.
487 #+(file-append (specification->package "gzip") "/bin"))
488 (for-each (lambda (file)
489 (invoke "gzip" "-9n" file))
490 (find-files #$output "\\.info(-[0-9]+)?$")))))
492 (computed-file "guix-manual" build))
494 (define* (guile-module-union things #:key (name "guix-module-union"))
495 "Return the union of the subset of THINGS (packages, computed files, etc.)
496 that provide Guile modules."
498 (with-imported-modules '((guix build union))
500 (use-modules (guix build union))
502 (define (modules directory)
503 (string-append directory "/share/guile/site"))
505 (define (objects directory)
506 (string-append directory "/lib/guile"))
508 (union-build #$output
509 (filter (lambda (directory)
510 (or (file-exists? (modules directory))
511 (file-exists? (objects directory))))
514 #:log-port (%make-void-port "w")))))
516 (computed-file name build))
518 (define* (guix-command modules
519 #:key source (dependencies '())
520 guile (guile-version (effective-version)))
521 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
523 (define glibc-utf8-locales
524 (module-ref (resolve-interface '(gnu packages base))
525 'glibc-utf8-locales))
527 (define module-directory
528 ;; To minimize the number of 'stat' calls needed to locate a module,
529 ;; create the union of all the module directories.
530 (guile-module-union (cons modules dependencies)))
532 (program-file "guix-command"
535 (cons (string-append #$module-directory
540 (set! %load-compiled-path
541 (cons (string-append #$module-directory
545 %load-compiled-path))
547 ;; To maximize the chances that locales are set up right
548 ;; out-of-the-box, bundle "common" UTF-8 locales.
549 (let ((locpath (getenv "GUIX_LOCPATH")))
550 (setenv "GUIX_LOCPATH"
551 (string-append (if locpath
552 (string-append locpath ":")
554 #$(file-append glibc-utf8-locales
557 (let ((guix-main (module-ref (resolve-interface '(guix ui))
561 (bindtextdomain "guix"
562 #$(locale-data source "guix"))
563 (bindtextdomain "guix-packages"
564 #$(locale-data source
569 ;; XXX: It would be more convenient to change it to:
570 ;; (exit (apply guix-main (command-line)))
571 (apply guix-main (command-line))))
574 (define (miscellaneous-files source)
575 "Return data files taken from SOURCE."
576 (file-mapping "guix-misc"
577 `(("etc/bash_completion.d/guix"
578 ,(file-append* source "/etc/completion/bash/guix"))
579 ("etc/bash_completion.d/guix-daemon"
580 ,(file-append* source "/etc/completion/bash/guix-daemon"))
581 ("share/zsh/site-functions/_guix"
582 ,(file-append* source "/etc/completion/zsh/_guix"))
583 ("share/fish/vendor_completions.d/guix.fish"
584 ,(file-append* source "/etc/completion/fish/guix.fish"))
585 ("share/guix/hydra.gnu.org.pub"
586 ,(file-append* source
587 "/etc/substitutes/hydra.gnu.org.pub"))
588 ("share/guix/berlin.guixsd.org.pub"
589 ,(file-append* source
590 "/etc/substitutes/berlin.guixsd.org.pub"))
591 ("share/guix/ci.guix.gnu.org.pub" ;alias
592 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub"))
593 ("share/guix/ci.guix.info.pub" ;alias
594 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub")))))
596 (define* (whole-package name modules dependencies
598 (guile-version (effective-version))
599 info daemon miscellany
601 (command (guix-command modules
602 #:dependencies dependencies
604 #:guile-version guile-version)))
605 "Return the whole Guix package NAME that uses MODULES, a derivation of all
606 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
607 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
609 (define (wrap daemon)
610 (program-file "guix-daemon"
612 (setenv "GUIX" #$command)
613 (apply execl #$(file-append daemon "/bin/guix-daemon")
614 "guix-daemon" (cdr (command-line))))))
617 (with-imported-modules '((guix build utils))
619 (use-modules (guix build utils))
622 #$(and daemon (wrap daemon)))
624 (mkdir-p (string-append #$output "/bin"))
626 (string-append #$output "/bin/guix"))
630 (string-append #$output "/bin/guix-daemon")))
632 (let ((share (string-append #$output "/share"))
633 (lib (string-append #$output "/lib"))
636 (symlink #$(file-append modules "/share/guile")
637 (string-append share "/guile"))
639 (symlink #$info (string-append share "/info")))
642 (symlink #$(file-append modules "/lib/guile")
643 (string-append lib "/guile")))
646 (copy-recursively #$miscellany #$output
647 #:log (%make-void-port "w")))))))
649 (define* (compiled-guix source #:key (version %guix-version)
651 (name (string-append "guix-" version))
652 (guile-version (effective-version))
653 (guile-for-build (default-guile))
654 (zlib (specification->package "zlib"))
655 (gzip (specification->package "gzip"))
656 (bzip2 (specification->package "bzip2"))
657 (xz (specification->package "xz"))
658 (guix (specification->package "guix")))
659 "Return a file-like object that contains a compiled Guix."
661 (specification->package "guile-json"))
664 (specification->package "guile-ssh"))
667 (specification->package "guile-git"))
669 (define guile-sqlite3
670 (specification->package "guile-sqlite3"))
673 (specification->package "guile-gcrypt"))
676 (specification->package "gnutls"))
679 (match (append-map (lambda (package)
680 (cons (list "x" package)
681 (package-transitive-propagated-inputs package)))
682 (list guile-gcrypt gnutls guile-git guile-json
683 guile-ssh guile-sqlite3))
684 (((labels packages _ ...) ...)
687 (define *core-modules*
688 (scheme-node "guix-core"
695 (guix build-system gnu)
696 (guix build-system trivial)
697 (guix build profiles)
698 (guix build gnu-build-system))
700 ;; Provide a dummy (guix config) with the default version
701 ;; number, storedir, etc. This is so that "guix-core" is the
702 ;; same across all installations and doesn't need to be
703 ;; rebuilt when the version changes, which in turn means we
704 ;; can have substitutes for it.
706 `(((guix config) => ,(make-config.scm)))
708 ;; (guix man-db) is needed at build-time by (guix profiles)
709 ;; but we don't need to compile it; not compiling it allows
710 ;; us to avoid an extra dependency on guile-gdbm-ffi.
712 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
713 ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
714 ("guix/store/schema.sql"
715 ,(local-file "../guix/store/schema.sql")))
717 #:extensions (list guile-gcrypt)
718 #:guile-for-build guile-for-build))
720 (define *extra-modules*
721 (scheme-node "guix-extra"
722 (filter-map (match-lambda
723 (('guix 'scripts _ ..1) #f)
726 (scheme-modules* source "guix"))
727 (list *core-modules*)
728 #:extensions dependencies
729 #:guile-for-build guile-for-build))
731 (define *core-package-modules*
732 (scheme-node "guix-packages-base"
735 (list *core-modules* *extra-modules*)
736 #:extensions dependencies
738 ;; Add all the non-Scheme files here. We must do it here so
739 ;; that 'search-patches' & co. can find them. Ideally we'd
740 ;; keep them next to the .scm files that use them but it's
741 ;; difficult to do (XXX).
743 (file-imports source "gnu/packages"
745 (and (eq? 'regular (stat:type stat))
746 (not (string-suffix? ".scm" file))
747 (not (string-suffix? ".go" file))
748 (not (string-prefix? ".#" file))
749 (not (string-suffix? "~" file)))))
750 #:guile-for-build guile-for-build))
752 (define *package-modules*
753 (scheme-node "guix-packages"
754 (scheme-modules* source "gnu/packages")
755 (list *core-modules* *extra-modules* *core-package-modules*)
756 #:extensions dependencies
757 #:guile-for-build guile-for-build))
759 (define *system-modules*
760 (scheme-node "guix-system"
763 ,@(scheme-modules* source "gnu/bootloader")
764 ,@(scheme-modules* source "gnu/system")
765 ,@(scheme-modules* source "gnu/services"))
766 (list *core-package-modules* *package-modules*
767 *extra-modules* *core-modules*)
768 #:extensions dependencies
770 (append (file-imports source "gnu/system/examples"
773 ;; All the installer code is on the build-side.
774 (file-imports source "gnu/installer/"
776 ;; Build-side code that we don't build. Some of
777 ;; these depend on guile-rsvg, the Shepherd, etc.
778 (file-imports source "gnu/build" (const #t)))
782 (define *cli-modules*
783 (scheme-node "guix-cli"
784 (append (scheme-modules* source "/guix/scripts")
786 (list *core-modules* *extra-modules*
787 *core-package-modules* *package-modules*
789 #:extensions dependencies
790 #:guile-for-build guile-for-build))
792 (define *system-test-modules*
793 ;; Ship these modules mostly so (gnu ci) can discover them.
794 (scheme-node "guix-system-tests"
796 ,@(scheme-modules* source "gnu/tests"))
797 (list *core-package-modules* *package-modules*
798 *extra-modules* *system-modules* *core-modules*
799 *cli-modules*) ;for (guix scripts pack), etc.
800 #:extensions dependencies
801 #:guile-for-build guile-for-build))
804 (scheme-node "guix-config"
808 => ,(make-config.scm #:zlib zlib
817 %guix-bug-report-address
819 %guix-home-page-url)))
820 #:guile-for-build guile-for-build))
822 (define (built-modules node-subset)
823 (directory-union (string-append name "-modules")
824 (append-map node-subset
826 ;; Note: *CONFIG* comes first so that it
827 ;; overrides the (guix config) module that
828 ;; comes with *CORE-MODULES*.
831 *system-test-modules*
834 *core-package-modules*
838 ;; Silently choose the first entry upon collision so that
839 ;; we choose *CONFIG*.
840 #:resolve-collision 'first
842 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
843 ;; be a regular file, not a symlink. Thus, arrange so that
844 ;; regular files appear as regular files in the final
849 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
850 ;; Version 1 is when we return the full package.
851 (cond ((= 1 pull-version)
852 ;; The whole package, with a standard file hierarchy.
853 (let* ((modules (built-modules (compose list node-source+compiled)))
854 (command (guix-command modules
856 #:dependencies dependencies
857 #:guile guile-for-build
858 #:guile-version guile-version)))
859 (whole-package name modules dependencies
861 #:guile guile-for-build
863 ;; Include 'guix-daemon'. XXX: Here we inject an
864 ;; older snapshot of guix-daemon, but that's a good
865 ;; enough approximation for now.
866 #:daemon (module-ref (resolve-interface
871 #:info (info-manual source)
872 #:miscellany (miscellaneous-files source)
873 #:guile-version guile-version)))
875 ;; Legacy 'guix pull': return the .scm and .go files as one
877 (built-modules (lambda (node)
878 (list (node-source node)
879 (node-compiled node)))))
881 ;; Unsupported 'guix pull' version.
886 ;;; Generating (guix config).
889 (define %persona-variables
890 ;; (guix config) variables that define Guix's persona.
893 %guix-bug-report-address
894 %guix-home-page-url))
896 (define %config-variables
897 ;; (guix config) variables corresponding to Guix configuration.
898 (letrec-syntax ((variables (syntax-rules ()
901 ((_ variable rest ...)
902 (cons `(variable . ,variable)
903 (variables rest ...))))))
904 (variables %localstatedir %storedir %sysconfdir)))
906 (define* (make-config.scm #:key zlib gzip xz bzip2
907 (package-name "GNU Guix")
908 (package-version "0")
909 (bug-report-address "bug-guix@gnu.org")
910 (home-page-url "https://gnu.org/s/guix"))
912 ;; Hack so that Geiser is not confused.
913 (define defmod 'define-module)
915 (scheme-file "config.scm"
916 #~(;; The following expressions get spliced.
917 (#$defmod (guix config)
918 #:export (%guix-package-name
920 %guix-bug-report-address
925 %store-database-directory
936 #$@(map (match-lambda
938 #~(define-public #$name #$value)))
941 (define %store-directory
942 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
945 (define %state-directory
946 ;; This must match `NIX_STATE_DIR' as defined in
948 (or (getenv "GUIX_STATE_DIRECTORY")
949 (string-append %localstatedir "/guix")))
951 (define %store-database-directory
952 (or (getenv "GUIX_DATABASE_DIRECTORY")
953 (string-append %state-directory "/db")))
955 (define %config-directory
956 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
957 ;; defined in `nix/local.mk'.
958 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
959 (string-append %sysconfdir "/guix")))
961 (define %guix-package-name #$package-name)
962 (define %guix-version #$package-version)
963 (define %guix-bug-report-address #$bug-report-address)
964 (define %guix-home-page-url #$home-page-url)
967 #+(and gzip (file-append gzip "/bin/gzip")))
969 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
971 #+(and xz (file-append xz "/bin/xz")))
975 (file-append zlib "/lib/libz"))))
977 ;; Guile 2.0 *requires* the 'define-module' to be at the
978 ;; top-level or the 'toplevel-ref' in the resulting .go file are
979 ;; made relative to a nonexistent anonymous module.
987 (define* (compiled-modules name module-tree module-files
990 (dependencies-compiled '())
992 (extensions '()) ;full-blown Guile packages
995 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
996 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
997 containing MODULE-FILES and possibly other files as well."
998 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1001 (with-imported-modules (source-module-closure
1002 '((guix build compile)
1003 (guix build utils)))
1005 (use-modules (srfi srfi-26)
1009 (guix build compile)
1012 (define (regular? file)
1013 (not (member file '("." ".."))))
1015 (define (report-load file total completed)
1018 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1020 ;; Note: Multiply TOTAL by two to account for the
1021 ;; compilation phase that follows.
1022 completed (* total 2)
1024 (* 100. (/ completed total)) total)
1027 (define (report-compilation file total completed)
1029 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1031 ;; Add TOTAL to account for the load phase that came
1033 (+ total completed) (* total 2)
1035 (* 100. (/ completed total)) total)
1038 (define (process-directory directory files output)
1039 ;; Hide compilation warnings.
1040 (parameterize ((current-warning-port (%make-void-port "w")))
1041 (compile-files directory #$output files
1042 #:workers (parallel-job-count)
1043 #:report-load report-load
1044 #:report-compilation report-compilation)))
1046 (setvbuf (current-output-port) 'line)
1047 (setvbuf (current-error-port) 'line)
1049 (set! %load-path (cons #+module-tree %load-path))
1051 (append '#+dependencies
1052 (map (lambda (extension)
1053 (string-append extension "/share/guile/site/"
1054 (effective-version)))
1058 (set! %load-compiled-path
1059 (append '#+dependencies-compiled
1060 (map (lambda (extension)
1061 (string-append extension "/lib/guile/"
1065 %load-compiled-path))
1067 ;; Load the compiler modules upfront.
1071 (chdir #+module-tree)
1072 (process-directory "." '#+module-files #$output)
1075 (computed-file name build
1076 #:guile guile-for-build
1078 `(#:local-build? #f ;allow substitutes
1080 ;; Don't annoy people about _IONBF deprecation.
1081 ;; Initialize 'terminal-width' in (system repl debug)
1082 ;; to a large-enough value to make backtrace more
1084 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1085 ("COLUMNS" . "200")))))
1092 (define* (guix-derivation source version
1093 #:optional (guile-version (effective-version))
1094 #:key (pull-version 0))
1095 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1096 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
1097 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
1099 (define (shorten version)
1100 (if (and (string-every char-set:hex-digit version)
1101 (> (string-length version) 9))
1102 (string-take version 9) ;Git commit
1106 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2
1110 (when (and (< pull-version 1)
1111 (not (string=? (package-version guile) guile-version)))
1112 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1113 ;; can be any version. When that happens and Guile is not current (e.g.,
1114 ;; it's Guile 2.0), just bail out.
1117 (message "Guix is too old and cannot be upgraded")))))
1119 (mbegin %store-monad
1120 (set-guile-for-build guile)
1121 (let ((guix (compiled-guix source
1123 #:name (string-append "guix-"
1125 #:pull-version pull-version
1126 #:guile-version (if (>= pull-version 1)
1127 "2.2" guile-version)
1128 #:guile-for-build guile)))