1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix self)
21 #:use-module (guix config)
22 #:use-module (guix i18n)
23 #:use-module (guix modules)
24 #:use-module (guix gexp)
25 #:use-module (guix store)
26 #:use-module (guix monads)
27 #:use-module (guix discovery)
28 #:use-module (guix packages)
29 #:use-module (guix sets)
30 #:use-module (guix modules)
31 #:use-module ((guix utils) #:select (version-major+minor))
32 #:use-module ((guix build utils) #:select (find-files))
33 #:use-module (srfi srfi-1)
34 #:use-module (srfi srfi-9)
35 #:use-module (srfi srfi-35)
36 #:use-module (ice-9 match)
37 #:export (make-config.scm
38 whole-package ;for internal use in 'guix pull'
44 ;;; Dependency handling.
47 (define specification->package
48 ;; Use our own variant of that procedure because that of (gnu packages)
49 ;; would traverse all the .scm files, which is wasteful.
50 (let ((ref (lambda (module variable)
51 (module-ref (resolve-interface module) variable))))
53 ("guile" (ref '(gnu packages guile) 'guile-3.0/libgc-7))
54 ("guile-avahi" (ref '(gnu packages guile-xyz) 'guile-avahi))
55 ("guile-json" (ref '(gnu packages guile) 'guile-json-4))
56 ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh))
57 ("guile-git" (ref '(gnu packages guile) 'guile-git))
58 ("guile-semver" (ref '(gnu packages guile-xyz) 'guile-semver))
59 ("guile-lib" (ref '(gnu packages guile-xyz) 'guile-lib))
60 ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3))
61 ("guile-zlib" (ref '(gnu packages guile) 'guile-zlib))
62 ("guile-lzlib" (ref '(gnu packages guile) 'guile-lzlib))
63 ("guile-zstd" (ref '(gnu packages guile) 'guile-zstd))
64 ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
65 ("gnutls" (ref '(gnu packages tls) 'gnutls))
66 ("gzip" (ref '(gnu packages compression) 'gzip))
67 ("bzip2" (ref '(gnu packages compression) 'bzip2))
68 ("xz" (ref '(gnu packages compression) 'xz))
69 ("po4a" (ref '(gnu packages gettext) 'po4a))
70 ("gettext" (ref '(gnu packages gettext) 'gettext-minimal))
71 ("gcc-toolchain" (ref '(gnu packages commencement) 'gcc-toolchain))
72 (_ #f)))) ;no such package
79 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
80 ;; easier to express things this way.
81 (define-record-type <node>
82 (node name modules source dependencies compiled)
84 (name node-name) ;string
85 (modules node-modules) ;list of module names
86 (source node-source) ;list of source files
87 (dependencies node-dependencies) ;list of nodes
88 (compiled node-compiled)) ;node -> lowerable object
90 ;; File mappings are essentially an alist as passed to 'imported-files'.
91 (define-record-type <file-mapping>
92 (file-mapping name alist)
94 (name file-mapping-name)
95 (alist file-mapping-alist))
97 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
99 ;; Here we use 'imported-files', which can arrange to directly import all
100 ;; the files instead of creating a derivation, when possible.
101 (imported-files (map (match-lambda
102 ((destination (? local-file? file))
104 (local-file-absolute-file-name file)))
105 ((destination source)
106 (cons destination source))) ;silliness
107 (file-mapping-alist mapping))
108 #:name (file-mapping-name mapping)
111 (define (node-source+compiled node)
112 "Return a \"bundle\" containing both the source code and object files for
113 NODE's modules, under their FHS directories: share/guile/site and lib/guile."
115 (with-imported-modules '((guix build utils))
117 (use-modules (guix build utils))
120 (string-append #$output "/share/guile/site/"
121 (effective-version)))
124 (string-append #$output "/lib/guile/" (effective-version)
127 (mkdir-p (dirname source))
128 (symlink #$(node-source node) source)
129 (mkdir-p (dirname object))
130 (symlink #$(node-compiled node) object))))
132 (computed-file (string-append (node-name node) "-modules")
134 #:options '(#:local-build? #t
136 ;; "Building" it locally is faster.
137 #:substitutable? #f)))
139 (define (node-fold proc init nodes)
140 (let loop ((nodes nodes)
146 (if (set-contains? visited head)
147 (loop tail visited result)
148 (loop tail (set-insert head visited)
149 (proc head result)))))))
151 (define (node-modules/recursive nodes)
152 (node-fold (lambda (node modules)
153 (append (node-modules node) modules))
157 (define* (closure modules #:optional (except '()))
158 (source-module-closure modules
164 (or ('guix _ ...) ('gnu _ ...)))
165 (not (member module except)))
168 (define module->import
169 ;; Return a file-name/file-like object pair for the specified module and
170 ;; suitable for 'imported-files'.
173 (let ((file (module-name->file-name module)))
176 (let ((file (module-name->file-name module)))
178 (local-file (search-path %load-path file)))))))
180 (define* (scheme-node name modules #:optional (dependencies '())
181 #:key (extra-modules '()) (extra-files '())
183 parallel? guile-for-build)
184 "Return a node that builds the given Scheme MODULES, and depends on
185 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
186 added to the source, and EXTRA-FILES is a list of additional files.
187 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
188 must be present in the search path."
189 (let* ((modules (append extra-modules
191 (node-modules/recursive dependencies))))
192 (module-files (map module->import modules))
193 (source (file-mapping (string-append name "-source")
194 (append module-files extra-files))))
195 (node name modules source dependencies
196 (compiled-modules name source
197 (map car module-files)
198 (map node-source dependencies)
199 (map node-compiled dependencies)
200 #:extensions extensions
201 #:parallel? parallel?
202 #:guile-for-build guile-for-build))))
204 (define (file-imports directory sub-directory pred)
205 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
206 list of file-name/file-like objects suitable as inputs to 'imported-files'."
208 (list (string-drop file (+ 1 (string-length directory)))
209 (local-file file #:recursive? #t)))
210 (find-files (string-append directory "/" sub-directory) pred)))
212 (define* (file-append* item file #:key (recursive? #t))
213 "Return FILE within ITEM, which may be a file name or a file-like object.
214 When ITEM is a plain file name (a string), simply return a 'local-file'
215 record with the new file name."
218 ;; This is the optimal case: we return a new "source". Thus, a
219 ;; derivation that depends on this sub-directory does not depend on ITEM
221 (local-file (string-append item "/" file)
222 #:recursive? recursive?))
223 ((? local-file? base)
224 ;; Likewise, but with a <local-file>.
225 (if (local-file-recursive? base)
226 (local-file (string-append (local-file-absolute-file-name base)
229 #:recursive? recursive?
230 #:select? (local-file-select? base))
231 (file-append base file)))
233 ;; In this case, anything that refers to the result also depends on ITEM,
234 ;; which isn't great.
235 (file-append item "/" file))))
237 (define* (locale-data source domain
238 #:optional (directory domain))
239 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
240 DOMAIN, a gettext domain."
242 (module-ref (resolve-interface '(gnu packages gettext))
246 (with-imported-modules '((guix build utils))
248 (use-modules (guix build utils)
250 (ice-9 match) (ice-9 ftw))
253 #+(file-append* source (string-append "po/" directory)))
255 (define (compile language)
256 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
258 (mkdir-p (dirname gmo))
259 (invoke #+(file-append gettext "/bin/msgfmt")
260 "-c" "--statistics" "--verbose"
262 (string-append po-directory "/" language ".po"))))
265 ;; Return the list of languages. Note: don't read 'LINGUAS'
266 ;; because it contains things like 'en@boldquot' that do not have
267 ;; a corresponding .po file.
268 (map (cut basename <> ".po")
269 (scandir po-directory
270 (cut string-suffix? ".po" <>))))
272 (for-each compile (linguas)))))
274 (computed-file (string-append "guix-locale-" domain)
277 (define (translate-texi-manuals source)
278 "Return the translated texinfo manuals built from SOURCE."
280 (specification->package "po4a"))
283 (specification->package "gettext"))
285 (define glibc-utf8-locales
286 (module-ref (resolve-interface '(gnu packages base))
287 'glibc-utf8-locales))
289 (define documentation
290 (file-append* source "doc"))
292 (define documentation-po
293 (file-append* source "po/doc"))
296 (with-imported-modules '((guix build utils) (guix build po))
298 (use-modules (guix build utils) (guix build po)
299 (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
300 (ice-9 vlist) (ice-9 threads)
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 (canonicalize-whitespace str)
311 ;; Change whitespace (newlines, etc.) in STR to #\space.
312 (string-map (lambda (chr)
313 (if (char-set-contains? char-set:whitespace chr)
319 ;; Texinfo cross-reference regexp.
320 (make-regexp "@(px|x)?ref\\{([^,}]+)"))
322 (define (translate-cross-references texi translations)
323 ;; Translate the cross-references that appear in TEXI, a Texinfo
324 ;; file, using the msgid/msgstr pairs from TRANSLATIONS.
326 (call-with-input-file texi get-string-all))
329 (list-matches xref-regexp content))
331 (define translation-map
333 (((msgid . str) result)
334 (vhash-cons msgid str result)))
339 ;; Iterate over MATCHES and replace cross-references with their
340 ;; translation found in TRANSLATION-MAP. (We can't use
341 ;; 'substitute*' because matches can span multiple lines.)
342 (let loop ((matches matches)
347 (string-concatenate-reverse
348 (cons (string-drop content offset) result)))
350 (let ((prefix (match:substring head 1))
351 (ref (canonicalize-whitespace (match:substring head 2))))
353 (string-append "@" (or prefix "")
355 (match (vhash-assoc ref translation-map)
361 (append (list translated
363 (string-drop content offset)
364 (- (match:start head) offset)))
367 (format (current-error-port)
368 "translated ~a cross-references in '~a'~%"
369 (length matches) texi)
370 (call-with-output-file texi
372 (display translated port))))
374 (define* (translate-texi prefix po lang
376 "Translate the manual for one language LANG using the PO file.
377 PREFIX must be the prefix of the manual, 'guix' or 'guix-cookbook'. EXTRAS is
378 a list of extra files, such as '(\"contributing\")."
379 (let ((translations (call-with-input-file po read-po-file)))
380 (for-each (lambda (file)
381 (translate-tmp-texi po (string-append file ".texi")
382 (string-append file "." lang
384 (cons prefix extras))
386 (for-each (lambda (file)
387 (let* ((texi (string-append file "." lang ".texi"))
388 (tmp (string-append texi ".tmp")))
390 (translate-cross-references texi
392 (cons prefix extras))))
394 (define (available-translations directory domain)
395 ;; Return the list of available translations under DIRECTORY for
396 ;; DOMAIN, a gettext domain such as "guix-manual". The result is
397 ;; a list of language/PO file pairs.
398 (filter-map (lambda (po)
399 (let ((base (basename po)))
400 (and (string-prefix? (string-append domain ".")
402 (match (string-split base #\.)
405 (find-files directory
406 "\\.[a-z]{2}(_[A-Z]{2})?\\.po$")))
408 (define parallel-jobs
409 ;; Limit thread creation by 'n-par-for-each'. Going beyond can
410 ;; lead libgc 8.0.4 to abort with:
411 ;; mmap(PROT_NONE) failed
412 (min (parallel-job-count) 4))
415 (copy-recursively #$documentation "."
416 #:log (%make-void-port "w"))
420 (copy-file file (basename file)))
421 (find-files #$documentation-po ".*.po$"))
423 (setenv "GUIX_LOCPATH"
424 #+(file-append glibc-utf8-locales "/lib/locale"))
425 (setenv "PATH" #+(file-append gettext "/bin"))
426 (setenv "LC_ALL" "en_US.UTF-8")
427 (setlocale LC_ALL "en_US.UTF-8")
429 (n-par-for-each parallel-jobs
432 (translate-texi "guix" po language
433 #:extras '("contributing"))))
434 (available-translations "." "guix-manual"))
436 (n-par-for-each parallel-jobs
439 (translate-texi "guix-cookbook" po language)))
440 (available-translations "." "guix-cookbook"))
442 (for-each (lambda (file)
443 (install-file file #$output))
445 (find-files "." "contributing\\..*\\.texi$")
446 (find-files "." "guix\\..*\\.texi$")
447 (find-files "." "guix-cookbook\\..*\\.texi$"))))))
449 (computed-file "guix-translated-texinfo" build))
451 (define (info-manual source)
452 "Return the Info manual built from SOURCE."
454 (module-ref (resolve-interface '(gnu packages texinfo))
458 (module-ref (resolve-interface '(gnu packages graphviz))
461 (define glibc-utf8-locales
462 (module-ref (resolve-interface '(gnu packages base))
463 'glibc-utf8-locales))
465 (define documentation
466 (file-append* source "doc"))
469 (file-append* source "gnu/system/examples"))
472 (with-imported-modules '((guix build utils))
474 (use-modules (guix build utils)
479 ;; Create 'version.texi'.
480 ;; XXX: Can we use a more meaningful version string yet one that
481 ;; doesn't change at each commit?
482 (call-with-output-file "version.texi"
484 (let ((version "0.0-git"))
486 @set UPDATED 1 January 1970
487 @set UPDATED-MONTH January 1970
489 @set VERSION ~a\n" version version))))
491 ;; Copy configuration templates that the manual includes.
492 (for-each (lambda (template)
496 (basename template ".tmpl")
498 (find-files #$examples "\\.tmpl$"))
501 (mkdir-p (string-append #$output "/images"))
502 (for-each (lambda (dot-file)
503 (invoke #+(file-append graphviz "/bin/dot")
504 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
505 "-Granksep=.00005" "-Nfontsize=9"
506 "-Nheight=.1" "-Nwidth=.1"
507 "-o" (string-append #$output "/images/"
508 (basename dot-file ".dot")
511 (find-files (string-append #$documentation "/images")
515 (for-each (lambda (png-file)
516 (install-file png-file
517 (string-append #$output "/images")))
518 (find-files (string-append #$documentation "/images")
521 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
522 ;; add a symlink to the 'images' directory so that 'makeinfo' can
523 ;; see those images and produce image references in the Info output.
524 (copy-recursively #$documentation "."
525 #:log (%make-void-port "w"))
526 (copy-recursively #+(translate-texi-manuals source) "."
527 #:log (%make-void-port "w"))
528 (delete-file-recursively "images")
529 (symlink (string-append #$output "/images") "images")
531 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
532 (setenv "GUIX_LOCPATH"
533 #+(file-append glibc-utf8-locales "/lib/locale"))
535 (for-each (lambda (texi)
536 (match (string-split (basename texi) #\.)
537 (("guix" language "texi")
538 ;; Create 'version-LL.texi'.
539 (symlink "version.texi"
540 (string-append "version-" language
544 (invoke #+(file-append texinfo "/bin/makeinfo")
545 texi "-I" #$documentation
547 "-o" (string-append #$output "/"
548 (basename texi ".texi")
551 (append (find-files "."
552 "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")
554 "^guix-cookbook.*\\.texi$"))))
556 ;; Compress Info files.
558 #+(file-append (specification->package "gzip") "/bin"))
559 (for-each (lambda (file)
560 (invoke "gzip" "-9n" file))
561 (find-files #$output "\\.info(-[0-9]+)?$")))))
563 (computed-file "guix-manual" build))
565 (define-syntax-rule (prevent-inlining! identifier ...)
566 (begin (set! identifier identifier) ...))
568 ;; XXX: These procedures are actually used by 'doc/build.scm'. Protect them
569 ;; from inlining on Guile 3.
570 (prevent-inlining! file-append* translate-texi-manuals info-manual)
572 (define* (guile-module-union things #:key (name "guix-module-union"))
573 "Return the union of the subset of THINGS (packages, computed files, etc.)
574 that provide Guile modules."
576 (with-imported-modules '((guix build union))
578 (use-modules (guix build union))
580 (define (modules directory)
581 (string-append directory "/share/guile/site"))
583 (define (objects directory)
584 (string-append directory "/lib/guile"))
586 (union-build #$output
587 (filter (lambda (directory)
588 (or (file-exists? (modules directory))
589 (file-exists? (objects directory))))
592 #:log-port (%make-void-port "w")))))
594 (computed-file name build))
596 (define (quiet-guile guile)
597 "Return a wrapper that does the same as the 'guile' executable of GUILE,
598 except that it does not complain about locales and falls back to 'en_US.utf8'
601 (specification->package "gcc-toolchain"))
604 (search-path %load-path
605 "gnu/packages/aux-files/guile-launcher.c"))
608 (version-major+minor (package-version guile)))
611 ;; XXX: Reuse <c-compiler> from (guix scripts pack) instead?
612 (with-imported-modules '((guix build utils))
614 (use-modules (guix build utils)
617 (mkdir-p (string-append #$output "/bin"))
619 (setenv "PATH" #$(file-append gcc "/bin"))
620 (setenv "C_INCLUDE_PATH"
622 (map (cut string-append <> "/include")
623 '#$(match (bag-transitive-build-inputs
624 (package->bag guile))
625 (((labels packages . _) ...)
626 (filter package? packages))))
628 (setenv "LIBRARY_PATH" #$(file-append gcc "/lib"))
630 (invoke "gcc" #$(local-file source) "-Wall" "-g0" "-O2"
631 "-I" #$(file-append guile "/include/guile/" effective)
632 "-L" #$(file-append guile "/lib")
633 #$(string-append "-lguile-" effective)
634 "-o" (string-append #$output "/bin/guile")))))
636 (computed-file "guile-wrapper" build))
638 (define* (guix-command modules
639 #:key source (dependencies '())
640 guile (guile-version (effective-version)))
641 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
643 (define glibc-utf8-locales
644 (module-ref (resolve-interface '(gnu packages base))
645 'glibc-utf8-locales))
647 (define module-directory
648 ;; To minimize the number of 'stat' calls needed to locate a module,
649 ;; create the union of all the module directories.
650 (guile-module-union (cons modules dependencies)))
652 (program-file "guix-command"
654 ;; Remove the empty extension from the search path.
655 (set! %load-extensions '(".scm"))
658 (append (list (string-append #$module-directory
661 (string-append #$guile "/share/guile/"
662 (effective-version)))
665 (set! %load-compiled-path
666 (append (list (string-append #$module-directory
670 (string-append #$guile "/lib/guile/"
673 %load-compiled-path))
675 ;; To maximize the chances that locales are set up right
676 ;; out-of-the-box, bundle "common" UTF-8 locales.
677 (let ((locpath (getenv "GUIX_LOCPATH")))
678 (setenv "GUIX_LOCPATH"
679 (string-append (if locpath
680 (string-append locpath ":")
682 #$(file-append glibc-utf8-locales
685 (let ((guix-main (module-ref (resolve-interface '(guix ui))
689 (bindtextdomain "guix"
690 #$(locale-data source "guix"))
691 (bindtextdomain "guix-packages"
692 #$(locale-data source
697 ;; XXX: It would be more convenient to change it to:
698 ;; (exit (apply guix-main (command-line)))
699 (apply guix-main (command-line))))
701 ;; Use a 'guile' variant that doesn't complain about locales.
702 #:guile (quiet-guile guile)))
704 (define (miscellaneous-files source)
705 "Return data files taken from SOURCE."
706 (file-mapping "guix-misc"
707 `(("etc/bash_completion.d/guix"
708 ,(file-append* source "/etc/completion/bash/guix"))
709 ("etc/bash_completion.d/guix-daemon"
710 ,(file-append* source "/etc/completion/bash/guix-daemon"))
711 ("share/zsh/site-functions/_guix"
712 ,(file-append* source "/etc/completion/zsh/_guix"))
713 ("share/fish/vendor_completions.d/guix.fish"
714 ,(file-append* source "/etc/completion/fish/guix.fish"))
715 ("share/guix/berlin.guix.gnu.org.pub"
716 ,(file-append* source
717 "/etc/substitutes/berlin.guix.gnu.org.pub"))
718 ("share/guix/ci.guix.gnu.org.pub" ;alias
719 ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub"))
720 ("share/guix/ci.guix.info.pub" ;alias
721 ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub")))))
723 (define* (whole-package name modules dependencies
725 (guile-version (effective-version))
726 info daemon miscellany
728 (command (guix-command modules
729 #:dependencies dependencies
731 #:guile-version guile-version)))
732 "Return the whole Guix package NAME that uses MODULES, a derivation of all
733 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
734 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
736 (define (wrap daemon)
737 (program-file "guix-daemon"
739 ;; Refer to the right 'guix' command for 'guix
741 (setenv "GUIX" #$command)
743 ;; Honor the user's settings rather than those hardcoded
744 ;; in the 'guix-daemon' package.
745 (unless (getenv "GUIX_STATE_DIRECTORY")
746 (setenv "GUIX_STATE_DIRECTORY"
747 #$(string-append %localstatedir "/guix")))
748 (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
749 (setenv "GUIX_CONFIGURATION_DIRECTORY"
750 #$(string-append %sysconfdir "/guix")))
751 (unless (getenv "NIX_STORE_DIR")
752 (setenv "NIX_STORE_DIR" #$%storedir))
754 (apply execl #$(file-append daemon "/bin/guix-daemon")
755 "guix-daemon" (cdr (command-line))))))
758 (with-imported-modules '((guix build utils))
760 (use-modules (guix build utils))
763 #$(and daemon (wrap daemon)))
765 (mkdir-p (string-append #$output "/bin"))
767 (string-append #$output "/bin/guix"))
771 (string-append #$output "/bin/guix-daemon")))
773 (let ((share (string-append #$output "/share"))
774 (lib (string-append #$output "/lib"))
777 (symlink #$(file-append modules "/share/guile")
778 (string-append share "/guile"))
780 (symlink #$info (string-append share "/info")))
783 (symlink #$(file-append modules "/lib/guile")
784 (string-append lib "/guile")))
787 (copy-recursively #$miscellany #$output
788 #:log (%make-void-port "w")))))))
790 (define (transitive-package-dependencies package)
791 "Return the list of packages propagated by PACKAGE, including PACKAGE
793 (match (package-transitive-propagated-inputs package)
794 (((labels packages _ ...) ...)
795 (cons package packages))))
797 (define* (compiled-guix source #:key
798 (version %guix-version)
799 (channel-metadata #f)
801 (name (string-append "guix-" version))
802 (guile-version (effective-version))
803 (guile-for-build (default-guile))
804 (gzip (specification->package "gzip"))
805 (bzip2 (specification->package "bzip2"))
806 (xz (specification->package "xz"))
807 (guix (specification->package "guix")))
808 "Return a file-like object that contains a compiled Guix."
810 (specification->package "guile-avahi"))
813 (specification->package "guile-json"))
816 (specification->package "guile-ssh"))
819 (specification->package "guile-lib"))
822 (specification->package "guile-git"))
824 (define guile-sqlite3
825 (specification->package "guile-sqlite3"))
828 (specification->package "guile-zlib"))
831 (specification->package "guile-lzlib"))
834 (specification->package "guile-zstd"))
837 (specification->package "guile-gcrypt"))
840 (specification->package "guile-semver"))
843 (specification->package "gnutls"))
846 (append-map transitive-package-dependencies
847 (list guile-gcrypt gnutls guile-git guile-avahi
848 guile-json guile-semver guile-ssh guile-sqlite3
849 guile-lib guile-zlib guile-lzlib guile-zstd)))
851 (define *core-modules*
852 (scheme-node "guix-core"
859 (guix build-system gnu)
860 (guix build-system trivial)
861 (guix build profiles)
862 (guix build gnu-build-system))
864 ;; Provide a dummy (guix config) with the default version
865 ;; number, storedir, etc. This is so that "guix-core" is the
866 ;; same across all installations and doesn't need to be
867 ;; rebuilt when the version changes, which in turn means we
868 ;; can have substitutes for it.
870 `(((guix config) => ,(make-config.scm)))
872 ;; (guix man-db) is needed at build-time by (guix profiles)
873 ;; but we don't need to compile it; not compiling it allows
874 ;; us to avoid an extra dependency on guile-gdbm-ffi.
876 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
877 ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
878 ("guix/store/schema.sql"
879 ,(local-file "../guix/store/schema.sql")))
881 #:extensions (list guile-gcrypt)
882 #:guile-for-build guile-for-build))
884 (define *extra-modules*
885 (scheme-node "guix-extra"
886 (filter-map (match-lambda
887 (('guix 'scripts _ ..1) #f)
889 (('guix 'tests _ ...) #f)
891 (scheme-modules* source "guix"))
892 (list *core-modules*)
895 `(("guix/graph.js" ,(local-file "../guix/graph.js"))
896 ("guix/d3.v3.js" ,(local-file "../guix/d3.v3.js")))
898 #:extensions dependencies
899 #:guile-for-build guile-for-build))
901 (define *core-package-modules*
902 (scheme-node "guix-packages-base"
905 (list *core-modules* *extra-modules*)
906 #:extensions dependencies
908 ;; Add all the non-Scheme files here. We must do it here so
909 ;; that 'search-patches' & co. can find them. Ideally we'd
910 ;; keep them next to the .scm files that use them but it's
911 ;; difficult to do (XXX).
913 (file-imports source "gnu/packages"
915 (and (eq? 'regular (stat:type stat))
916 (not (string-suffix? ".scm" file))
917 (not (string-suffix? ".go" file))
918 (not (string-prefix? ".#" file))
919 (not (string-suffix? "~" file)))))
920 #:guile-for-build guile-for-build))
922 (define *package-modules*
923 (scheme-node "guix-packages"
924 (scheme-modules* source "gnu/packages")
925 (list *core-modules* *extra-modules* *core-package-modules*)
926 #:extensions dependencies
927 #:guile-for-build guile-for-build))
929 (define *system-modules*
930 (scheme-node "guix-system"
933 ,@(scheme-modules* source "gnu/bootloader")
934 ,@(scheme-modules* source "gnu/system")
935 ,@(scheme-modules* source "gnu/services")
936 ,@(scheme-modules* source "gnu/machine"))
937 (list *core-package-modules* *package-modules*
938 *extra-modules* *core-modules*)
939 #:extensions dependencies
941 (append (file-imports source "gnu/system/examples"
944 ;; All the installer code is on the build-side.
945 (file-imports source "gnu/installer/"
947 ;; Build-side code that we don't build. Some of
948 ;; these depend on guile-rsvg, the Shepherd, etc.
949 (file-imports source "gnu/build" (const #t)))
953 (define *cli-modules*
954 (scheme-node "guix-cli"
955 (append (scheme-modules* source "/guix/scripts")
957 (list *core-modules* *extra-modules*
958 *core-package-modules* *package-modules*
960 #:extensions dependencies
961 #:guile-for-build guile-for-build))
963 (define *system-test-modules*
964 ;; Ship these modules mostly so (gnu ci) can discover them.
965 (scheme-node "guix-system-tests"
967 ,@(scheme-modules* source "gnu/tests"))
968 (list *core-package-modules* *package-modules*
969 *extra-modules* *system-modules* *core-modules*
970 *cli-modules*) ;for (guix scripts pack), etc.
971 #:extensions dependencies
972 #:guile-for-build guile-for-build))
975 (scheme-node "guix-config"
979 => ,(make-config.scm #:gzip gzip
989 %guix-bug-report-address
991 %guix-home-page-url)))
992 #:guile-for-build guile-for-build))
994 (define (built-modules node-subset)
995 (directory-union (string-append name "-modules")
996 (append-map node-subset
998 ;; Note: *CONFIG* comes first so that it
999 ;; overrides the (guix config) module that
1000 ;; comes with *CORE-MODULES*.
1003 *system-test-modules*
1006 *core-package-modules*
1010 ;; Silently choose the first entry upon collision so that
1011 ;; we choose *CONFIG*.
1012 #:resolve-collision 'first
1014 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
1015 ;; be a regular file, not a symlink. Thus, arrange so that
1016 ;; regular files appear as regular files in the final
1021 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
1022 ;; Version 1 is when we return the full package.
1023 (cond ((= 1 pull-version)
1024 ;; The whole package, with a standard file hierarchy.
1025 (let* ((modules (built-modules (compose list node-source+compiled)))
1026 (command (guix-command modules
1028 #:dependencies dependencies
1029 #:guile guile-for-build
1030 #:guile-version guile-version)))
1031 (whole-package name modules dependencies
1033 #:guile guile-for-build
1035 ;; Include 'guix-daemon'. XXX: Here we inject an
1036 ;; older snapshot of guix-daemon, but that's a good
1037 ;; enough approximation for now.
1038 #:daemon (module-ref (resolve-interface
1040 package-management))
1043 #:info (info-manual source)
1044 #:miscellany (miscellaneous-files source)
1045 #:guile-version guile-version)))
1047 ;; Legacy 'guix pull': return the .scm and .go files as one
1049 (built-modules (lambda (node)
1050 (list (node-source node)
1051 (node-compiled node)))))
1053 ;; Unsupported 'guix pull' version.
1058 ;;; Generating (guix config).
1061 (define %persona-variables
1062 ;; (guix config) variables that define Guix's persona.
1063 '(%guix-package-name
1065 %guix-bug-report-address
1066 %guix-home-page-url))
1068 (define %config-variables
1069 ;; (guix config) variables corresponding to Guix configuration.
1070 (letrec-syntax ((variables (syntax-rules ()
1073 ((_ variable rest ...)
1074 (cons `(variable . ,variable)
1075 (variables rest ...))))))
1076 (variables %localstatedir %storedir %sysconfdir)))
1078 (define* (make-config.scm #:key gzip xz bzip2
1079 (package-name "GNU Guix")
1080 (package-version "0")
1081 (channel-metadata #f)
1082 (bug-report-address "bug-guix@gnu.org")
1083 (home-page-url "https://guix.gnu.org"))
1085 ;; Hack so that Geiser is not confused.
1086 (define defmod 'define-module)
1088 (scheme-file "config.scm"
1089 #~(;; The following expressions get spliced.
1090 (#$defmod (guix config)
1091 #:export (%guix-package-name
1093 %guix-bug-report-address
1099 %store-database-directory
1106 #$(%current-system))
1108 #$@(map (match-lambda
1110 #~(define-public #$name #$value)))
1113 (define %store-directory
1114 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
1117 (define %state-directory
1118 ;; This must match `NIX_STATE_DIR' as defined in
1120 (or (getenv "GUIX_STATE_DIRECTORY")
1121 (string-append %localstatedir "/guix")))
1123 (define %store-database-directory
1124 (or (getenv "GUIX_DATABASE_DIRECTORY")
1125 (string-append %state-directory "/db")))
1127 (define %config-directory
1128 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
1129 ;; defined in `nix/local.mk'.
1130 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
1131 (string-append %sysconfdir "/guix")))
1133 (define %guix-package-name #$package-name)
1134 (define %guix-version #$package-version)
1135 (define %guix-bug-report-address #$bug-report-address)
1136 (define %guix-home-page-url #$home-page-url)
1138 (define %channel-metadata
1139 ;; Metadata for the 'guix' channel in use. This
1140 ;; information is used by (guix describe).
1141 '#$channel-metadata)
1144 #+(and gzip (file-append gzip "/bin/gzip")))
1146 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
1148 #+(and xz (file-append xz "/bin/xz"))))
1150 ;; Guile 2.0 *requires* the 'define-module' to be at the
1151 ;; top-level or the 'toplevel-ref' in the resulting .go file are
1152 ;; made relative to a nonexistent anonymous module.
1160 (define* (compiled-modules name module-tree module-files
1163 (dependencies-compiled '())
1165 (extensions '()) ;full-blown Guile packages
1168 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
1169 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
1170 containing MODULE-FILES and possibly other files as well."
1171 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1174 (with-imported-modules (source-module-closure
1175 '((guix build compile)
1176 (guix build utils)))
1178 (use-modules (srfi srfi-26)
1182 (guix build compile)
1185 (define (regular? file)
1186 (not (member file '("." ".."))))
1188 (define (report-load file total completed)
1191 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1193 ;; Note: Multiply TOTAL by two to account for the
1194 ;; compilation phase that follows.
1195 completed (* total 2)
1197 (* 100. (/ completed total)) total)
1200 (define (report-compilation file total completed)
1202 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1204 ;; Add TOTAL to account for the load phase that came
1206 (+ total completed) (* total 2)
1208 (* 100. (/ completed total)) total)
1211 (define (process-directory directory files output)
1212 ;; Hide compilation warnings.
1213 (parameterize ((current-warning-port (%make-void-port "w")))
1214 (compile-files directory #$output files
1215 #:workers (parallel-job-count)
1216 #:report-load report-load
1217 #:report-compilation report-compilation)))
1219 (setvbuf (current-output-port) 'line)
1220 (setvbuf (current-error-port) 'line)
1222 (set! %load-path (cons #+module-tree %load-path))
1224 (append '#+dependencies
1225 (map (lambda (extension)
1226 (string-append extension "/share/guile/site/"
1227 (effective-version)))
1231 (set! %load-compiled-path
1232 (append '#+dependencies-compiled
1233 (map (lambda (extension)
1234 (string-append extension "/lib/guile/"
1238 %load-compiled-path))
1240 ;; Load the compiler modules upfront.
1244 (chdir #+module-tree)
1245 (process-directory "." '#+module-files #$output)
1248 (computed-file name build
1249 #:guile guile-for-build
1251 `(#:local-build? #f ;allow substitutes
1253 ;; Don't annoy people about _IONBF deprecation.
1254 ;; Initialize 'terminal-width' in (system repl debug)
1255 ;; to a large-enough value to make backtrace more
1257 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1258 ("COLUMNS" . "200")))))
1265 (define* (guix-derivation source version
1266 #:optional (guile-version (effective-version))
1267 #:key (pull-version 0)
1269 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1270 for GUILE-VERSION. Use VERSION as the version string. Use CHANNEL-METADATA
1271 as the channel metadata sexp to include in (guix config).
1273 PULL-VERSION specifies the version of the 'guix pull' protocol. Return #f if
1274 this PULL-VERSION value is not supported."
1275 (define (shorten version)
1276 (if (and (string-every char-set:hex-digit version)
1277 (> (string-length version) 9))
1278 (string-take version 9) ;Git commit
1282 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use the
1283 ;; current Guile unconditionally.
1284 (specification->package "guile"))
1286 (when (and (< pull-version 1)
1287 (not (string=? (package-version guile) guile-version)))
1288 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1289 ;; can be any version. When that happens and Guile is not current (e.g.,
1290 ;; it's Guile 2.0), just bail out.
1293 (message "Guix is too old and cannot be upgraded")))))
1295 (mbegin %store-monad
1296 (set-guile-for-build guile)
1297 (let ((guix (compiled-guix source
1299 #:channel-metadata channel-metadata
1300 #:name (string-append "guix-"
1302 #:pull-version pull-version
1303 #:guile-version (if (>= pull-version 1)
1304 "3.0" guile-version)
1305 #:guile-for-build guile)))