1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix self)
20 #:use-module (guix config)
21 #:use-module (guix i18n)
22 #:use-module (guix modules)
23 #:use-module (guix gexp)
24 #:use-module (guix store)
25 #:use-module (guix monads)
26 #:use-module (guix discovery)
27 #:use-module (guix packages)
28 #:use-module (guix sets)
29 #:use-module (guix modules)
30 #:use-module ((guix build utils) #:select (find-files))
31 #:use-module ((guix build compile) #:select (%lightweight-optimizations))
32 #:use-module (srfi srfi-1)
33 #:use-module (srfi srfi-9)
34 #:use-module (srfi srfi-35)
35 #:use-module (ice-9 match)
36 #:export (make-config.scm
37 whole-package ;for internal use in 'guix pull'
43 ;;; Dependency handling.
46 (define specification->package
47 ;; Use our own variant of that procedure because that of (gnu packages)
48 ;; would traverse all the .scm files, which is wasteful.
49 (let ((ref (lambda (module variable)
50 (module-ref (resolve-interface module) variable))))
52 ("guile" (ref '(gnu packages commencement) 'guile-final))
53 ("guile-json" (ref '(gnu packages guile) 'guile-json-3))
54 ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh))
55 ("guile-git" (ref '(gnu packages guile) 'guile-git))
56 ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3))
57 ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt))
58 ("gnutls" (ref '(gnu packages tls) 'gnutls))
59 ("zlib" (ref '(gnu packages compression) 'zlib))
60 ("lzlib" (ref '(gnu packages compression) 'lzlib))
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 (_ #f)))) ;no such package
73 ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's
74 ;; easier to express things this way.
75 (define-record-type <node>
76 (node name modules source dependencies compiled)
78 (name node-name) ;string
79 (modules node-modules) ;list of module names
80 (source node-source) ;list of source files
81 (dependencies node-dependencies) ;list of nodes
82 (compiled node-compiled)) ;node -> lowerable object
84 ;; File mappings are essentially an alist as passed to 'imported-files'.
85 (define-record-type <file-mapping>
86 (file-mapping name alist)
88 (name file-mapping-name)
89 (alist file-mapping-alist))
91 (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>)
93 ;; Here we use 'imported-files', which can arrange to directly import all
94 ;; the files instead of creating a derivation, when possible.
95 (imported-files (map (match-lambda
96 ((destination (? local-file? file))
98 (local-file-absolute-file-name file)))
100 (cons destination source))) ;silliness
101 (file-mapping-alist mapping))
102 #:name (file-mapping-name mapping)
105 (define (node-source+compiled node)
106 "Return a \"bundle\" containing both the source code and object files for
107 NODE's modules, under their FHS directories: share/guile/site and lib/guile."
109 (with-imported-modules '((guix build utils))
111 (use-modules (guix build utils))
114 (string-append #$output "/share/guile/site/"
115 (effective-version)))
118 (string-append #$output "/lib/guile/" (effective-version)
121 (mkdir-p (dirname source))
122 (symlink #$(node-source node) source)
123 (mkdir-p (dirname object))
124 (symlink #$(node-compiled node) object))))
126 (computed-file (string-append (node-name node) "-modules")
128 #:options '(#:local-build? #t
130 ;; "Building" it locally is faster.
131 #:substitutable? #f)))
133 (define (node-fold proc init nodes)
134 (let loop ((nodes nodes)
140 (if (set-contains? visited head)
141 (loop tail visited result)
142 (loop tail (set-insert head visited)
143 (proc head result)))))))
145 (define (node-modules/recursive nodes)
146 (node-fold (lambda (node modules)
147 (append (node-modules node) modules))
151 (define* (closure modules #:optional (except '()))
152 (source-module-closure modules
158 (or ('guix _ ...) ('gnu _ ...)))
159 (not (member module except)))
162 (define module->import
163 ;; Return a file-name/file-like object pair for the specified module and
164 ;; suitable for 'imported-files'.
167 (let ((file (module-name->file-name module)))
170 (let ((file (module-name->file-name module)))
172 (local-file (search-path %load-path file)))))))
174 (define* (scheme-node name modules #:optional (dependencies '())
175 #:key (extra-modules '()) (extra-files '())
177 parallel? guile-for-build)
178 "Return a node that builds the given Scheme MODULES, and depends on
179 DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules
180 added to the source, and EXTRA-FILES is a list of additional files.
181 EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that
182 must be present in the search path."
183 (let* ((modules (append extra-modules
185 (node-modules/recursive dependencies))))
186 (module-files (map module->import modules))
187 (source (file-mapping (string-append name "-source")
188 (append module-files extra-files))))
189 (node name modules source dependencies
190 (compiled-modules name source
191 (map car module-files)
192 (map node-source dependencies)
193 (map node-compiled dependencies)
194 #:extensions extensions
195 #:parallel? parallel?
196 #:guile-for-build guile-for-build))))
198 (define (file-imports directory sub-directory pred)
199 "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a
200 list of file-name/file-like objects suitable as inputs to 'imported-files'."
202 (list (string-drop file (+ 1 (string-length directory)))
203 (local-file file #:recursive? #t)))
204 (find-files (string-append directory "/" sub-directory) pred)))
206 (define* (file-append* item file #:key (recursive? #t))
207 "Return FILE within ITEM, which may be a file name or a file-like object.
208 When ITEM is a plain file name (a string), simply return a 'local-file'
209 record with the new file name."
212 ;; This is the optimal case: we return a new "source". Thus, a
213 ;; derivation that depends on this sub-directory does not depend on ITEM
215 (local-file (string-append item "/" file)
216 #:recursive? recursive?))
217 ;; TODO: Add 'local-file?' case.
219 ;; In this case, anything that refers to the result also depends on ITEM,
220 ;; which isn't great.
221 (file-append item "/" file))))
223 (define* (locale-data source domain
224 #:optional (directory domain))
225 "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to
226 DOMAIN, a gettext domain."
228 (module-ref (resolve-interface '(gnu packages gettext))
232 (with-imported-modules '((guix build utils))
234 (use-modules (guix build utils)
236 (ice-9 match) (ice-9 ftw))
239 #+(file-append* source (string-append "po/" directory)))
241 (define (compile language)
242 (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/"
244 (mkdir-p (dirname gmo))
245 (invoke #+(file-append gettext "/bin/msgfmt")
246 "-c" "--statistics" "--verbose"
248 (string-append po-directory "/" language ".po"))))
251 ;; Return the list of languages. Note: don't read 'LINGUAS'
252 ;; because it contains things like 'en@boldquot' that do not have
253 ;; a corresponding .po file.
254 (map (cut basename <> ".po")
255 (scandir po-directory
256 (cut string-suffix? ".po" <>))))
258 (for-each compile (linguas)))))
260 (computed-file (string-append "guix-locale-" domain)
263 (define (translate-texi-manuals source)
264 "Return the translated texinfo manuals built from SOURCE."
266 (specification->package "po4a"))
269 (specification->package "gettext"))
271 (define glibc-utf8-locales
272 (module-ref (resolve-interface '(gnu packages base))
273 'glibc-utf8-locales))
275 (define documentation
276 (file-append* source "doc"))
278 (define documentation-po
279 (file-append* source "po/doc"))
282 (with-imported-modules '((guix build utils) (guix build po))
284 (use-modules (guix build utils) (guix build po)
285 (ice-9 match) (ice-9 regex) (ice-9 textual-ports)
290 (copy-recursively #$documentation "."
291 #:log (%make-void-port "w"))
295 (copy-file file (basename file)))
296 (find-files #$documentation-po ".*.po$"))
298 (setenv "GUIX_LOCPATH"
299 #+(file-append glibc-utf8-locales "/lib/locale"))
300 (setenv "PATH" #+(file-append gettext "/bin"))
301 (setenv "LC_ALL" "en_US.UTF-8")
302 (setlocale LC_ALL "en_US.UTF-8")
304 (define (translate-tmp-texi po source output)
305 "Translate Texinfo file SOURCE using messages from PO, and write
306 the result to OUTPUT."
307 (invoke #+(file-append po4a "/bin/po4a-translate")
308 "-M" "UTF-8" "-L" "UTF-8" "-k" "0" "-f" "texinfo"
309 "-m" source "-p" po "-l" output))
311 (define (make-ref-regex msgid end)
312 (make-regexp (string-append
314 (string-join (string-split (regexp-quote msgid) #\ )
318 (define (translate-cross-references content translations)
319 "Take CONTENT, a string representing a .texi file and translate any
320 cross-reference in it (@ref, @xref and @pxref) that have a translation in
321 TRANSLATIONS, an alist of msgid and msgstr."
323 (lambda (elem content)
326 ;; Empty translations and strings containing some special characters
327 ;; cannot be the name of a section.
328 (if (or (equal? msgstr "")
329 (string-any (lambda (chr)
330 (member chr '(#\{ #\} #\( #\) #\newline #\,)))
333 ;; Otherwise, they might be the name of a section, so we
334 ;; need to translate any occurence in @(p?x?)ref{...}.
335 (let ((regexp1 (make-ref-regex msgid ","))
336 (regexp2 (make-ref-regex msgid "\\}")))
337 (regexp-substitute/global
339 (regexp-substitute/global
340 #f regexp1 content 'pre "ref{" msgstr "," 'post)
341 'pre "ref{" msgstr "}" 'post))))))
342 content translations))
344 (define (translate-texi po lang)
345 "Translate the manual for one language LANG using the PO file."
346 (let ((translations (call-with-input-file po read-po-file)))
347 (translate-tmp-texi po "guix.texi"
348 (string-append "guix." lang ".texi.tmp"))
349 (translate-tmp-texi po "contributing.texi"
350 (string-append "contributing." lang ".texi.tmp"))
351 (let* ((texi-name (string-append "guix." lang ".texi"))
352 (tmp-name (string-append texi-name ".tmp")))
353 (with-output-to-file texi-name
356 (translate-cross-references
357 (call-with-input-file tmp-name get-string-all)
359 (let* ((texi-name (string-append "contributing." lang ".texi"))
360 (tmp-name (string-append texi-name ".tmp")))
361 (with-output-to-file texi-name
364 (translate-cross-references
365 (call-with-input-file tmp-name get-string-all)
368 (for-each (lambda (po)
369 (match (reverse (string-split po #\.))
371 (translate-texi po lang))))
372 (find-files "." "^guix-manual\\.[a-z]{2}(_[A-Z]{2})?\\.po$"))
376 (copy-file file (string-append #$output "/" file)))
378 (find-files "." "contributing\\..*\\.texi$")
379 (find-files "." "guix\\..*\\.texi$"))))))
381 (computed-file "guix-translated-texinfo" build))
383 (define (info-manual source)
384 "Return the Info manual built from SOURCE."
386 (module-ref (resolve-interface '(gnu packages texinfo))
390 (module-ref (resolve-interface '(gnu packages graphviz))
393 (define glibc-utf8-locales
394 (module-ref (resolve-interface '(gnu packages base))
395 'glibc-utf8-locales))
397 (define documentation
398 (file-append* source "doc"))
401 (file-append* source "gnu/system/examples"))
404 (with-imported-modules '((guix build utils))
406 (use-modules (guix build utils))
410 ;; Create 'version.texi'.
411 ;; XXX: Can we use a more meaningful version string yet one that
412 ;; doesn't change at each commit?
413 (call-with-output-file "version.texi"
415 (let ((version "0.0-git"))
417 @set UPDATED 1 January 1970
418 @set UPDATED-MONTH January 1970
420 @set VERSION ~a\n" version version))))
422 ;; Copy configuration templates that the manual includes.
423 (for-each (lambda (template)
427 (basename template ".tmpl")
429 (find-files #$examples "\\.tmpl$"))
432 (mkdir-p (string-append #$output "/images"))
433 (for-each (lambda (dot-file)
434 (invoke #+(file-append graphviz "/bin/dot")
435 "-Tpng" "-Gratio=.9" "-Gnodesep=.005"
436 "-Granksep=.00005" "-Nfontsize=9"
437 "-Nheight=.1" "-Nwidth=.1"
438 "-o" (string-append #$output "/images/"
439 (basename dot-file ".dot")
442 (find-files (string-append #$documentation "/images")
446 (for-each (lambda (png-file)
447 (install-file png-file
448 (string-append #$output "/images")))
449 (find-files (string-append #$documentation "/images")
452 ;; Finally build the manual. Copy it the Texinfo files to $PWD and
453 ;; add a symlink to the 'images' directory so that 'makeinfo' can
454 ;; see those images and produce image references in the Info output.
455 (copy-recursively #$documentation "."
456 #:log (%make-void-port "w"))
457 (copy-recursively #+(translate-texi-manuals source) "."
458 #:log (%make-void-port "w"))
459 (delete-file-recursively "images")
460 (symlink (string-append #$output "/images") "images")
462 ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo.
463 (setenv "GUIX_LOCPATH"
464 #+(file-append glibc-utf8-locales "/lib/locale"))
466 (for-each (lambda (texi)
467 (unless (string=? "guix.texi" texi)
468 ;; Create 'version-LL.texi'.
469 (let* ((base (basename texi ".texi"))
470 (dot (string-index base #\.))
471 (tag (string-drop base (+ 1 dot))))
472 (symlink "version.texi"
473 (string-append "version-" tag ".texi"))))
475 (invoke #+(file-append texinfo "/bin/makeinfo")
476 texi "-I" #$documentation
478 "-o" (string-append #$output "/"
479 (basename texi ".texi")
482 (find-files "." "^guix\\.[a-z]{2}(_[A-Z]{2})?\\.texi$")))
484 ;; Compress Info files.
486 #+(file-append (specification->package "gzip") "/bin"))
487 (for-each (lambda (file)
488 (invoke "gzip" "-9n" file))
489 (find-files #$output "\\.info(-[0-9]+)?$")))))
491 (computed-file "guix-manual" build))
493 (define* (guile-module-union things #:key (name "guix-module-union"))
494 "Return the union of the subset of THINGS (packages, computed files, etc.)
495 that provide Guile modules."
497 (with-imported-modules '((guix build union))
499 (use-modules (guix build union))
501 (define (modules directory)
502 (string-append directory "/share/guile/site"))
504 (define (objects directory)
505 (string-append directory "/lib/guile"))
507 (union-build #$output
508 (filter (lambda (directory)
509 (or (file-exists? (modules directory))
510 (file-exists? (objects directory))))
513 #:log-port (%make-void-port "w")))))
515 (computed-file name build))
517 (define* (guix-command modules
518 #:key source (dependencies '())
519 guile (guile-version (effective-version)))
520 "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its
522 (define glibc-utf8-locales
523 (module-ref (resolve-interface '(gnu packages base))
524 'glibc-utf8-locales))
526 (define module-directory
527 ;; To minimize the number of 'stat' calls needed to locate a module,
528 ;; create the union of all the module directories.
529 (guile-module-union (cons modules dependencies)))
531 (program-file "guix-command"
534 (cons (string-append #$module-directory
539 (set! %load-compiled-path
540 (cons (string-append #$module-directory
544 %load-compiled-path))
546 ;; To maximize the chances that locales are set up right
547 ;; out-of-the-box, bundle "common" UTF-8 locales.
548 (let ((locpath (getenv "GUIX_LOCPATH")))
549 (setenv "GUIX_LOCPATH"
550 (string-append (if locpath
551 (string-append locpath ":")
553 #$(file-append glibc-utf8-locales
556 (let ((guix-main (module-ref (resolve-interface '(guix ui))
560 (bindtextdomain "guix"
561 #$(locale-data source "guix"))
562 (bindtextdomain "guix-packages"
563 #$(locale-data source
568 ;; XXX: It would be more convenient to change it to:
569 ;; (exit (apply guix-main (command-line)))
570 (apply guix-main (command-line))))
573 (define (miscellaneous-files source)
574 "Return data files taken from SOURCE."
575 (file-mapping "guix-misc"
576 `(("etc/bash_completion.d/guix"
577 ,(file-append* source "/etc/completion/bash/guix"))
578 ("etc/bash_completion.d/guix-daemon"
579 ,(file-append* source "/etc/completion/bash/guix-daemon"))
580 ("share/zsh/site-functions/_guix"
581 ,(file-append* source "/etc/completion/zsh/_guix"))
582 ("share/fish/vendor_completions.d/guix.fish"
583 ,(file-append* source "/etc/completion/fish/guix.fish"))
584 ("share/guix/berlin.guixsd.org.pub"
585 ,(file-append* source
586 "/etc/substitutes/berlin.guixsd.org.pub"))
587 ("share/guix/ci.guix.gnu.org.pub" ;alias
588 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub"))
589 ("share/guix/ci.guix.info.pub" ;alias
590 ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub")))))
592 (define* (whole-package name modules dependencies
594 (guile-version (effective-version))
595 info daemon miscellany
597 (command (guix-command modules
598 #:dependencies dependencies
600 #:guile-version guile-version)))
601 "Return the whole Guix package NAME that uses MODULES, a derivation of all
602 the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list
603 of packages depended on. COMMAND is the 'guix' program to use; INFO is the
605 (define (wrap daemon)
606 (program-file "guix-daemon"
608 ;; Refer to the right 'guix' command for 'guix
610 (setenv "GUIX" #$command)
612 ;; Honor the user's settings rather than those hardcoded
613 ;; in the 'guix-daemon' package.
614 (unless (getenv "GUIX_STATE_DIRECTORY")
615 (setenv "GUIX_STATE_DIRECTORY"
616 #$(string-append %localstatedir "/guix")))
617 (unless (getenv "GUIX_CONFIGURATION_DIRECTORY")
618 (setenv "GUIX_CONFIGURATION_DIRECTORY"
619 #$(string-append %sysconfdir "/guix")))
620 (unless (getenv "NIX_STORE_DIR")
621 (setenv "NIX_STORE_DIR" #$%storedir))
623 (apply execl #$(file-append daemon "/bin/guix-daemon")
624 "guix-daemon" (cdr (command-line))))))
627 (with-imported-modules '((guix build utils))
629 (use-modules (guix build utils))
632 #$(and daemon (wrap daemon)))
634 (mkdir-p (string-append #$output "/bin"))
636 (string-append #$output "/bin/guix"))
640 (string-append #$output "/bin/guix-daemon")))
642 (let ((share (string-append #$output "/share"))
643 (lib (string-append #$output "/lib"))
646 (symlink #$(file-append modules "/share/guile")
647 (string-append share "/guile"))
649 (symlink #$info (string-append share "/info")))
652 (symlink #$(file-append modules "/lib/guile")
653 (string-append lib "/guile")))
656 (copy-recursively #$miscellany #$output
657 #:log (%make-void-port "w")))))))
659 (define* (compiled-guix source #:key (version %guix-version)
661 (name (string-append "guix-" version))
662 (guile-version (effective-version))
663 (guile-for-build (default-guile))
664 (zlib (specification->package "zlib"))
665 (lzlib (specification->package "lzlib"))
666 (gzip (specification->package "gzip"))
667 (bzip2 (specification->package "bzip2"))
668 (xz (specification->package "xz"))
669 (guix (specification->package "guix")))
670 "Return a file-like object that contains a compiled Guix."
672 (specification->package "guile-json"))
675 (specification->package "guile-ssh"))
678 (specification->package "guile-git"))
680 (define guile-sqlite3
681 (specification->package "guile-sqlite3"))
684 (specification->package "guile-gcrypt"))
687 (specification->package "gnutls"))
690 (match (append-map (lambda (package)
691 (cons (list "x" package)
692 (package-transitive-propagated-inputs package)))
693 (list guile-gcrypt gnutls guile-git guile-json
694 guile-ssh guile-sqlite3))
695 (((labels packages _ ...) ...)
698 (define *core-modules*
699 (scheme-node "guix-core"
706 (guix build-system gnu)
707 (guix build-system trivial)
708 (guix build profiles)
709 (guix build gnu-build-system))
711 ;; Provide a dummy (guix config) with the default version
712 ;; number, storedir, etc. This is so that "guix-core" is the
713 ;; same across all installations and doesn't need to be
714 ;; rebuilt when the version changes, which in turn means we
715 ;; can have substitutes for it.
717 `(((guix config) => ,(make-config.scm)))
719 ;; (guix man-db) is needed at build-time by (guix profiles)
720 ;; but we don't need to compile it; not compiling it allows
721 ;; us to avoid an extra dependency on guile-gdbm-ffi.
723 `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm"))
724 ("guix/build/po.scm" ,(local-file "../guix/build/po.scm"))
725 ("guix/store/schema.sql"
726 ,(local-file "../guix/store/schema.sql")))
728 #:extensions (list guile-gcrypt)
729 #:guile-for-build guile-for-build))
731 (define *extra-modules*
732 (scheme-node "guix-extra"
733 (filter-map (match-lambda
734 (('guix 'scripts _ ..1) #f)
736 (('guix 'tests _ ...) #f)
738 (scheme-modules* source "guix"))
739 (list *core-modules*)
740 #:extensions dependencies
741 #:guile-for-build guile-for-build))
743 (define *core-package-modules*
744 (scheme-node "guix-packages-base"
747 (list *core-modules* *extra-modules*)
748 #:extensions dependencies
750 ;; Add all the non-Scheme files here. We must do it here so
751 ;; that 'search-patches' & co. can find them. Ideally we'd
752 ;; keep them next to the .scm files that use them but it's
753 ;; difficult to do (XXX).
755 (file-imports source "gnu/packages"
757 (and (eq? 'regular (stat:type stat))
758 (not (string-suffix? ".scm" file))
759 (not (string-suffix? ".go" file))
760 (not (string-prefix? ".#" file))
761 (not (string-suffix? "~" file)))))
762 #:guile-for-build guile-for-build))
764 (define *package-modules*
765 (scheme-node "guix-packages"
766 (scheme-modules* source "gnu/packages")
767 (list *core-modules* *extra-modules* *core-package-modules*)
768 #:extensions dependencies
769 #:guile-for-build guile-for-build))
771 (define *system-modules*
772 (scheme-node "guix-system"
775 ,@(scheme-modules* source "gnu/bootloader")
776 ,@(scheme-modules* source "gnu/system")
777 ,@(scheme-modules* source "gnu/services")
778 ,@(scheme-modules* source "gnu/machine"))
779 (list *core-package-modules* *package-modules*
780 *extra-modules* *core-modules*)
781 #:extensions dependencies
783 (append (file-imports source "gnu/system/examples"
786 ;; All the installer code is on the build-side.
787 (file-imports source "gnu/installer/"
789 ;; Build-side code that we don't build. Some of
790 ;; these depend on guile-rsvg, the Shepherd, etc.
791 (file-imports source "gnu/build" (const #t)))
795 (define *cli-modules*
796 (scheme-node "guix-cli"
797 (append (scheme-modules* source "/guix/scripts")
799 (list *core-modules* *extra-modules*
800 *core-package-modules* *package-modules*
802 #:extensions dependencies
803 #:guile-for-build guile-for-build))
805 (define *system-test-modules*
806 ;; Ship these modules mostly so (gnu ci) can discover them.
807 (scheme-node "guix-system-tests"
809 ,@(scheme-modules* source "gnu/tests"))
810 (list *core-package-modules* *package-modules*
811 *extra-modules* *system-modules* *core-modules*
812 *cli-modules*) ;for (guix scripts pack), etc.
813 #:extensions dependencies
814 #:guile-for-build guile-for-build))
817 (scheme-node "guix-config"
821 => ,(make-config.scm #:zlib zlib
831 %guix-bug-report-address
833 %guix-home-page-url)))
834 #:guile-for-build guile-for-build))
836 (define (built-modules node-subset)
837 (directory-union (string-append name "-modules")
838 (append-map node-subset
840 ;; Note: *CONFIG* comes first so that it
841 ;; overrides the (guix config) module that
842 ;; comes with *CORE-MODULES*.
845 *system-test-modules*
848 *core-package-modules*
852 ;; Silently choose the first entry upon collision so that
853 ;; we choose *CONFIG*.
854 #:resolve-collision 'first
856 ;; When we do (add-to-store "utils.scm"), "utils.scm" must
857 ;; be a regular file, not a symlink. Thus, arrange so that
858 ;; regular files appear as regular files in the final
863 ;; Version 0 of 'guix pull' meant we'd just return Scheme modules.
864 ;; Version 1 is when we return the full package.
865 (cond ((= 1 pull-version)
866 ;; The whole package, with a standard file hierarchy.
867 (let* ((modules (built-modules (compose list node-source+compiled)))
868 (command (guix-command modules
870 #:dependencies dependencies
871 #:guile guile-for-build
872 #:guile-version guile-version)))
873 (whole-package name modules dependencies
875 #:guile guile-for-build
877 ;; Include 'guix-daemon'. XXX: Here we inject an
878 ;; older snapshot of guix-daemon, but that's a good
879 ;; enough approximation for now.
880 #:daemon (module-ref (resolve-interface
885 #:info (info-manual source)
886 #:miscellany (miscellaneous-files source)
887 #:guile-version guile-version)))
889 ;; Legacy 'guix pull': return the .scm and .go files as one
891 (built-modules (lambda (node)
892 (list (node-source node)
893 (node-compiled node)))))
895 ;; Unsupported 'guix pull' version.
900 ;;; Generating (guix config).
903 (define %persona-variables
904 ;; (guix config) variables that define Guix's persona.
907 %guix-bug-report-address
908 %guix-home-page-url))
910 (define %config-variables
911 ;; (guix config) variables corresponding to Guix configuration.
912 (letrec-syntax ((variables (syntax-rules ()
915 ((_ variable rest ...)
916 (cons `(variable . ,variable)
917 (variables rest ...))))))
918 (variables %localstatedir %storedir %sysconfdir)))
920 (define* (make-config.scm #:key zlib lzlib gzip xz bzip2
921 (package-name "GNU Guix")
922 (package-version "0")
923 (bug-report-address "bug-guix@gnu.org")
924 (home-page-url "https://guix.gnu.org"))
926 ;; Hack so that Geiser is not confused.
927 (define defmod 'define-module)
929 (scheme-file "config.scm"
930 #~(;; The following expressions get spliced.
931 (#$defmod (guix config)
932 #:export (%guix-package-name
934 %guix-bug-report-address
939 %store-database-directory
950 #$@(map (match-lambda
952 #~(define-public #$name #$value)))
955 (define %store-directory
956 (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path)
959 (define %state-directory
960 ;; This must match `NIX_STATE_DIR' as defined in
962 (or (getenv "GUIX_STATE_DIRECTORY")
963 (string-append %localstatedir "/guix")))
965 (define %store-database-directory
966 (or (getenv "GUIX_DATABASE_DIRECTORY")
967 (string-append %state-directory "/db")))
969 (define %config-directory
970 ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as
971 ;; defined in `nix/local.mk'.
972 (or (getenv "GUIX_CONFIGURATION_DIRECTORY")
973 (string-append %sysconfdir "/guix")))
975 (define %guix-package-name #$package-name)
976 (define %guix-version #$package-version)
977 (define %guix-bug-report-address #$bug-report-address)
978 (define %guix-home-page-url #$home-page-url)
981 #+(and gzip (file-append gzip "/bin/gzip")))
983 #+(and bzip2 (file-append bzip2 "/bin/bzip2")))
985 #+(and xz (file-append xz "/bin/xz")))
989 (file-append zlib "/lib/libz")))
993 (file-append lzlib "/lib/liblz"))))
995 ;; Guile 2.0 *requires* the 'define-module' to be at the
996 ;; top-level or the 'toplevel-ref' in the resulting .go file are
997 ;; made relative to a nonexistent anonymous module.
1005 (define* (compiled-modules name module-tree module-files
1008 (dependencies-compiled '())
1010 (extensions '()) ;full-blown Guile packages
1013 "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list
1014 like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory
1015 containing MODULE-FILES and possibly other files as well."
1016 ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix
1019 (with-imported-modules (source-module-closure
1020 '((guix build compile)
1021 (guix build utils)))
1023 (use-modules (srfi srfi-26)
1027 (guix build compile)
1030 (define (regular? file)
1031 (not (member file '("." ".."))))
1033 (define (report-load file total completed)
1036 "[~3@a/~3@a] loading...\t~5,1f% of ~d files"
1038 ;; Note: Multiply TOTAL by two to account for the
1039 ;; compilation phase that follows.
1040 completed (* total 2)
1042 (* 100. (/ completed total)) total)
1045 (define (report-compilation file total completed)
1047 (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files"
1049 ;; Add TOTAL to account for the load phase that came
1051 (+ total completed) (* total 2)
1053 (* 100. (/ completed total)) total)
1056 (define (process-directory directory files output)
1057 ;; Hide compilation warnings.
1058 (parameterize ((current-warning-port (%make-void-port "w")))
1059 (compile-files directory #$output files
1060 #:workers (parallel-job-count)
1061 #:report-load report-load
1062 #:report-compilation report-compilation)))
1064 (setvbuf (current-output-port) 'line)
1065 (setvbuf (current-error-port) 'line)
1067 (set! %load-path (cons #+module-tree %load-path))
1069 (append '#+dependencies
1070 (map (lambda (extension)
1071 (string-append extension "/share/guile/site/"
1072 (effective-version)))
1076 (set! %load-compiled-path
1077 (append '#+dependencies-compiled
1078 (map (lambda (extension)
1079 (string-append extension "/lib/guile/"
1083 %load-compiled-path))
1085 ;; Load the compiler modules upfront.
1089 (chdir #+module-tree)
1090 (process-directory "." '#+module-files #$output)
1093 (computed-file name build
1094 #:guile guile-for-build
1096 `(#:local-build? #f ;allow substitutes
1098 ;; Don't annoy people about _IONBF deprecation.
1099 ;; Initialize 'terminal-width' in (system repl debug)
1100 ;; to a large-enough value to make backtrace more
1102 #:env-vars (("GUILE_WARN_DEPRECATED" . "no")
1103 ("COLUMNS" . "200")))))
1110 (define* (guix-derivation source version
1111 #:optional (guile-version (effective-version))
1112 #:key (pull-version 0))
1113 "Return, as a monadic value, the derivation to build the Guix from SOURCE
1114 for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies
1115 the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value
1117 (define (shorten version)
1118 (if (and (string-every char-set:hex-digit version)
1119 (> (string-length version) 9))
1120 (string-take version 9) ;Git commit
1124 ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2
1128 (when (and (< pull-version 1)
1129 (not (string=? (package-version guile) guile-version)))
1130 ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and
1131 ;; can be any version. When that happens and Guile is not current (e.g.,
1132 ;; it's Guile 2.0), just bail out.
1135 (message "Guix is too old and cannot be upgraded")))))
1137 (mbegin %store-monad
1138 (set-guile-for-build guile)
1139 (let ((guix (compiled-guix source
1141 #:name (string-append "guix-"
1143 #:pull-version pull-version
1144 #:guile-version (if (>= pull-version 1)
1145 "2.2" guile-version)
1146 #:guile-for-build guile)))