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$")))
404 (copy-recursively #$documentation "."
405 #:log (%make-void-port "w"))
409 (copy-file file (basename file)))
410 (find-files #$documentation-po ".*.po$"))
412 (setenv "GUIX_LOCPATH"
413 #+(file-append glibc-utf8-locales "/lib/locale"))
414 (setenv "PATH" #+(file-append gettext "/bin"))
415 (setenv "LC_ALL" "en_US.UTF-8")
416 (setlocale LC_ALL "en_US.UTF-8")
418 (n-par-for-each (parallel-job-count)
421 (translate-texi "guix" po language
422 #:extras '("contributing"))))
423 (available-translations "." "guix-manual"))
425 (n-par-for-each (parallel-job-count)
428 (translate-texi "guix-cookbook" po language)))
429 (available-translations "." "guix-cookbook"))
431 (for-each (lambda (file)
432 (install-file file #$output))
434 (find-files "." "contributing\\..*\\.texi$")
435 (find-files "." "guix\\..*\\.texi$")
436 (find-files "." "guix-cookbook\\..*\\.texi$"))))))
438 (computed-file "guix-translated-texinfo" build))
440 (define (info-manual source)
441 "Return the Info manual built from SOURCE."
443 (module-ref (resolve-interface '(gnu packages texinfo))
447 (module-ref (resolve-interface '(gnu packages graphviz))
450 (define glibc-utf8-locales
451 (module-ref (resolve-interface '(gnu packages base))
452 'glibc-utf8-locales))
454 (define documentation
455 (file-append* source "doc"))
458 (file-append* source "gnu/system/examples"))
461 (with-imported-modules '((guix build utils))
463 (use-modules (guix build utils)
468 ;; Create 'version.texi'.
469 ;; XXX: Can we use a more meaningful version string yet one that
470 ;; doesn't change at each commit?
471 (call-with-output-file "version.texi"
473 (let ((version "0.0-git"))
475 @set UPDATED 1 January 1970
476 @set UPDATED-MONTH January 1970
478 @set VERSION ~a\n" version version))))
480 ;; Copy configuration templates that the manual includes.
481 (for-each (lambda (template)
485 (basename template ".tmpl")
487 (find-files #$examples "\\.tmpl$"))
490 (mkdir-p (string-append #$output "/images"))
491 (for-each (lambda (dot-file)
492 (invoke #+(file-append graphviz "/bin/dot")
493 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
494 "-Granksep=.00005" "-Nfontsize=9"
495 "-Nheight=.1" "-Nwidth=.1"
496 "-o" (string-append #$output "/images/"
497 (basename dot-file ".dot")
500 (find-files (string-append #$documentation "/images")
504 (for-each (lambda (png-file)
505 (install-file png-file
506 (string-append #$output "/images")))
507 (find-files (string-append #$documentation "/images")
510 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
511 ;; add a symlink to the 'images' directory so that 'makeinfo' can
512 ;; see those images and produce image references in the Info output.
513 (copy-recursively #$documentation "."
514 #:log (%make-void-port "w"))
515 (copy-recursively #+(translate-texi-manuals source) "."
516 #:log (%make-void-port "w"))
517 (delete-file-recursively "images")
518 (symlink (string-append #$output "/images") "images")
520 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
521 (setenv "GUIX_LOCPATH"
522 #+(file-append glibc-utf8-locales "/lib/locale"))
524 (for-each (lambda (texi)
525 (match (string-split (basename texi) #\.)
526 (("guix" language "texi")
527 ;; Create 'version-LL.texi'.
528 (symlink "version.texi"
529 (string-append "version-" language
533 (invoke #+(file-append texinfo "/bin/makeinfo")
534 texi "-I" #$documentation
536 "-o" (string-append #$output "/"
537 (basename texi ".texi")
540 (append (find-files "."
541 "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")
543 "^guix-cookbook.*\\.texi$"))))
545 ;; Compress Info files.
547 #+(file-append (specification->package "gzip") "/bin"))
548 (for-each (lambda (file)
549 (invoke "gzip" "-9n" file))
550 (find-files #$output "\\.info(-[0-9]+)?$")))))
552 (computed-file "guix-manual" build))
554 (define-syntax-rule (prevent-inlining! identifier ...)
555 (begin (set! identifier identifier) ...))
557 ;; XXX: These procedures are actually used by 'doc/build.scm'. Protect them
558 ;; from inlining on Guile 3.
559 (prevent-inlining! file-append* translate-texi-manuals info-manual)
561 (define* (guile-module-union things #:key (name "guix-module-union"))
562 "Return the union of the subset of THINGS (packages, computed files, etc.)
563 that provide Guile modules."
565 (with-imported-modules '((guix build union))
567 (use-modules (guix build union))
569 (define (modules directory)
570 (string-append directory "/share/guile/site"))
572 (define (objects directory)
573 (string-append directory "/lib/guile"))
575 (union-build #$output
576 (filter (lambda (directory)
577 (or (file-exists? (modules directory))
578 (file-exists? (objects directory))))
581 #:log-port (%make-void-port "w")))))
583 (computed-file name build))
585 (define (quiet-guile guile)
586 "Return a wrapper that does the same as the 'guile' executable of GUILE,
587 except that it does not complain about locales and falls back to 'en_US.utf8'
590 (specification->package "gcc-toolchain"))
593 (search-path %load-path
594 "gnu/packages/aux-files/guile-launcher.c"))
597 (version-major+minor (package-version guile)))
600 ;; XXX: Reuse <c-compiler> from (guix scripts pack) instead?
601 (with-imported-modules '((guix build utils))
603 (use-modules (guix build utils)
606 (mkdir-p (string-append #$output "/bin"))
608 (setenv "PATH" #$(file-append gcc "/bin"))
609 (setenv "C_INCLUDE_PATH"
611 (map (cut string-append <> "/include")
612 '#$(match (bag-transitive-build-inputs
613 (package->bag guile))
614 (((labels packages . _) ...)
615 (filter package? packages))))
617 (setenv "LIBRARY_PATH" #$(file-append gcc "/lib"))
619 (invoke "gcc" #$(local-file source) "-Wall" "-g0" "-O2"
620 "-I" #$(file-append guile "/include/guile/" effective)
621 "-L" #$(file-append guile "/lib")
622 #$(string-append "-lguile-" effective)
623 "-o" (string-append #$output "/bin/guile")))))
625 (computed-file "guile-wrapper" build))
627 (define* (guix-command modules
628 #:key source (dependencies '())
629 guile (guile-version (effective-version)))
630 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
632 (define glibc-utf8-locales
633 (module-ref (resolve-interface '(gnu packages base))
634 'glibc-utf8-locales))
636 (define module-directory
637 ;; To minimize the number of 'stat' calls needed to locate a module,
638 ;; create the union of all the module directories.
639 (guile-module-union (cons modules dependencies)))
641 (program-file "guix-command"
644 (cons (string-append #$module-directory
649 (set! %load-compiled-path
650 (cons (string-append #$module-directory
654 %load-compiled-path))
656 ;; To maximize the chances that locales are set up right
657 ;; out-of-the-box, bundle "common" UTF-8 locales.
658 (let ((locpath (getenv "GUIX_LOCPATH")))
659 (setenv "GUIX_LOCPATH"
660 (string-append (if locpath
661 (string-append locpath ":")
663 #$(file-append glibc-utf8-locales
666 (let ((guix-main (module-ref (resolve-interface '(guix ui))
670 (bindtextdomain "guix"
671 #$(locale-data source "guix"))
672 (bindtextdomain "guix-packages"
673 #$(locale-data source
678 ;; XXX: It would be more convenient to change it to:
679 ;; (exit (apply guix-main (command-line)))
680 (apply guix-main (command-line))))
682 ;; Use a 'guile' variant that doesn't complain about locales.
683 #:guile (quiet-guile guile)))
685 (define (miscellaneous-files source)
686 "Return data files taken from SOURCE."
687 (file-mapping "guix-misc"
688 `(("etc/bash_completion.d/guix"
689 ,(file-append* source "/etc/completion/bash/guix"))
690 ("etc/bash_completion.d/guix-daemon"
691 ,(file-append* source "/etc/completion/bash/guix-daemon"))
692 ("share/zsh/site-functions/_guix"
693 ,(file-append* source "/etc/completion/zsh/_guix"))
694 ("share/fish/vendor_completions.d/guix.fish"
695 ,(file-append* source "/etc/completion/fish/guix.fish"))
696 ("share/guix/berlin.guix.gnu.org.pub"
697 ,(file-append* source
698 "/etc/substitutes/berlin.guix.gnu.org.pub"))
699 ("share/guix/ci.guix.gnu.org.pub" ;alias
700 ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub"))
701 ("share/guix/ci.guix.info.pub" ;alias
702 ,(file-append* source "/etc/substitutes/berlin.guix.gnu.org.pub")))))
704 (define* (whole-package name modules dependencies
706 (guile-version (effective-version))
707 info daemon miscellany
709 (command (guix-command modules
710 #:dependencies dependencies
712 #:guile-version guile-version)))
713 "Return the whole Guix package NAME that uses MODULES, a derivation of all
714 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
715 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
717 (define (wrap daemon)
718 (program-file "guix-daemon"
720 ;; Refer to the right 'guix' command for 'guix
722 (setenv "GUIX" #$command)
724 ;; Honor the user's settings rather than those hardcoded
725 ;; in the 'guix-daemon' package.
726 (unless (getenv "GUIX_STATE_DIRECTORY")
727 (setenv "GUIX_STATE_DIRECTORY"
728 #$(string-append %localstatedir "/guix")))
729 (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
730 (setenv "GUIX_CONFIGURATION_DIRECTORY"
731 #$(string-append %sysconfdir "/guix")))
732 (unless (getenv "NIX_STORE_DIR")
733 (setenv "NIX_STORE_DIR" #$%storedir))
735 (apply execl #$(file-append daemon "/bin/guix-daemon")
736 "guix-daemon" (cdr (command-line))))))
739 (with-imported-modules '((guix build utils))
741 (use-modules (guix build utils))
744 #$(and daemon (wrap daemon)))
746 (mkdir-p (string-append #$output "/bin"))
748 (string-append #$output "/bin/guix"))
752 (string-append #$output "/bin/guix-daemon")))
754 (let ((share (string-append #$output "/share"))
755 (lib (string-append #$output "/lib"))
758 (symlink #$(file-append modules "/share/guile")
759 (string-append share "/guile"))
761 (symlink #$info (string-append share "/info")))
764 (symlink #$(file-append modules "/lib/guile")
765 (string-append lib "/guile")))
768 (copy-recursively #$miscellany #$output
769 #:log (%make-void-port "w")))))))
771 (define* (compiled-guix source #:key (version %guix-version)
773 (name (string-append "guix-" version))
774 (guile-version (effective-version))
775 (guile-for-build (default-guile))
776 (gzip (specification->package "gzip"))
777 (bzip2 (specification->package "bzip2"))
778 (xz (specification->package "xz"))
779 (guix (specification->package "guix")))
780 "Return a file-like object that contains a compiled Guix."
782 (specification->package "guile-json"))
785 (specification->package "guile-ssh"))
788 (specification->package "guile-git"))
790 (define guile-sqlite3
791 (specification->package "guile-sqlite3"))
794 (specification->package "guile-zlib"))
797 (specification->package "guile-lzlib"))
800 (specification->package "guile-gcrypt"))
803 (specification->package "gnutls"))
806 (match (append-map (lambda (package)
807 (cons (list "x" package)
808 (package-transitive-propagated-inputs package)))
809 (list guile-gcrypt gnutls guile-git guile-json
810 guile-ssh guile-sqlite3 guile-zlib guile-lzlib))
811 (((labels packages _ ...) ...)
814 (define *core-modules*
815 (scheme-node "guix-core"
822 (guix build-system gnu)
823 (guix build-system trivial)
824 (guix build profiles)
825 (guix build gnu-build-system))
827 ;; Provide a dummy (guix config) with the default version
828 ;; number, storedir, etc. This is so that "guix-core" is the
829 ;; same across all installations and doesn't need to be
830 ;; rebuilt when the version changes, which in turn means we
831 ;; can have substitutes for it.
833 `(((guix config) => ,(make-config.scm)))
835 ;; (guix man-db) is needed at build-time by (guix profiles)
836 ;; but we don't need to compile it; not compiling it allows
837 ;; us to avoid an extra dependency on guile-gdbm-ffi.
839 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
840 ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
841 ("guix/store/schema.sql"
842 ,(local-file "../guix/store/schema.sql")))
844 #:extensions (list guile-gcrypt)
845 #:guile-for-build guile-for-build))
847 (define *extra-modules*
848 (scheme-node "guix-extra"
849 (filter-map (match-lambda
850 (('guix 'scripts _ ..1) #f)
852 (('guix 'tests _ ...) #f)
854 (scheme-modules* source "guix"))
855 (list *core-modules*)
856 #:extensions dependencies
857 #:guile-for-build guile-for-build))
859 (define *core-package-modules*
860 (scheme-node "guix-packages-base"
863 (list *core-modules* *extra-modules*)
864 #:extensions dependencies
866 ;; Add all the non-Scheme files here. We must do it here so
867 ;; that 'search-patches' & co. can find them. Ideally we'd
868 ;; keep them next to the .scm files that use them but it's
869 ;; difficult to do (XXX).
871 (file-imports source "gnu/packages"
873 (and (eq? 'regular (stat:type stat))
874 (not (string-suffix? ".scm" file))
875 (not (string-suffix? ".go" file))
876 (not (string-prefix? ".#" file))
877 (not (string-suffix? "~" file)))))
878 #:guile-for-build guile-for-build))
880 (define *package-modules*
881 (scheme-node "guix-packages"
882 (scheme-modules* source "gnu/packages")
883 (list *core-modules* *extra-modules* *core-package-modules*)
884 #:extensions dependencies
885 #:guile-for-build guile-for-build))
887 (define *system-modules*
888 (scheme-node "guix-system"
891 ,@(scheme-modules* source "gnu/bootloader")
892 ,@(scheme-modules* source "gnu/system")
893 ,@(scheme-modules* source "gnu/services")
894 ,@(scheme-modules* source "gnu/machine"))
895 (list *core-package-modules* *package-modules*
896 *extra-modules* *core-modules*)
897 #:extensions dependencies
899 (append (file-imports source "gnu/system/examples"
902 ;; All the installer code is on the build-side.
903 (file-imports source "gnu/installer/"
905 ;; Build-side code that we don't build. Some of
906 ;; these depend on guile-rsvg, the Shepherd, etc.
907 (file-imports source "gnu/build" (const #t)))
911 (define *cli-modules*
912 (scheme-node "guix-cli"
913 (append (scheme-modules* source "/guix/scripts")
915 (list *core-modules* *extra-modules*
916 *core-package-modules* *package-modules*
918 #:extensions dependencies
919 #:guile-for-build guile-for-build))
921 (define *system-test-modules*
922 ;; Ship these modules mostly so (gnu ci) can discover them.
923 (scheme-node "guix-system-tests"
925 ,@(scheme-modules* source "gnu/tests"))
926 (list *core-package-modules* *package-modules*
927 *extra-modules* *system-modules* *core-modules*
928 *cli-modules*) ;for (guix scripts pack), etc.
929 #:extensions dependencies
930 #:guile-for-build guile-for-build))
933 (scheme-node "guix-config"
937 => ,(make-config.scm #:gzip gzip
945 %guix-bug-report-address
947 %guix-home-page-url)))
948 #:guile-for-build guile-for-build))
950 (define (built-modules node-subset)
951 (directory-union (string-append name "-modules")
952 (append-map node-subset
954 ;; Note: *CONFIG* comes first so that it
955 ;; overrides the (guix config) module that
956 ;; comes with *CORE-MODULES*.
959 *system-test-modules*
962 *core-package-modules*
966 ;; Silently choose the first entry upon collision so that
967 ;; we choose *CONFIG*.
968 #:resolve-collision 'first
970 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
971 ;; be a regular file, not a symlink. Thus, arrange so that
972 ;; regular files appear as regular files in the final
977 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
978 ;; Version 1 is when we return the full package.
979 (cond ((= 1 pull-version)
980 ;; The whole package, with a standard file hierarchy.
981 (let* ((modules (built-modules (compose list node-source+compiled)))
982 (command (guix-command modules
984 #:dependencies dependencies
985 #:guile guile-for-build
986 #:guile-version guile-version)))
987 (whole-package name modules dependencies
989 #:guile guile-for-build
991 ;; Include 'guix-daemon'. XXX: Here we inject an
992 ;; older snapshot of guix-daemon, but that's a good
993 ;; enough approximation for now.
994 #:daemon (module-ref (resolve-interface
999 #:info (info-manual source)
1000 #:miscellany (miscellaneous-files source)
1001 #:guile-version guile-version)))
1003 ;; Legacy 'guix pull': return the .scm and .go files as one
1005 (built-modules (lambda (node)
1006 (list (node-source node)
1007 (node-compiled node)))))
1009 ;; Unsupported 'guix pull' version.
1014 ;;; Generating (guix config).
1017 (define %persona-variables
1018 ;; (guix config) variables that define Guix's persona.
1019 '(%guix-package-name
1021 %guix-bug-report-address
1022 %guix-home-page-url))
1024 (define %config-variables
1025 ;; (guix config) variables corresponding to Guix configuration.
1026 (letrec-syntax ((variables (syntax-rules ()
1029 ((_ variable rest ...)
1030 (cons `(variable . ,variable)
1031 (variables rest ...))))))
1032 (variables %localstatedir %storedir %sysconfdir)))
1034 (define* (make-config.scm #:key gzip xz bzip2
1035 (package-name "GNU Guix")
1036 (package-version "0")
1037 (bug-report-address "bug-guix@gnu.org")
1038 (home-page-url "https://guix.gnu.org"))
1040 ;; Hack so that Geiser is not confused.
1041 (define defmod 'define-module)
1043 (scheme-file "config.scm"
1044 #~(;; The following expressions get spliced.
1045 (#$defmod (guix config)
1046 #:export (%guix-package-name
1048 %guix-bug-report-address
1053 %store-database-directory
1060 #$(%current-system))
1062 #$@(map (match-lambda
1064 #~(define-public #$name #$value)))
1067 (define %store-directory
1068 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
1071 (define %state-directory
1072 ;; This must match `NIX_STATE_DIR' as defined in
1074 (or (getenv "GUIX_STATE_DIRECTORY")
1075 (string-append %localstatedir "/guix")))
1077 (define %store-database-directory
1078 (or (getenv "GUIX_DATABASE_DIRECTORY")
1079 (string-append %state-directory "/db")))
1081 (define %config-directory
1082 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
1083 ;; defined in `nix/local.mk'.
1084 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
1085 (string-append %sysconfdir "/guix")))
1087 (define %guix-package-name #$package-name)
1088 (define %guix-version #$package-version)
1089 (define %guix-bug-report-address #$bug-report-address)
1090 (define %guix-home-page-url #$home-page-url)
1093 #+(and gzip (file-append gzip "/bin/gzip")))
1095 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
1097 #+(and xz (file-append xz "/bin/xz"))))
1099 ;; Guile 2.0 *requires* the 'define-module' to be at the
1100 ;; top-level or the 'toplevel-ref' in the resulting .go file are
1101 ;; made relative to a nonexistent anonymous module.
1109 (define* (compiled-modules name module-tree module-files
1112 (dependencies-compiled '())
1114 (extensions '()) ;full-blown Guile packages
1117 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
1118 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
1119 containing MODULE-FILES and possibly other files as well."
1120 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1123 (with-imported-modules (source-module-closure
1124 '((guix build compile)
1125 (guix build utils)))
1127 (use-modules (srfi srfi-26)
1131 (guix build compile)
1134 (define (regular? file)
1135 (not (member file '("." ".."))))
1137 (define (report-load file total completed)
1140 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1142 ;; Note: Multiply TOTAL by two to account for the
1143 ;; compilation phase that follows.
1144 completed (* total 2)
1146 (* 100. (/ completed total)) total)
1149 (define (report-compilation file total completed)
1151 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1153 ;; Add TOTAL to account for the load phase that came
1155 (+ total completed) (* total 2)
1157 (* 100. (/ completed total)) total)
1160 (define (process-directory directory files output)
1161 ;; Hide compilation warnings.
1162 (parameterize ((current-warning-port (%make-void-port "w")))
1163 (compile-files directory #$output files
1164 #:workers (parallel-job-count)
1165 #:report-load report-load
1166 #:report-compilation report-compilation)))
1168 (setvbuf (current-output-port) 'line)
1169 (setvbuf (current-error-port) 'line)
1171 (set! %load-path (cons #+module-tree %load-path))
1173 (append '#+dependencies
1174 (map (lambda (extension)
1175 (string-append extension "/share/guile/site/"
1176 (effective-version)))
1180 (set! %load-compiled-path
1181 (append '#+dependencies-compiled
1182 (map (lambda (extension)
1183 (string-append extension "/lib/guile/"
1187 %load-compiled-path))
1189 ;; Load the compiler modules upfront.
1193 (chdir #+module-tree)
1194 (process-directory "." '#+module-files #$output)
1197 (computed-file name build
1198 #:guile guile-for-build
1200 `(#:local-build? #f ;allow substitutes
1202 ;; Don't annoy people about _IONBF deprecation.
1203 ;; Initialize 'terminal-width' in (system repl debug)
1204 ;; to a large-enough value to make backtrace more
1206 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1207 ("COLUMNS" . "200")))))
1214 (define* (guix-derivation source version
1215 #:optional (guile-version (effective-version))
1216 #:key (pull-version 0))
1217 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1218 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
1219 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
1221 (define (shorten version)
1222 (if (and (string-every char-set:hex-digit version)
1223 (> (string-length version) 9))
1224 (string-take version 9) ;Git commit
1228 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use the
1229 ;; current Guile unconditionally.
1230 (specification->package "guile"))
1232 (when (and (< pull-version 1)
1233 (not (string=? (package-version guile) guile-version)))
1234 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1235 ;; can be any version. When that happens and Guile is not current (e.g.,
1236 ;; it's Guile 2.0), just bail out.
1239 (message "Guix is too old and cannot be upgraded")))))
1241 (mbegin %store-monad
1242 (set-guile-for-build guile)
1243 (let ((guix (compiled-guix source
1245 #:name (string-append "guix-"
1247 #:pull-version pull-version
1248 #:guile-version (if (>= pull-version 1)
1249 "3.0" guile-version)
1250 #:guile-for-build guile)))