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 utils) #:select (version-major+minor))
31 #:use-module ((guix build utils) #:select (find-files))
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 guile) 'guile-3.0/libgc-7))
53 ("guile-json" (ref '(gnu packages guile) 'guile-json-4))
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-zlib" (ref '(gnu packages guile) 'guile-zlib))
58 ("guile-lzlib" (ref '(gnu packages guile) 'guile-lzlib))
59 ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
60 ("gnutls" (ref '(gnu packages tls) 'gnutls))
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 ("gcc-toolchain" (ref '(gnu packages commencement) 'gcc-toolchain))
67 (_ #f)))) ;no such package
74 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
75 ;; easier to express things this way.
76 (define-record-type <node>
77 (node name modules source dependencies compiled)
79 (name node-name) ;string
80 (modules node-modules) ;list of module names
81 (source node-source) ;list of source files
82 (dependencies node-dependencies) ;list of nodes
83 (compiled node-compiled)) ;node -> lowerable object
85 ;; File mappings are essentially an alist as passed to 'imported-files'.
86 (define-record-type <file-mapping>
87 (file-mapping name alist)
89 (name file-mapping-name)
90 (alist file-mapping-alist))
92 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
94 ;; Here we use 'imported-files', which can arrange to directly import all
95 ;; the files instead of creating a derivation, when possible.
96 (imported-files (map (match-lambda
97 ((destination (? local-file? file))
99 (local-file-absolute-file-name file)))
100 ((destination source)
101 (cons destination source))) ;silliness
102 (file-mapping-alist mapping))
103 #:name (file-mapping-name mapping)
106 (define (node-source+compiled node)
107 "Return a \"bundle\" containing both the source code and object files for
108 NODE's modules, under their FHS directories: share/guile/site and lib/guile."
110 (with-imported-modules '((guix build utils))
112 (use-modules (guix build utils))
115 (string-append #$output "/share/guile/site/"
116 (effective-version)))
119 (string-append #$output "/lib/guile/" (effective-version)
122 (mkdir-p (dirname source))
123 (symlink #$(node-source node) source)
124 (mkdir-p (dirname object))
125 (symlink #$(node-compiled node) object))))
127 (computed-file (string-append (node-name node) "-modules")
129 #:options '(#:local-build? #t
131 ;; "Building" it locally is faster.
132 #:substitutable? #f)))
134 (define (node-fold proc init nodes)
135 (let loop ((nodes nodes)
141 (if (set-contains? visited head)
142 (loop tail visited result)
143 (loop tail (set-insert head visited)
144 (proc head result)))))))
146 (define (node-modules/recursive nodes)
147 (node-fold (lambda (node modules)
148 (append (node-modules node) modules))
152 (define* (closure modules #:optional (except '()))
153 (source-module-closure modules
159 (or ('guix _ ...) ('gnu _ ...)))
160 (not (member module except)))
163 (define module->import
164 ;; Return a file-name/file-like object pair for the specified module and
165 ;; suitable for 'imported-files'.
168 (let ((file (module-name->file-name module)))
171 (let ((file (module-name->file-name module)))
173 (local-file (search-path %load-path file)))))))
175 (define* (scheme-node name modules #:optional (dependencies '())
176 #:key (extra-modules '()) (extra-files '())
178 parallel? guile-for-build)
179 "Return a node that builds the given Scheme MODULES, and depends on
180 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
181 added to the source, and EXTRA-FILES is a list of additional files.
182 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
183 must be present in the search path."
184 (let* ((modules (append extra-modules
186 (node-modules/recursive dependencies))))
187 (module-files (map module->import modules))
188 (source (file-mapping (string-append name "-source")
189 (append module-files extra-files))))
190 (node name modules source dependencies
191 (compiled-modules name source
192 (map car module-files)
193 (map node-source dependencies)
194 (map node-compiled dependencies)
195 #:extensions extensions
196 #:parallel? parallel?
197 #:guile-for-build guile-for-build))))
199 (define (file-imports directory sub-directory pred)
200 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
201 list of file-name/file-like objects suitable as inputs to 'imported-files'."
203 (list (string-drop file (+ 1 (string-length directory)))
204 (local-file file #:recursive? #t)))
205 (find-files (string-append directory "/" sub-directory) pred)))
207 (define* (file-append* item file #:key (recursive? #t))
208 "Return FILE within ITEM, which may be a file name or a file-like object.
209 When ITEM is a plain file name (a string), simply return a 'local-file'
210 record with the new file name."
213 ;; This is the optimal case: we return a new "source". Thus, a
214 ;; derivation that depends on this sub-directory does not depend on ITEM
216 (local-file (string-append item "/" file)
217 #:recursive? recursive?))
218 ((? local-file? base)
219 ;; Likewise, but with a <local-file>.
220 (if (local-file-recursive? base)
221 (local-file (string-append (local-file-absolute-file-name base)
224 #:recursive? recursive?
225 #:select? (local-file-select? base))
226 (file-append base file)))
228 ;; In this case, anything that refers to the result also depends on ITEM,
229 ;; which isn't great.
230 (file-append item "/" file))))
232 (define* (locale-data source domain
233 #:optional (directory domain))
234 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
235 DOMAIN, a gettext domain."
237 (module-ref (resolve-interface '(gnu packages gettext))
241 (with-imported-modules '((guix build utils))
243 (use-modules (guix build utils)
245 (ice-9 match) (ice-9 ftw))
248 #+(file-append* source (string-append "po/" directory)))
250 (define (compile language)
251 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
253 (mkdir-p (dirname gmo))
254 (invoke #+(file-append gettext "/bin/msgfmt")
255 "-c" "--statistics" "--verbose"
257 (string-append po-directory "/" language ".po"))))
260 ;; Return the list of languages. Note: don't read 'LINGUAS'
261 ;; because it contains things like 'en@boldquot' that do not have
262 ;; a corresponding .po file.
263 (map (cut basename <> ".po")
264 (scandir po-directory
265 (cut string-suffix? ".po" <>))))
267 (for-each compile (linguas)))))
269 (computed-file (string-append "guix-locale-" domain)
272 (define (translate-texi-manuals source)
273 "Return the translated texinfo manuals built from SOURCE."
275 (specification->package "po4a"))
278 (specification->package "gettext"))
280 (define glibc-utf8-locales
281 (module-ref (resolve-interface '(gnu packages base))
282 'glibc-utf8-locales))
284 (define documentation
285 (file-append* source "doc"))
287 (define documentation-po
288 (file-append* source "po/doc"))
291 (with-imported-modules '((guix build utils) (guix build po))
293 (use-modules (guix build utils) (guix build po)
294 (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
295 (ice-9 vlist) (ice-9 threads)
298 (define (translate-tmp-texi po source output)
299 "Translate Texinfo file SOURCE using messages from PO, and write
300 the result to OUTPUT."
301 (invoke #+(file-append po4a "/bin/po4a-translate")
302 "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
303 "-m" source "-p" po "-l" output))
305 (define (canonicalize-whitespace str)
306 ;; Change whitespace (newlines, etc.) in STR to #\space.
307 (string-map (lambda (chr)
308 (if (char-set-contains? char-set:whitespace chr)
314 ;; Texinfo cross-reference regexp.
315 (make-regexp "@(px|x)?ref\\{([^,}]+)"))
317 (define (translate-cross-references texi translations)
318 ;; Translate the cross-references that appear in TEXI, a Texinfo
319 ;; file, using the msgid/msgstr pairs from TRANSLATIONS.
321 (call-with-input-file texi get-string-all))
324 (list-matches xref-regexp content))
326 (define translation-map
328 (((msgid . str) result)
329 (vhash-cons msgid str result)))
334 ;; Iterate over MATCHES and replace cross-references with their
335 ;; translation found in TRANSLATION-MAP. (We can't use
336 ;; 'substitute*' because matches can span multiple lines.)
337 (let loop ((matches matches)
342 (string-concatenate-reverse
343 (cons (string-drop content offset) result)))
345 (let ((prefix (match:substring head 1))
346 (ref (canonicalize-whitespace (match:substring head 2))))
348 (string-append "@" (or prefix "")
350 (match (vhash-assoc ref translation-map)
356 (append (list translated
358 (string-drop content offset)
359 (- (match:start head) offset)))
362 (format (current-error-port)
363 "translated ~a cross-references in '~a'~%"
364 (length matches) texi)
365 (call-with-output-file texi
367 (display translated port))))
369 (define* (translate-texi prefix po lang
371 "Translate the manual for one language LANG using the PO file.
372 PREFIX must be the prefix of the manual, 'guix' or 'guix-cookbook'. EXTRAS is
373 a list of extra files, such as '(\"contributing\")."
374 (let ((translations (call-with-input-file po read-po-file)))
375 (for-each (lambda (file)
376 (translate-tmp-texi po (string-append file ".texi")
377 (string-append file "." lang
379 (cons prefix extras))
381 (for-each (lambda (file)
382 (let* ((texi (string-append file "." lang ".texi"))
383 (tmp (string-append texi ".tmp")))
385 (translate-cross-references texi
387 (cons prefix extras))))
389 (define (available-translations directory domain)
390 ;; Return the list of available translations under DIRECTORY for
391 ;; DOMAIN, a gettext domain such as "guix-manual". The result is
392 ;; a list of language/PO file pairs.
393 (filter-map (lambda (po)
394 (let ((base (basename po)))
395 (and (string-prefix? (string-append domain ".")
397 (match (string-split base #\.)
400 (find-files directory
401 "\\.[a-z]{2}(_[A-Z]{2})?\\.po$")))
403 (define parallel-jobs
404 ;; Limit thread creation by 'n-par-for-each'. Going beyond can
405 ;; lead libgc 8.0.4 to abort with:
406 ;; mmap(PROT_NONE) failed
407 (min (parallel-job-count) 4))
410 (copy-recursively #$documentation "."
411 #:log (%make-void-port "w"))
415 (copy-file file (basename file)))
416 (find-files #$documentation-po ".*.po$"))
418 (setenv "GUIX_LOCPATH"
419 #+(file-append glibc-utf8-locales "/lib/locale"))
420 (setenv "PATH" #+(file-append gettext "/bin"))
421 (setenv "LC_ALL" "en_US.UTF-8")
422 (setlocale LC_ALL "en_US.UTF-8")
424 (n-par-for-each parallel-jobs
427 (translate-texi "guix" po language
428 #:extras '("contributing"))))
429 (available-translations "." "guix-manual"))
431 (n-par-for-each parallel-jobs
434 (translate-texi "guix-cookbook" po language)))
435 (available-translations "." "guix-cookbook"))
437 (for-each (lambda (file)
438 (install-file file #$output))
440 (find-files "." "contributing\\..*\\.texi$")
441 (find-files "." "guix\\..*\\.texi$")
442 (find-files "." "guix-cookbook\\..*\\.texi$"))))))
444 (computed-file "guix-translated-texinfo" build))
446 (define (info-manual source)
447 "Return the Info manual built from SOURCE."
449 (module-ref (resolve-interface '(gnu packages texinfo))
453 (module-ref (resolve-interface '(gnu packages graphviz))
456 (define glibc-utf8-locales
457 (module-ref (resolve-interface '(gnu packages base))
458 'glibc-utf8-locales))
460 (define documentation
461 (file-append* source "doc"))
464 (file-append* source "gnu/system/examples"))
467 (with-imported-modules '((guix build utils))
469 (use-modules (guix build utils)
474 ;; Create 'version.texi'.
475 ;; XXX: Can we use a more meaningful version string yet one that
476 ;; doesn't change at each commit?
477 (call-with-output-file "version.texi"
479 (let ((version "0.0-git"))
481 @set UPDATED 1 January 1970
482 @set UPDATED-MONTH January 1970
484 @set VERSION ~a\n" version version))))
486 ;; Copy configuration templates that the manual includes.
487 (for-each (lambda (template)
491 (basename template ".tmpl")
493 (find-files #$examples "\\.tmpl$"))
496 (mkdir-p (string-append #$output "/images"))
497 (for-each (lambda (dot-file)
498 (invoke #+(file-append graphviz "/bin/dot")
499 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
500 "-Granksep=.00005" "-Nfontsize=9"
501 "-Nheight=.1" "-Nwidth=.1"
502 "-o" (string-append #$output "/images/"
503 (basename dot-file ".dot")
506 (find-files (string-append #$documentation "/images")
510 (for-each (lambda (png-file)
511 (install-file png-file
512 (string-append #$output "/images")))
513 (find-files (string-append #$documentation "/images")
516 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
517 ;; add a symlink to the 'images' directory so that 'makeinfo' can
518 ;; see those images and produce image references in the Info output.
519 (copy-recursively #$documentation "."
520 #:log (%make-void-port "w"))
521 (copy-recursively #+(translate-texi-manuals source) "."
522 #:log (%make-void-port "w"))
523 (delete-file-recursively "images")
524 (symlink (string-append #$output "/images") "images")
526 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
527 (setenv "GUIX_LOCPATH"
528 #+(file-append glibc-utf8-locales "/lib/locale"))
530 (for-each (lambda (texi)
531 (match (string-split (basename texi) #\.)
532 (("guix" language "texi")
533 ;; Create 'version-LL.texi'.
534 (symlink "version.texi"
535 (string-append "version-" language
539 (invoke #+(file-append texinfo "/bin/makeinfo")
540 texi "-I" #$documentation
542 "-o" (string-append #$output "/"
543 (basename texi ".texi")
546 (append (find-files "."
547 "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")
549 "^guix-cookbook.*\\.texi$"))))
551 ;; Compress Info files.
553 #+(file-append (specification->package "gzip") "/bin"))
554 (for-each (lambda (file)
555 (invoke "gzip" "-9n" file))
556 (find-files #$output "\\.info(-[0-9]+)?$")))))
558 (computed-file "guix-manual" build))
560 (define-syntax-rule (prevent-inlining! identifier ...)
561 (begin (set! identifier identifier) ...))
563 ;; XXX: These procedures are actually used by 'doc/build.scm'. Protect them
564 ;; from inlining on Guile 3.
565 (prevent-inlining! file-append* translate-texi-manuals info-manual)
567 (define* (guile-module-union things #:key (name "guix-module-union"))
568 "Return the union of the subset of THINGS (packages, computed files, etc.)
569 that provide Guile modules."
571 (with-imported-modules '((guix build union))
573 (use-modules (guix build union))
575 (define (modules directory)
576 (string-append directory "/share/guile/site"))
578 (define (objects directory)
579 (string-append directory "/lib/guile"))
581 (union-build #$output
582 (filter (lambda (directory)
583 (or (file-exists? (modules directory))
584 (file-exists? (objects directory))))
587 #:log-port (%make-void-port "w")))))
589 (computed-file name build))
591 (define (quiet-guile guile)
592 "Return a wrapper that does the same as the 'guile' executable of GUILE,
593 except that it does not complain about locales and falls back to 'en_US.utf8'
596 (specification->package "gcc-toolchain"))
599 (search-path %load-path
600 "gnu/packages/aux-files/guile-launcher.c"))
603 (version-major+minor (package-version guile)))
606 ;; XXX: Reuse <c-compiler> from (guix scripts pack) instead?
607 (with-imported-modules '((guix build utils))
609 (use-modules (guix build utils)
612 (mkdir-p (string-append #$output "/bin"))
614 (setenv "PATH" #$(file-append gcc "/bin"))
615 (setenv "C_INCLUDE_PATH"
617 (map (cut string-append <> "/include")
618 '#$(match (bag-transitive-build-inputs
619 (package->bag guile))
620 (((labels packages . _) ...)
621 (filter package? packages))))
623 (setenv "LIBRARY_PATH" #$(file-append gcc "/lib"))
625 (invoke "gcc" #$(local-file source) "-Wall" "-g0" "-O2"
626 "-I" #$(file-append guile "/include/guile/" effective)
627 "-L" #$(file-append guile "/lib")
628 #$(string-append "-lguile-" effective)
629 "-o" (string-append #$output "/bin/guile")))))
631 (computed-file "guile-wrapper" build))
633 (define* (guix-command modules
634 #:key source (dependencies '())
635 guile (guile-version (effective-version)))
636 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
638 (define glibc-utf8-locales
639 (module-ref (resolve-interface '(gnu packages base))
640 'glibc-utf8-locales))
642 (define module-directory
643 ;; To minimize the number of 'stat' calls needed to locate a module,
644 ;; create the union of all the module directories.
645 (guile-module-union (cons modules dependencies)))
647 (program-file "guix-command"
650 (cons (string-append #$module-directory
655 (set! %load-compiled-path
656 (cons (string-append #$module-directory
660 %load-compiled-path))
662 ;; To maximize the chances that locales are set up right
663 ;; out-of-the-box, bundle "common" UTF-8 locales.
664 (let ((locpath (getenv "GUIX_LOCPATH")))
665 (setenv "GUIX_LOCPATH"
666 (string-append (if locpath
667 (string-append locpath ":")
669 #$(file-append glibc-utf8-locales
672 (let ((guix-main (module-ref (resolve-interface '(guix ui))
676 (bindtextdomain "guix"
677 #$(locale-data source "guix"))
678 (bindtextdomain "guix-packages"
679 #$(locale-data source
684 ;; XXX: It would be more convenient to change it to:
685 ;; (exit (apply guix-main (command-line)))
686 (apply guix-main (command-line))))
688 ;; Use a 'guile' variant that doesn't complain about locales.
689 #:guile (quiet-guile guile)))
691 (define (miscellaneous-files source)
692 "Return data files taken from SOURCE."
693 (file-mapping "guix-misc"
694 `(("etc/bash_completion.d/guix"
695 ,(file-append* source "/etc/completion/bash/guix"))
696 ("etc/bash_completion.d/guix-daemon"
697 ,(file-append* source "/etc/completion/bash/guix-daemon"))
698 ("share/zsh/site-functions/_guix"
699 ,(file-append* source "/etc/completion/zsh/_guix"))
700 ("share/fish/vendor_completions.d/guix.fish"
701 ,(file-append* source "/etc/completion/fish/guix.fish"))
702 ("share/guix/berlin.guix.gnu.org.pub"
703 ,(file-append* source
704 "/etc/substitutes/berlin.guix.gnu.org.pub"))
705 ("share/guix/ci.guix.gnu.org.pub" ;alias
706 ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub"))
707 ("share/guix/ci.guix.info.pub" ;alias
708 ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub")))))
710 (define* (whole-package name modules dependencies
712 (guile-version (effective-version))
713 info daemon miscellany
715 (command (guix-command modules
716 #:dependencies dependencies
718 #:guile-version guile-version)))
719 "Return the whole Guix package NAME that uses MODULES, a derivation of all
720 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
721 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
723 (define (wrap daemon)
724 (program-file "guix-daemon"
726 ;; Refer to the right 'guix' command for 'guix
728 (setenv "GUIX" #$command)
730 ;; Honor the user's settings rather than those hardcoded
731 ;; in the 'guix-daemon' package.
732 (unless (getenv "GUIX_STATE_DIRECTORY")
733 (setenv "GUIX_STATE_DIRECTORY"
734 #$(string-append %localstatedir "/guix")))
735 (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
736 (setenv "GUIX_CONFIGURATION_DIRECTORY"
737 #$(string-append %sysconfdir "/guix")))
738 (unless (getenv "NIX_STORE_DIR")
739 (setenv "NIX_STORE_DIR" #$%storedir))
741 (apply execl #$(file-append daemon "/bin/guix-daemon")
742 "guix-daemon" (cdr (command-line))))))
745 (with-imported-modules '((guix build utils))
747 (use-modules (guix build utils))
750 #$(and daemon (wrap daemon)))
752 (mkdir-p (string-append #$output "/bin"))
754 (string-append #$output "/bin/guix"))
758 (string-append #$output "/bin/guix-daemon")))
760 (let ((share (string-append #$output "/share"))
761 (lib (string-append #$output "/lib"))
764 (symlink #$(file-append modules "/share/guile")
765 (string-append share "/guile"))
767 (symlink #$info (string-append share "/info")))
770 (symlink #$(file-append modules "/lib/guile")
771 (string-append lib "/guile")))
774 (copy-recursively #$miscellany #$output
775 #:log (%make-void-port "w")))))))
777 (define* (compiled-guix source #:key (version %guix-version)
779 (name (string-append "guix-" version))
780 (guile-version (effective-version))
781 (guile-for-build (default-guile))
782 (gzip (specification->package "gzip"))
783 (bzip2 (specification->package "bzip2"))
784 (xz (specification->package "xz"))
785 (guix (specification->package "guix")))
786 "Return a file-like object that contains a compiled Guix."
788 (specification->package "guile-json"))
791 (specification->package "guile-ssh"))
794 (specification->package "guile-git"))
796 (define guile-sqlite3
797 (specification->package "guile-sqlite3"))
800 (specification->package "guile-zlib"))
803 (specification->package "guile-lzlib"))
806 (specification->package "guile-gcrypt"))
809 (specification->package "gnutls"))
812 (match (append-map (lambda (package)
813 (cons (list "x" package)
814 (package-transitive-propagated-inputs package)))
815 (list guile-gcrypt gnutls guile-git guile-json
816 guile-ssh guile-sqlite3 guile-zlib guile-lzlib))
817 (((labels packages _ ...) ...)
820 (define *core-modules*
821 (scheme-node "guix-core"
828 (guix build-system gnu)
829 (guix build-system trivial)
830 (guix build profiles)
831 (guix build gnu-build-system))
833 ;; Provide a dummy (guix config) with the default version
834 ;; number, storedir, etc. This is so that "guix-core" is the
835 ;; same across all installations and doesn't need to be
836 ;; rebuilt when the version changes, which in turn means we
837 ;; can have substitutes for it.
839 `(((guix config) => ,(make-config.scm)))
841 ;; (guix man-db) is needed at build-time by (guix profiles)
842 ;; but we don't need to compile it; not compiling it allows
843 ;; us to avoid an extra dependency on guile-gdbm-ffi.
845 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
846 ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
847 ("guix/store/schema.sql"
848 ,(local-file "../guix/store/schema.sql")))
850 #:extensions (list guile-gcrypt)
851 #:guile-for-build guile-for-build))
853 (define *extra-modules*
854 (scheme-node "guix-extra"
855 (filter-map (match-lambda
856 (('guix 'scripts _ ..1) #f)
858 (('guix 'tests _ ...) #f)
860 (scheme-modules* source "guix"))
861 (list *core-modules*)
862 #:extensions dependencies
863 #:guile-for-build guile-for-build))
865 (define *core-package-modules*
866 (scheme-node "guix-packages-base"
869 (list *core-modules* *extra-modules*)
870 #:extensions dependencies
872 ;; Add all the non-Scheme files here. We must do it here so
873 ;; that 'search-patches' & co. can find them. Ideally we'd
874 ;; keep them next to the .scm files that use them but it's
875 ;; difficult to do (XXX).
877 (file-imports source "gnu/packages"
879 (and (eq? 'regular (stat:type stat))
880 (not (string-suffix? ".scm" file))
881 (not (string-suffix? ".go" file))
882 (not (string-prefix? ".#" file))
883 (not (string-suffix? "~" file)))))
884 #:guile-for-build guile-for-build))
886 (define *package-modules*
887 (scheme-node "guix-packages"
888 (scheme-modules* source "gnu/packages")
889 (list *core-modules* *extra-modules* *core-package-modules*)
890 #:extensions dependencies
891 #:guile-for-build guile-for-build))
893 (define *system-modules*
894 (scheme-node "guix-system"
897 ,@(scheme-modules* source "gnu/bootloader")
898 ,@(scheme-modules* source "gnu/system")
899 ,@(scheme-modules* source "gnu/services")
900 ,@(scheme-modules* source "gnu/machine"))
901 (list *core-package-modules* *package-modules*
902 *extra-modules* *core-modules*)
903 #:extensions dependencies
905 (append (file-imports source "gnu/system/examples"
908 ;; All the installer code is on the build-side.
909 (file-imports source "gnu/installer/"
911 ;; Build-side code that we don't build. Some of
912 ;; these depend on guile-rsvg, the Shepherd, etc.
913 (file-imports source "gnu/build" (const #t)))
917 (define *cli-modules*
918 (scheme-node "guix-cli"
919 (append (scheme-modules* source "/guix/scripts")
921 (list *core-modules* *extra-modules*
922 *core-package-modules* *package-modules*
924 #:extensions dependencies
925 #:guile-for-build guile-for-build))
927 (define *system-test-modules*
928 ;; Ship these modules mostly so (gnu ci) can discover them.
929 (scheme-node "guix-system-tests"
931 ,@(scheme-modules* source "gnu/tests"))
932 (list *core-package-modules* *package-modules*
933 *extra-modules* *system-modules* *core-modules*
934 *cli-modules*) ;for (guix scripts pack), etc.
935 #:extensions dependencies
936 #:guile-for-build guile-for-build))
939 (scheme-node "guix-config"
943 => ,(make-config.scm #:gzip gzip
951 %guix-bug-report-address
953 %guix-home-page-url)))
954 #:guile-for-build guile-for-build))
956 (define (built-modules node-subset)
957 (directory-union (string-append name "-modules")
958 (append-map node-subset
960 ;; Note: *CONFIG* comes first so that it
961 ;; overrides the (guix config) module that
962 ;; comes with *CORE-MODULES*.
965 *system-test-modules*
968 *core-package-modules*
972 ;; Silently choose the first entry upon collision so that
973 ;; we choose *CONFIG*.
974 #:resolve-collision 'first
976 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
977 ;; be a regular file, not a symlink. Thus, arrange so that
978 ;; regular files appear as regular files in the final
983 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
984 ;; Version 1 is when we return the full package.
985 (cond ((= 1 pull-version)
986 ;; The whole package, with a standard file hierarchy.
987 (let* ((modules (built-modules (compose list node-source+compiled)))
988 (command (guix-command modules
990 #:dependencies dependencies
991 #:guile guile-for-build
992 #:guile-version guile-version)))
993 (whole-package name modules dependencies
995 #:guile guile-for-build
997 ;; Include 'guix-daemon'. XXX: Here we inject an
998 ;; older snapshot of guix-daemon, but that's a good
999 ;; enough approximation for now.
1000 #:daemon (module-ref (resolve-interface
1002 package-management))
1005 #:info (info-manual source)
1006 #:miscellany (miscellaneous-files source)
1007 #:guile-version guile-version)))
1009 ;; Legacy 'guix pull': return the .scm and .go files as one
1011 (built-modules (lambda (node)
1012 (list (node-source node)
1013 (node-compiled node)))))
1015 ;; Unsupported 'guix pull' version.
1020 ;;; Generating (guix config).
1023 (define %persona-variables
1024 ;; (guix config) variables that define Guix's persona.
1025 '(%guix-package-name
1027 %guix-bug-report-address
1028 %guix-home-page-url))
1030 (define %config-variables
1031 ;; (guix config) variables corresponding to Guix configuration.
1032 (letrec-syntax ((variables (syntax-rules ()
1035 ((_ variable rest ...)
1036 (cons `(variable . ,variable)
1037 (variables rest ...))))))
1038 (variables %localstatedir %storedir %sysconfdir)))
1040 (define* (make-config.scm #:key gzip xz bzip2
1041 (package-name "GNU Guix")
1042 (package-version "0")
1043 (bug-report-address "bug-guix@gnu.org")
1044 (home-page-url "https://guix.gnu.org"))
1046 ;; Hack so that Geiser is not confused.
1047 (define defmod 'define-module)
1049 (scheme-file "config.scm"
1050 #~(;; The following expressions get spliced.
1051 (#$defmod (guix config)
1052 #:export (%guix-package-name
1054 %guix-bug-report-address
1059 %store-database-directory
1066 #$(%current-system))
1068 #$@(map (match-lambda
1070 #~(define-public #$name #$value)))
1073 (define %store-directory
1074 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
1077 (define %state-directory
1078 ;; This must match `NIX_STATE_DIR' as defined in
1080 (or (getenv "GUIX_STATE_DIRECTORY")
1081 (string-append %localstatedir "/guix")))
1083 (define %store-database-directory
1084 (or (getenv "GUIX_DATABASE_DIRECTORY")
1085 (string-append %state-directory "/db")))
1087 (define %config-directory
1088 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
1089 ;; defined in `nix/local.mk'.
1090 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
1091 (string-append %sysconfdir "/guix")))
1093 (define %guix-package-name #$package-name)
1094 (define %guix-version #$package-version)
1095 (define %guix-bug-report-address #$bug-report-address)
1096 (define %guix-home-page-url #$home-page-url)
1099 #+(and gzip (file-append gzip "/bin/gzip")))
1101 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
1103 #+(and xz (file-append xz "/bin/xz"))))
1105 ;; Guile 2.0 *requires* the 'define-module' to be at the
1106 ;; top-level or the 'toplevel-ref' in the resulting .go file are
1107 ;; made relative to a nonexistent anonymous module.
1115 (define* (compiled-modules name module-tree module-files
1118 (dependencies-compiled '())
1120 (extensions '()) ;full-blown Guile packages
1123 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
1124 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
1125 containing MODULE-FILES and possibly other files as well."
1126 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1129 (with-imported-modules (source-module-closure
1130 '((guix build compile)
1131 (guix build utils)))
1133 (use-modules (srfi srfi-26)
1137 (guix build compile)
1140 (define (regular? file)
1141 (not (member file '("." ".."))))
1143 (define (report-load file total completed)
1146 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1148 ;; Note: Multiply TOTAL by two to account for the
1149 ;; compilation phase that follows.
1150 completed (* total 2)
1152 (* 100. (/ completed total)) total)
1155 (define (report-compilation file total completed)
1157 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1159 ;; Add TOTAL to account for the load phase that came
1161 (+ total completed) (* total 2)
1163 (* 100. (/ completed total)) total)
1166 (define (process-directory directory files output)
1167 ;; Hide compilation warnings.
1168 (parameterize ((current-warning-port (%make-void-port "w")))
1169 (compile-files directory #$output files
1170 #:workers (parallel-job-count)
1171 #:report-load report-load
1172 #:report-compilation report-compilation)))
1174 (setvbuf (current-output-port) 'line)
1175 (setvbuf (current-error-port) 'line)
1177 (set! %load-path (cons #+module-tree %load-path))
1179 (append '#+dependencies
1180 (map (lambda (extension)
1181 (string-append extension "/share/guile/site/"
1182 (effective-version)))
1186 (set! %load-compiled-path
1187 (append '#+dependencies-compiled
1188 (map (lambda (extension)
1189 (string-append extension "/lib/guile/"
1193 %load-compiled-path))
1195 ;; Load the compiler modules upfront.
1199 (chdir #+module-tree)
1200 (process-directory "." '#+module-files #$output)
1203 (computed-file name build
1204 #:guile guile-for-build
1206 `(#:local-build? #f ;allow substitutes
1208 ;; Don't annoy people about _IONBF deprecation.
1209 ;; Initialize 'terminal-width' in (system repl debug)
1210 ;; to a large-enough value to make backtrace more
1212 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1213 ("COLUMNS" . "200")))))
1220 (define* (guix-derivation source version
1221 #:optional (guile-version (effective-version))
1222 #:key (pull-version 0))
1223 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1224 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
1225 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
1227 (define (shorten version)
1228 (if (and (string-every char-set:hex-digit version)
1229 (> (string-length version) 9))
1230 (string-take version 9) ;Git commit
1234 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use the
1235 ;; current Guile unconditionally.
1236 (specification->package "guile"))
1238 (when (and (< pull-version 1)
1239 (not (string=? (package-version guile) guile-version)))
1240 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1241 ;; can be any version. When that happens and Guile is not current (e.g.,
1242 ;; it's Guile 2.0), just bail out.
1245 (message "Guix is too old and cannot be upgraded")))))
1247 (mbegin %store-monad
1248 (set-guile-for-build guile)
1249 (let ((guix (compiled-guix source
1251 #:name (string-append "guix-"
1253 #:pull-version pull-version
1254 #:guile-version (if (>= pull-version 1)
1255 "3.0" guile-version)
1256 #:guile-for-build guile)))