Commit | Line | Data |
---|---|---|
eaae07ec | 1 | ;;; GNU Guix --- Functional package management for GNU |
76832d34 | 2 | ;;; Copyright © 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
eaae07ec LC |
3 | ;;; |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
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) | |
eaae07ec | 29 | #:use-module (guix modules) |
45779fa6 | 30 | #:use-module ((guix build utils) #:select (find-files)) |
eaae07ec LC |
31 | #:use-module ((guix build compile) #:select (%lightweight-optimizations)) |
32 | #:use-module (srfi srfi-1) | |
33 | #:use-module (srfi srfi-9) | |
6e54e488 | 34 | #:use-module (srfi srfi-35) |
eaae07ec LC |
35 | #:use-module (ice-9 match) |
36 | #:export (make-config.scm | |
8a0d9bc8 | 37 | whole-package ;for internal use in 'guix pull' |
eaae07ec | 38 | compiled-guix |
567f0d25 | 39 | guix-derivation)) |
eaae07ec LC |
40 | |
41 | \f | |
42 | ;;; | |
43 | ;;; Dependency handling. | |
44 | ;;; | |
45 | ||
eaae07ec LC |
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)))) | |
51 | (match-lambda | |
52 | ("guile" (ref '(gnu packages commencement) 'guile-final)) | |
53 | ("guile-json" (ref '(gnu packages guile) 'guile-json)) | |
54 | ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh)) | |
55 | ("guile-git" (ref '(gnu packages guile) 'guile-git)) | |
d59e75f3 | 56 | ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3)) |
ca719424 | 57 | ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt)) |
108015df | 58 | ("gnutls" (ref '(gnu packages tls) 'gnutls)) |
eaae07ec LC |
59 | ("zlib" (ref '(gnu packages compression) 'zlib)) |
60 | ("gzip" (ref '(gnu packages compression) 'gzip)) | |
61 | ("bzip2" (ref '(gnu packages compression) 'bzip2)) | |
62 | ("xz" (ref '(gnu packages compression) 'xz)) | |
6e54e488 | 63 | (_ #f)))) ;no such package |
eaae07ec LC |
64 | |
65 | \f | |
66 | ;;; | |
67 | ;;; Derivations. | |
68 | ;;; | |
69 | ||
70 | ;; Node in a DAG of build tasks. Each node maps to a derivation, but it's | |
71 | ;; easier to express things this way. | |
72 | (define-record-type <node> | |
73 | (node name modules source dependencies compiled) | |
74 | node? | |
75 | (name node-name) ;string | |
76 | (modules node-modules) ;list of module names | |
77 | (source node-source) ;list of source files | |
78 | (dependencies node-dependencies) ;list of nodes | |
79 | (compiled node-compiled)) ;node -> lowerable object | |
80 | ||
f5db54ea LC |
81 | ;; File mappings are essentially an alist as passed to 'imported-files'. |
82 | (define-record-type <file-mapping> | |
83 | (file-mapping name alist) | |
84 | file-mapping? | |
85 | (name file-mapping-name) | |
86 | (alist file-mapping-alist)) | |
87 | ||
88 | (define-gexp-compiler (file-mapping-compiler (mapping <file-mapping>) | |
89 | system target) | |
90 | ;; Here we use 'imported-files', which can arrange to directly import all | |
91 | ;; the files instead of creating a derivation, when possible. | |
92 | (imported-files (map (match-lambda | |
93 | ((destination (? local-file? file)) | |
94 | (cons destination | |
95 | (local-file-absolute-file-name file))) | |
96 | ((destination source) | |
97 | (cons destination source))) ;silliness | |
98 | (file-mapping-alist mapping)) | |
99 | #:name (file-mapping-name mapping) | |
100 | #:system system)) | |
101 | ||
49c35bbb LC |
102 | (define (node-source+compiled node) |
103 | "Return a \"bundle\" containing both the source code and object files for | |
104 | NODE's modules, under their FHS directories: share/guile/site and lib/guile." | |
105 | (define build | |
106 | (with-imported-modules '((guix build utils)) | |
107 | #~(begin | |
108 | (use-modules (guix build utils)) | |
109 | ||
110 | (define source | |
111 | (string-append #$output "/share/guile/site/" | |
112 | (effective-version))) | |
113 | ||
114 | (define object | |
115 | (string-append #$output "/lib/guile/" (effective-version) | |
116 | "/site-ccache")) | |
117 | ||
118 | (mkdir-p (dirname source)) | |
119 | (symlink #$(node-source node) source) | |
120 | (mkdir-p (dirname object)) | |
121 | (symlink #$(node-compiled node) object)))) | |
122 | ||
123 | (computed-file (string-append (node-name node) "-modules") | |
124 | build)) | |
125 | ||
eaae07ec LC |
126 | (define (node-fold proc init nodes) |
127 | (let loop ((nodes nodes) | |
128 | (visited (setq)) | |
129 | (result init)) | |
130 | (match nodes | |
131 | (() result) | |
132 | ((head tail ...) | |
133 | (if (set-contains? visited head) | |
134 | (loop tail visited result) | |
135 | (loop tail (set-insert head visited) | |
136 | (proc head result))))))) | |
137 | ||
138 | (define (node-modules/recursive nodes) | |
139 | (node-fold (lambda (node modules) | |
140 | (append (node-modules node) modules)) | |
141 | '() | |
142 | nodes)) | |
143 | ||
144 | (define* (closure modules #:optional (except '())) | |
145 | (source-module-closure modules | |
146 | #:select? | |
147 | (match-lambda | |
148 | (('guix 'config) | |
149 | #f) | |
150 | ((and module | |
151 | (or ('guix _ ...) ('gnu _ ...))) | |
152 | (not (member module except))) | |
153 | (rest #f)))) | |
154 | ||
155 | (define module->import | |
156 | ;; Return a file-name/file-like object pair for the specified module and | |
157 | ;; suitable for 'imported-files'. | |
158 | (match-lambda | |
159 | ((module '=> thing) | |
160 | (let ((file (module-name->file-name module))) | |
161 | (list file thing))) | |
162 | (module | |
163 | (let ((file (module-name->file-name module))) | |
164 | (list file | |
165 | (local-file (search-path %load-path file))))))) | |
166 | ||
167 | (define* (scheme-node name modules #:optional (dependencies '()) | |
168 | #:key (extra-modules '()) (extra-files '()) | |
169 | (extensions '()) | |
170 | parallel? guile-for-build) | |
171 | "Return a node that builds the given Scheme MODULES, and depends on | |
172 | DEPENDENCIES (a list of nodes). EXTRA-MODULES is a list of additional modules | |
173 | added to the source, and EXTRA-FILES is a list of additional files. | |
174 | EXTENSIONS is a set of full-blown Guile packages (e.g., 'guile-json') that | |
175 | must be present in the search path." | |
176 | (let* ((modules (append extra-modules | |
177 | (closure modules | |
178 | (node-modules/recursive dependencies)))) | |
179 | (module-files (map module->import modules)) | |
f5db54ea LC |
180 | (source (file-mapping (string-append name "-source") |
181 | (append module-files extra-files)))) | |
eaae07ec | 182 | (node name modules source dependencies |
8031b3fa LC |
183 | (compiled-modules name source |
184 | (map car module-files) | |
eaae07ec LC |
185 | (map node-source dependencies) |
186 | (map node-compiled dependencies) | |
187 | #:extensions extensions | |
188 | #:parallel? parallel? | |
189 | #:guile-for-build guile-for-build)))) | |
190 | ||
191 | (define (file-imports directory sub-directory pred) | |
192 | "List all the files matching PRED under DIRECTORY/SUB-DIRECTORY. Return a | |
193 | list of file-name/file-like objects suitable as inputs to 'imported-files'." | |
194 | (map (lambda (file) | |
195 | (list (string-drop file (+ 1 (string-length directory))) | |
196 | (local-file file #:recursive? #t))) | |
197 | (find-files (string-append directory "/" sub-directory) pred))) | |
198 | ||
6cf502d1 LC |
199 | (define* (file-append* item file #:key (recursive? #t)) |
200 | "Return FILE within ITEM, which may be a file name or a file-like object. | |
201 | When ITEM is a plain file name (a string), simply return a 'local-file' | |
202 | record with the new file name." | |
9f1c3559 LC |
203 | (match item |
204 | ((? string?) | |
205 | ;; This is the optimal case: we return a new "source". Thus, a | |
206 | ;; derivation that depends on this sub-directory does not depend on ITEM | |
207 | ;; itself. | |
6cf502d1 LC |
208 | (local-file (string-append item "/" file) |
209 | #:recursive? recursive?)) | |
9f1c3559 LC |
210 | ;; TODO: Add 'local-file?' case. |
211 | (_ | |
212 | ;; In this case, anything that refers to the result also depends on ITEM, | |
213 | ;; which isn't great. | |
6cf502d1 | 214 | (file-append item "/" file)))) |
9f1c3559 LC |
215 | |
216 | (define* (locale-data source domain | |
217 | #:optional (directory domain)) | |
218 | "Return the locale data from 'po/DIRECTORY' in SOURCE, corresponding to | |
219 | DOMAIN, a gettext domain." | |
220 | (define gettext | |
221 | (module-ref (resolve-interface '(gnu packages gettext)) | |
222 | 'gettext-minimal)) | |
223 | ||
224 | (define build | |
225 | (with-imported-modules '((guix build utils)) | |
226 | #~(begin | |
227 | (use-modules (guix build utils) | |
228 | (srfi srfi-26) | |
229 | (ice-9 match) (ice-9 ftw)) | |
230 | ||
231 | (define po-directory | |
6cf502d1 | 232 | #+(file-append* source (string-append "po/" directory))) |
9f1c3559 LC |
233 | |
234 | (define (compile language) | |
235 | (let ((gmo (string-append #$output "/" language "/LC_MESSAGES/" | |
236 | #$domain ".mo"))) | |
237 | (mkdir-p (dirname gmo)) | |
238 | (invoke #+(file-append gettext "/bin/msgfmt") | |
239 | "-c" "--statistics" "--verbose" | |
240 | "-o" gmo | |
241 | (string-append po-directory "/" language ".po")))) | |
242 | ||
243 | (define (linguas) | |
244 | ;; Return the list of languages. Note: don't read 'LINGUAS' | |
245 | ;; because it contains things like 'en@boldquot' that do not have | |
246 | ;; a corresponding .po file. | |
247 | (map (cut basename <> ".po") | |
248 | (scandir po-directory | |
249 | (cut string-suffix? ".po" <>)))) | |
250 | ||
251 | (for-each compile (linguas))))) | |
252 | ||
253 | (computed-file (string-append "guix-locale-" domain) | |
254 | build)) | |
255 | ||
4554d4c8 LC |
256 | (define (info-manual source) |
257 | "Return the Info manual built from SOURCE." | |
258 | (define texinfo | |
259 | (module-ref (resolve-interface '(gnu packages texinfo)) | |
260 | 'texinfo)) | |
261 | ||
262 | (define graphviz | |
263 | (module-ref (resolve-interface '(gnu packages graphviz)) | |
264 | 'graphviz)) | |
265 | ||
2d337760 LC |
266 | (define glibc-utf8-locales |
267 | (module-ref (resolve-interface '(gnu packages base)) | |
268 | 'glibc-utf8-locales)) | |
269 | ||
4554d4c8 | 270 | (define documentation |
6cf502d1 | 271 | (file-append* source "doc")) |
4554d4c8 LC |
272 | |
273 | (define examples | |
6cf502d1 | 274 | (file-append* source "gnu/system/examples")) |
4554d4c8 LC |
275 | |
276 | (define build | |
277 | (with-imported-modules '((guix build utils)) | |
278 | #~(begin | |
279 | (use-modules (guix build utils)) | |
280 | ||
281 | (mkdir #$output) | |
282 | ||
283 | ;; Create 'version.texi'. | |
284 | ;; XXX: Can we use a more meaningful version string yet one that | |
285 | ;; doesn't change at each commit? | |
286 | (call-with-output-file "version.texi" | |
287 | (lambda (port) | |
cbe7387c | 288 | (let ((version "0.0-git")) |
4554d4c8 LC |
289 | (format port " |
290 | @set UPDATED 1 January 1970 | |
291 | @set UPDATED-MONTH January 1970 | |
292 | @set EDITION ~a | |
293 | @set VERSION ~a\n" version version)))) | |
294 | ||
295 | ;; Copy configuration templates that the manual includes. | |
296 | (for-each (lambda (template) | |
297 | (copy-file template | |
298 | (string-append | |
299 | "os-config-" | |
300 | (basename template ".tmpl") | |
301 | ".texi"))) | |
302 | (find-files #$examples "\\.tmpl$")) | |
303 | ||
304 | ;; Build graphs. | |
305 | (mkdir-p (string-append #$output "/images")) | |
306 | (for-each (lambda (dot-file) | |
307 | (invoke #+(file-append graphviz "/bin/dot") | |
308 | "-Tpng" "-Gratio=.9" "-Gnodesep=.005" | |
309 | "-Granksep=.00005" "-Nfontsize=9" | |
310 | "-Nheight=.1" "-Nwidth=.1" | |
311 | "-o" (string-append #$output "/images/" | |
312 | (basename dot-file ".dot") | |
313 | ".png") | |
314 | dot-file)) | |
315 | (find-files (string-append #$documentation "/images") | |
316 | "\\.dot$")) | |
317 | ||
318 | ;; Copy other PNGs. | |
319 | (for-each (lambda (png-file) | |
320 | (install-file png-file | |
321 | (string-append #$output "/images"))) | |
322 | (find-files (string-append #$documentation "/images") | |
323 | "\\.png$")) | |
324 | ||
325 | ;; Finally build the manual. Copy it the Texinfo files to $PWD and | |
326 | ;; add a symlink to the 'images' directory so that 'makeinfo' can | |
327 | ;; see those images and produce image references in the Info output. | |
328 | (copy-recursively #$documentation "." | |
329 | #:log (%make-void-port "w")) | |
330 | (delete-file-recursively "images") | |
331 | (symlink (string-append #$output "/images") "images") | |
332 | ||
2d337760 LC |
333 | ;; Provide UTF-8 locales needed by the 'xspara.c' code in makeinfo. |
334 | (setenv "GUIX_LOCPATH" | |
335 | #+(file-append glibc-utf8-locales "/lib/locale")) | |
336 | ||
4554d4c8 LC |
337 | (for-each (lambda (texi) |
338 | (unless (string=? "guix.texi" texi) | |
339 | ;; Create 'version-LL.texi'. | |
340 | (let* ((base (basename texi ".texi")) | |
341 | (dot (string-index base #\.)) | |
342 | (tag (string-drop base (+ 1 dot)))) | |
343 | (symlink "version.texi" | |
344 | (string-append "version-" tag ".texi")))) | |
345 | ||
346 | (invoke #+(file-append texinfo "/bin/makeinfo") | |
347 | texi "-I" #$documentation | |
348 | "-I" "." | |
349 | "-o" (string-append #$output "/" | |
350 | (basename texi ".texi") | |
351 | ".info"))) | |
352 | (cons "guix.texi" | |
08fdee39 LC |
353 | (find-files "." "^guix\\.[a-z]{2}\\.texi$"))) |
354 | ||
355 | ;; Compress Info files. | |
356 | (setenv "PATH" | |
357 | #+(file-append (specification->package "gzip") "/bin")) | |
358 | (for-each (lambda (file) | |
359 | (invoke "gzip" "-9n" file)) | |
360 | (find-files #$output "\\.info(-[0-9]+)?$"))))) | |
4554d4c8 LC |
361 | |
362 | (computed-file "guix-manual" build)) | |
363 | ||
49c35bbb LC |
364 | (define* (guile-module-union things #:key (name "guix-module-union")) |
365 | "Return the union of the subset of THINGS (packages, computed files, etc.) | |
366 | that provide Guile modules." | |
367 | (define build | |
368 | (with-imported-modules '((guix build union)) | |
369 | #~(begin | |
370 | (use-modules (guix build union)) | |
371 | ||
372 | (define (modules directory) | |
373 | (string-append directory "/share/guile/site")) | |
374 | ||
375 | (define (objects directory) | |
376 | (string-append directory "/lib/guile")) | |
377 | ||
378 | (union-build #$output | |
379 | (filter (lambda (directory) | |
380 | (or (file-exists? (modules directory)) | |
381 | (file-exists? (objects directory)))) | |
382 | '#$things) | |
383 | ||
384 | #:log-port (%make-void-port "w"))))) | |
385 | ||
386 | (computed-file name build)) | |
387 | ||
388 | (define* (guix-command modules | |
a89faa3f | 389 | #:key source (dependencies '()) |
8970a886 | 390 | guile (guile-version (effective-version))) |
8a0d9bc8 LC |
391 | "Return the 'guix' command such that it adds MODULES and DEPENDENCIES in its |
392 | load path." | |
49c35bbb LC |
393 | (define module-directory |
394 | ;; To minimize the number of 'stat' calls needed to locate a module, | |
395 | ;; create the union of all the module directories. | |
396 | (guile-module-union (cons modules dependencies))) | |
f2d0a2cf | 397 | |
8a0d9bc8 LC |
398 | (program-file "guix-command" |
399 | #~(begin | |
400 | (set! %load-path | |
49c35bbb LC |
401 | (cons (string-append #$module-directory |
402 | "/share/guile/site/" | |
403 | (effective-version)) | |
404 | %load-path)) | |
8a0d9bc8 | 405 | |
8a0d9bc8 | 406 | (set! %load-compiled-path |
49c35bbb LC |
407 | (cons (string-append #$module-directory |
408 | "/lib/guile/" | |
409 | (effective-version) | |
410 | "/site-ccache") | |
a89faa3f | 411 | %load-compiled-path)) |
8a0d9bc8 LC |
412 | |
413 | (let ((guix-main (module-ref (resolve-interface '(guix ui)) | |
414 | 'guix-main))) | |
9f1c3559 LC |
415 | #$(if source |
416 | #~(begin | |
417 | (bindtextdomain "guix" | |
418 | #$(locale-data source "guix")) | |
419 | (bindtextdomain "guix-packages" | |
420 | #$(locale-data source | |
421 | "guix-packages" | |
422 | "packages"))) | |
423 | #t) | |
8a0d9bc8 LC |
424 | |
425 | ;; XXX: It would be more convenient to change it to: | |
426 | ;; (exit (apply guix-main (command-line))) | |
8970a886 LC |
427 | (apply guix-main (command-line)))) |
428 | #:guile guile)) | |
8a0d9bc8 | 429 | |
e3744779 LC |
430 | (define (miscellaneous-files source) |
431 | "Return data files taken from SOURCE." | |
432 | (file-mapping "guix-misc" | |
433 | `(("etc/bash_completion.d/guix" | |
434 | ,(file-append* source "/etc/completion/bash/guix")) | |
435 | ("etc/bash_completion.d/guix-daemon" | |
436 | ,(file-append* source "/etc/completion/bash/guix-daemon")) | |
437 | ("share/zsh/site-functions/_guix" | |
438 | ,(file-append* source "/etc/completion/zsh/_guix")) | |
439 | ("share/fish/vendor_completions.d/guix.fish" | |
440 | ,(file-append* source "/etc/completion/fish/guix.fish")) | |
441 | ("share/guix/hydra.gnu.org.pub" | |
442 | ,(file-append* source | |
443 | "/etc/substitutes/hydra.gnu.org.pub")) | |
444 | ("share/guix/berlin.guixsd.org.pub" | |
6a837b60 LC |
445 | ,(file-append* source |
446 | "/etc/substitutes/berlin.guixsd.org.pub")) | |
447 | ("share/guix/ci.guix.info.pub" ;alias | |
e3744779 LC |
448 | ,(file-append* source "/etc/substitutes/berlin.guixsd.org.pub"))))) |
449 | ||
8a0d9bc8 | 450 | (define* (whole-package name modules dependencies |
9f1c3559 LC |
451 | #:key |
452 | (guile-version (effective-version)) | |
e3744779 | 453 | info daemon miscellany |
8d3beb3a | 454 | guile |
9f1c3559 LC |
455 | (command (guix-command modules |
456 | #:dependencies dependencies | |
8970a886 | 457 | #:guile guile |
9f1c3559 | 458 | #:guile-version guile-version))) |
8a0d9bc8 | 459 | "Return the whole Guix package NAME that uses MODULES, a derivation of all |
49c35bbb LC |
460 | the modules (under share/guile/site and lib/guile), and DEPENDENCIES, a list |
461 | of packages depended on. COMMAND is the 'guix' program to use; INFO is the | |
462 | Info manual." | |
765a5bf1 LC |
463 | (define (wrap daemon) |
464 | (program-file "guix-daemon" | |
465 | #~(begin | |
466 | (setenv "GUIX" #$command) | |
467 | (apply execl #$(file-append daemon "/bin/guix-daemon") | |
468 | "guix-daemon" (cdr (command-line)))))) | |
469 | ||
9f1c3559 LC |
470 | (computed-file name |
471 | (with-imported-modules '((guix build utils)) | |
472 | #~(begin | |
473 | (use-modules (guix build utils)) | |
e3744779 | 474 | |
765a5bf1 LC |
475 | (define daemon |
476 | #$(and daemon (wrap daemon))) | |
477 | ||
9f1c3559 LC |
478 | (mkdir-p (string-append #$output "/bin")) |
479 | (symlink #$command | |
480 | (string-append #$output "/bin/guix")) | |
481 | ||
765a5bf1 LC |
482 | (when daemon |
483 | (symlink daemon | |
baed9236 LC |
484 | (string-append #$output "/bin/guix-daemon"))) |
485 | ||
49c35bbb LC |
486 | (let ((share (string-append #$output "/share")) |
487 | (lib (string-append #$output "/lib")) | |
488 | (info #$info)) | |
489 | (mkdir-p share) | |
490 | (symlink #$(file-append modules "/share/guile") | |
491 | (string-append share "/guile")) | |
4554d4c8 | 492 | (when info |
49c35bbb LC |
493 | (symlink #$info (string-append share "/info"))) |
494 | ||
495 | (mkdir-p lib) | |
496 | (symlink #$(file-append modules "/lib/guile") | |
497 | (string-append lib "/guile"))) | |
a89faa3f | 498 | |
e3744779 LC |
499 | (when #$miscellany |
500 | (copy-recursively #$miscellany #$output | |
49c35bbb | 501 | #:log (%make-void-port "w"))))))) |
8a0d9bc8 | 502 | |
eaae07ec | 503 | (define* (compiled-guix source #:key (version %guix-version) |
8a0d9bc8 | 504 | (pull-version 1) |
eaae07ec LC |
505 | (name (string-append "guix-" version)) |
506 | (guile-version (effective-version)) | |
6e54e488 | 507 | (guile-for-build (default-guile)) |
eaae07ec LC |
508 | (zlib (specification->package "zlib")) |
509 | (gzip (specification->package "gzip")) | |
510 | (bzip2 (specification->package "bzip2")) | |
511 | (xz (specification->package "xz")) | |
512 | (guix (specification->package "guix"))) | |
513 | "Return a file-like object that contains a compiled Guix." | |
514 | (define guile-json | |
6e54e488 | 515 | (specification->package "guile-json")) |
eaae07ec LC |
516 | |
517 | (define guile-ssh | |
6e54e488 | 518 | (specification->package "guile-ssh")) |
eaae07ec LC |
519 | |
520 | (define guile-git | |
6e54e488 | 521 | (specification->package "guile-git")) |
eaae07ec | 522 | |
d59e75f3 | 523 | (define guile-sqlite3 |
6e54e488 | 524 | (specification->package "guile-sqlite3")) |
d59e75f3 | 525 | |
ca719424 | 526 | (define guile-gcrypt |
6e54e488 | 527 | (specification->package "guile-gcrypt")) |
ca719424 | 528 | |
108015df | 529 | (define gnutls |
6e54e488 | 530 | (specification->package "gnutls")) |
108015df | 531 | |
eaae07ec LC |
532 | (define dependencies |
533 | (match (append-map (lambda (package) | |
534 | (cons (list "x" package) | |
e13240f5 | 535 | (package-transitive-propagated-inputs package))) |
ca719424 | 536 | (list guile-gcrypt gnutls guile-git guile-json |
108015df | 537 | guile-ssh guile-sqlite3)) |
eaae07ec LC |
538 | (((labels packages _ ...) ...) |
539 | packages))) | |
540 | ||
541 | (define *core-modules* | |
542 | (scheme-node "guix-core" | |
543 | '((guix) | |
544 | (guix monad-repl) | |
545 | (guix packages) | |
546 | (guix download) | |
547 | (guix discovery) | |
548 | (guix profiles) | |
549 | (guix build-system gnu) | |
550 | (guix build-system trivial) | |
551 | (guix build profiles) | |
552 | (guix build gnu-build-system)) | |
553 | ||
554 | ;; Provide a dummy (guix config) with the default version | |
555 | ;; number, storedir, etc. This is so that "guix-core" is the | |
556 | ;; same across all installations and doesn't need to be | |
557 | ;; rebuilt when the version changes, which in turn means we | |
558 | ;; can have substitutes for it. | |
559 | #:extra-modules | |
ca719424 | 560 | `(((guix config) => ,(make-config.scm))) |
eaae07ec | 561 | |
8292f5a9 LC |
562 | ;; (guix man-db) is needed at build-time by (guix profiles) |
563 | ;; but we don't need to compile it; not compiling it allows | |
564 | ;; us to avoid an extra dependency on guile-gdbm-ffi. | |
565 | #:extra-files | |
3931c761 LC |
566 | `(("guix/man-db.scm" ,(local-file "../guix/man-db.scm")) |
567 | ("guix/store/schema.sql" | |
568 | ,(local-file "../guix/store/schema.sql"))) | |
8292f5a9 | 569 | |
ca719424 | 570 | #:extensions (list guile-gcrypt) |
eaae07ec LC |
571 | #:guile-for-build guile-for-build)) |
572 | ||
573 | (define *extra-modules* | |
574 | (scheme-node "guix-extra" | |
575 | (filter-map (match-lambda | |
576 | (('guix 'scripts _ ..1) #f) | |
8292f5a9 | 577 | (('guix 'man-db) #f) |
eaae07ec LC |
578 | (name name)) |
579 | (scheme-modules* source "guix")) | |
580 | (list *core-modules*) | |
581 | #:extensions dependencies | |
582 | #:guile-for-build guile-for-build)) | |
583 | ||
f2e66663 LC |
584 | (define *core-package-modules* |
585 | (scheme-node "guix-packages-base" | |
eaae07ec | 586 | `((gnu packages) |
f2e66663 | 587 | (gnu packages base)) |
eaae07ec LC |
588 | (list *core-modules* *extra-modules*) |
589 | #:extensions dependencies | |
f2e66663 LC |
590 | |
591 | ;; Add all the non-Scheme files here. We must do it here so | |
592 | ;; that 'search-patches' & co. can find them. Ideally we'd | |
593 | ;; keep them next to the .scm files that use them but it's | |
594 | ;; difficult to do (XXX). | |
595 | #:extra-files | |
eaae07ec LC |
596 | (file-imports source "gnu/packages" |
597 | (lambda (file stat) | |
598 | (and (eq? 'regular (stat:type stat)) | |
599 | (not (string-suffix? ".scm" file)) | |
600 | (not (string-suffix? ".go" file)) | |
601 | (not (string-prefix? ".#" file)) | |
602 | (not (string-suffix? "~" file))))) | |
603 | #:guile-for-build guile-for-build)) | |
604 | ||
f2e66663 LC |
605 | (define *package-modules* |
606 | (scheme-node "guix-packages" | |
607 | (scheme-modules* source "gnu/packages") | |
608 | (list *core-modules* *extra-modules* *core-package-modules*) | |
609 | #:extensions dependencies | |
610 | #:guile-for-build guile-for-build)) | |
611 | ||
eaae07ec LC |
612 | (define *system-modules* |
613 | (scheme-node "guix-system" | |
614 | `((gnu system) | |
615 | (gnu services) | |
a49d633c | 616 | ,@(scheme-modules* source "gnu/system") |
eaae07ec | 617 | ,@(scheme-modules* source "gnu/services")) |
f2e66663 LC |
618 | (list *core-package-modules* *package-modules* |
619 | *extra-modules* *core-modules*) | |
eaae07ec LC |
620 | #:extensions dependencies |
621 | #:extra-files | |
1458f768 LC |
622 | (append (file-imports source "gnu/system/examples" |
623 | (const #t)) | |
8bb62ae1 | 624 | |
a49d633c MO |
625 | ;; All the installer code is on the build-side. |
626 | (file-imports source "gnu/installer/" | |
627 | (const #t)) | |
1458f768 LC |
628 | ;; Build-side code that we don't build. Some of |
629 | ;; these depend on guile-rsvg, the Shepherd, etc. | |
630 | (file-imports source "gnu/build" (const #t))) | |
eaae07ec LC |
631 | #:guile-for-build |
632 | guile-for-build)) | |
633 | ||
634 | (define *cli-modules* | |
635 | (scheme-node "guix-cli" | |
b5f8c2c8 LC |
636 | (append (scheme-modules* source "/guix/scripts") |
637 | `((gnu ci))) | |
f2e66663 LC |
638 | (list *core-modules* *extra-modules* |
639 | *core-package-modules* *package-modules* | |
eaae07ec LC |
640 | *system-modules*) |
641 | #:extensions dependencies | |
642 | #:guile-for-build guile-for-build)) | |
643 | ||
5f2daffe LC |
644 | (define *system-test-modules* |
645 | ;; Ship these modules mostly so (gnu ci) can discover them. | |
646 | (scheme-node "guix-system-tests" | |
647 | `((gnu tests) | |
648 | ,@(scheme-modules* source "gnu/tests")) | |
649 | (list *core-package-modules* *package-modules* | |
650 | *extra-modules* *system-modules* *core-modules* | |
651 | *cli-modules*) ;for (guix scripts pack), etc. | |
652 | #:extensions dependencies | |
653 | #:guile-for-build guile-for-build)) | |
654 | ||
eaae07ec LC |
655 | (define *config* |
656 | (scheme-node "guix-config" | |
657 | '() | |
658 | #:extra-modules | |
659 | `(((guix config) | |
ca719424 | 660 | => ,(make-config.scm #:zlib zlib |
eaae07ec LC |
661 | #:gzip gzip |
662 | #:bzip2 bzip2 | |
663 | #:xz xz | |
eaae07ec LC |
664 | #:package-name |
665 | %guix-package-name | |
666 | #:package-version | |
667 | version | |
668 | #:bug-report-address | |
669 | %guix-bug-report-address | |
670 | #:home-page-url | |
671 | %guix-home-page-url))) | |
672 | #:guile-for-build guile-for-build)) | |
673 | ||
a89faa3f | 674 | (define (built-modules node-subset) |
8a0d9bc8 | 675 | (directory-union (string-append name "-modules") |
a89faa3f | 676 | (append-map node-subset |
8a0d9bc8 LC |
677 | |
678 | ;; Note: *CONFIG* comes first so that it | |
679 | ;; overrides the (guix config) module that | |
680 | ;; comes with *CORE-MODULES*. | |
681 | (list *config* | |
682 | *cli-modules* | |
54800977 | 683 | *system-test-modules* |
8a0d9bc8 LC |
684 | *system-modules* |
685 | *package-modules* | |
686 | *core-package-modules* | |
687 | *extra-modules* | |
688 | *core-modules*)) | |
689 | ||
690 | ;; Silently choose the first entry upon collision so that | |
691 | ;; we choose *CONFIG*. | |
692 | #:resolve-collision 'first | |
693 | ||
694 | ;; When we do (add-to-store "utils.scm"), "utils.scm" must | |
695 | ;; be a regular file, not a symlink. Thus, arrange so that | |
696 | ;; regular files appear as regular files in the final | |
697 | ;; output. | |
698 | #:copy? #t | |
699 | #:quiet? #t)) | |
700 | ||
701 | ;; Version 0 of 'guix pull' meant we'd just return Scheme modules. | |
702 | ;; Version 1 is when we return the full package. | |
703 | (cond ((= 1 pull-version) | |
704 | ;; The whole package, with a standard file hierarchy. | |
49c35bbb LC |
705 | (let* ((modules (built-modules (compose list node-source+compiled))) |
706 | (command (guix-command modules | |
a89faa3f LC |
707 | #:source source |
708 | #:dependencies dependencies | |
8970a886 | 709 | #:guile guile-for-build |
a89faa3f LC |
710 | #:guile-version guile-version))) |
711 | (whole-package name modules dependencies | |
9f1c3559 | 712 | #:command command |
8970a886 | 713 | #:guile guile-for-build |
baed9236 LC |
714 | |
715 | ;; Include 'guix-daemon'. XXX: Here we inject an | |
716 | ;; older snapshot of guix-daemon, but that's a good | |
717 | ;; enough approximation for now. | |
718 | #:daemon (module-ref (resolve-interface | |
719 | '(gnu packages | |
720 | package-management)) | |
721 | 'guix-daemon) | |
722 | ||
4554d4c8 | 723 | #:info (info-manual source) |
e3744779 | 724 | #:miscellany (miscellaneous-files source) |
9f1c3559 | 725 | #:guile-version guile-version))) |
8a0d9bc8 | 726 | ((= 0 pull-version) |
a89faa3f LC |
727 | ;; Legacy 'guix pull': return the .scm and .go files as one |
728 | ;; directory. | |
729 | (built-modules (lambda (node) | |
730 | (list (node-source node) | |
731 | (node-compiled node))))) | |
8a0d9bc8 LC |
732 | (else |
733 | ;; Unsupported 'guix pull' version. | |
734 | #f))) | |
eaae07ec LC |
735 | |
736 | \f | |
737 | ;;; | |
738 | ;;; Generating (guix config). | |
739 | ;;; | |
740 | ||
741 | (define %dependency-variables | |
742 | ;; (guix config) variables corresponding to dependencies. | |
ca719424 | 743 | '(%libz %xz %gzip %bzip2)) |
eaae07ec LC |
744 | |
745 | (define %persona-variables | |
746 | ;; (guix config) variables that define Guix's persona. | |
747 | '(%guix-package-name | |
748 | %guix-version | |
749 | %guix-bug-report-address | |
750 | %guix-home-page-url)) | |
751 | ||
752 | (define %config-variables | |
45779fa6 LC |
753 | ;; (guix config) variables corresponding to Guix configuration. |
754 | (letrec-syntax ((variables (syntax-rules () | |
755 | ((_) | |
756 | '()) | |
757 | ((_ variable rest ...) | |
758 | (cons `(variable . ,variable) | |
759 | (variables rest ...)))))) | |
7af5c2a2 | 760 | (variables %localstatedir %storedir %sysconfdir %system))) |
eaae07ec | 761 | |
ca719424 | 762 | (define* (make-config.scm #:key zlib gzip xz bzip2 |
eaae07ec LC |
763 | (package-name "GNU Guix") |
764 | (package-version "0") | |
765 | (bug-report-address "bug-guix@gnu.org") | |
766 | (home-page-url "https://gnu.org/s/guix")) | |
767 | ||
768 | ;; Hack so that Geiser is not confused. | |
769 | (define defmod 'define-module) | |
770 | ||
771 | (scheme-file "config.scm" | |
eb72cdf0 | 772 | #~(;; The following expressions get spliced. |
eaae07ec LC |
773 | (#$defmod (guix config) |
774 | #:export (%guix-package-name | |
775 | %guix-version | |
776 | %guix-bug-report-address | |
777 | %guix-home-page-url | |
7af5c2a2 LC |
778 | %store-directory |
779 | %state-directory | |
780 | %store-database-directory | |
781 | %config-directory | |
eaae07ec LC |
782 | %libz |
783 | %gzip | |
784 | %bzip2 | |
e8cb9c01 | 785 | %xz)) |
eaae07ec | 786 | |
63cab418 LC |
787 | #$@(map (match-lambda |
788 | ((name . value) | |
789 | #~(define-public #$name #$value))) | |
790 | %config-variables) | |
791 | ||
7af5c2a2 LC |
792 | (define %store-directory |
793 | (or (and=> (getenv "NIX_STORE_DIR") canonicalize-path) | |
794 | %storedir)) | |
795 | ||
796 | (define %state-directory | |
797 | ;; This must match `NIX_STATE_DIR' as defined in | |
798 | ;; `nix/local.mk'. | |
a87d66f3 | 799 | (or (getenv "GUIX_STATE_DIRECTORY") |
7af5c2a2 LC |
800 | (string-append %localstatedir "/guix"))) |
801 | ||
802 | (define %store-database-directory | |
a87d66f3 | 803 | (or (getenv "GUIX_DATABASE_DIRECTORY") |
7af5c2a2 LC |
804 | (string-append %state-directory "/db"))) |
805 | ||
806 | (define %config-directory | |
807 | ;; This must match `GUIX_CONFIGURATION_DIRECTORY' as | |
808 | ;; defined in `nix/local.mk'. | |
809 | (or (getenv "GUIX_CONFIGURATION_DIRECTORY") | |
810 | (string-append %sysconfdir "/guix"))) | |
811 | ||
63cab418 LC |
812 | (define %guix-package-name #$package-name) |
813 | (define %guix-version #$package-version) | |
814 | (define %guix-bug-report-address #$bug-report-address) | |
815 | (define %guix-home-page-url #$home-page-url) | |
816 | ||
63cab418 LC |
817 | (define %gzip |
818 | #+(and gzip (file-append gzip "/bin/gzip"))) | |
819 | (define %bzip2 | |
820 | #+(and bzip2 (file-append bzip2 "/bin/bzip2"))) | |
821 | (define %xz | |
822 | #+(and xz (file-append xz "/bin/xz"))) | |
823 | ||
63cab418 LC |
824 | (define %libz |
825 | #+(and zlib | |
e8cb9c01 | 826 | (file-append zlib "/lib/libz")))) |
eb72cdf0 LC |
827 | |
828 | ;; Guile 2.0 *requires* the 'define-module' to be at the | |
e8cb9c01 | 829 | ;; top-level or the 'toplevel-ref' in the resulting .go file are |
eb72cdf0 LC |
830 | ;; made relative to a nonexistent anonymous module. |
831 | #:splice? #t)) | |
eaae07ec | 832 | |
eaae07ec LC |
833 | \f |
834 | ;;; | |
835 | ;;; Building. | |
836 | ;;; | |
837 | ||
8031b3fa | 838 | (define* (compiled-modules name module-tree module-files |
eaae07ec LC |
839 | #:optional |
840 | (dependencies '()) | |
841 | (dependencies-compiled '()) | |
842 | #:key | |
843 | (extensions '()) ;full-blown Guile packages | |
844 | parallel? | |
845 | guile-for-build) | |
8031b3fa LC |
846 | "Build all the MODULE-FILES from MODULE-TREE. MODULE-FILES must be a list |
847 | like '(\"guix/foo.scm\" \"gnu/bar.scm\") and MODULE-TREE is the directory | |
848 | containing MODULE-FILES and possibly other files as well." | |
eaae07ec LC |
849 | ;; This is a non-monadic, enhanced version of 'compiled-file' from (guix |
850 | ;; gexp). | |
851 | (define build | |
852 | (with-imported-modules (source-module-closure | |
853 | '((guix build compile) | |
854 | (guix build utils))) | |
855 | #~(begin | |
856 | (use-modules (srfi srfi-26) | |
857 | (ice-9 match) | |
858 | (ice-9 format) | |
859 | (ice-9 threads) | |
860 | (guix build compile) | |
861 | (guix build utils)) | |
862 | ||
863 | (define (regular? file) | |
864 | (not (member file '("." "..")))) | |
865 | ||
866 | (define (report-load file total completed) | |
867 | (display #\cr) | |
868 | (format #t | |
35dcaa11 LC |
869 | "[~3@a/~3@a] loading...\t~5,1f% of ~d files" |
870 | ||
871 | ;; Note: Multiply TOTAL by two to account for the | |
872 | ;; compilation phase that follows. | |
873 | completed (* total 2) | |
874 | ||
eaae07ec LC |
875 | (* 100. (/ completed total)) total) |
876 | (force-output)) | |
877 | ||
878 | (define (report-compilation file total completed) | |
879 | (display #\cr) | |
35dcaa11 LC |
880 | (format #t "[~3@a/~3@a] compiling...\t~5,1f% of ~d files" |
881 | ||
882 | ;; Add TOTAL to account for the load phase that came | |
883 | ;; before. | |
884 | (+ total completed) (* total 2) | |
885 | ||
eaae07ec LC |
886 | (* 100. (/ completed total)) total) |
887 | (force-output)) | |
888 | ||
8031b3fa LC |
889 | (define (process-directory directory files output) |
890 | ;; Hide compilation warnings. | |
891 | (parameterize ((current-warning-port (%make-void-port "w"))) | |
892 | (compile-files directory #$output files | |
893 | #:workers (parallel-job-count) | |
894 | #:report-load report-load | |
895 | #:report-compilation report-compilation))) | |
eaae07ec | 896 | |
35dcaa11 LC |
897 | (setvbuf (current-output-port) 'line) |
898 | (setvbuf (current-error-port) 'line) | |
eaae07ec LC |
899 | |
900 | (set! %load-path (cons #+module-tree %load-path)) | |
901 | (set! %load-path | |
902 | (append '#+dependencies | |
903 | (map (lambda (extension) | |
904 | (string-append extension "/share/guile/site/" | |
905 | (effective-version))) | |
906 | '#+extensions) | |
907 | %load-path)) | |
908 | ||
909 | (set! %load-compiled-path | |
910 | (append '#+dependencies-compiled | |
911 | (map (lambda (extension) | |
912 | (string-append extension "/lib/guile/" | |
913 | (effective-version) | |
914 | "/site-ccache")) | |
915 | '#+extensions) | |
916 | %load-compiled-path)) | |
917 | ||
918 | ;; Load the compiler modules upfront. | |
919 | (compile #f) | |
920 | ||
921 | (mkdir #$output) | |
922 | (chdir #+module-tree) | |
8031b3fa | 923 | (process-directory "." '#+module-files #$output) |
69447b63 | 924 | (newline)))) |
eaae07ec LC |
925 | |
926 | (computed-file name build | |
927 | #:guile guile-for-build | |
928 | #:options | |
929 | `(#:local-build? #f ;allow substitutes | |
930 | ||
931 | ;; Don't annoy people about _IONBF deprecation. | |
54be2b4d LC |
932 | ;; Initialize 'terminal-width' in (system repl debug) |
933 | ;; to a large-enough value to make backtrace more | |
934 | ;; verbose. | |
935 | #:env-vars (("GUILE_WARN_DEPRECATED" . "no") | |
936 | ("COLUMNS" . "200"))))) | |
eaae07ec LC |
937 | |
938 | \f | |
939 | ;;; | |
940 | ;;; Building. | |
941 | ;;; | |
942 | ||
eaae07ec | 943 | (define* (guix-derivation source version |
8a0d9bc8 LC |
944 | #:optional (guile-version (effective-version)) |
945 | #:key (pull-version 0)) | |
eaae07ec | 946 | "Return, as a monadic value, the derivation to build the Guix from SOURCE |
8a0d9bc8 LC |
947 | for GUILE-VERSION. Use VERSION as the version string. PULL-VERSION specifies |
948 | the version of the 'guix pull' protocol. Return #f if this PULL-VERSION value | |
949 | is not supported." | |
eaae07ec LC |
950 | (define (shorten version) |
951 | (if (and (string-every char-set:hex-digit version) | |
952 | (> (string-length version) 9)) | |
953 | (string-take version 9) ;Git commit | |
954 | version)) | |
955 | ||
956 | (define guile | |
099bb017 LC |
957 | ;; When PULL-VERSION >= 1, produce a self-contained Guix and use Guile 2.2 |
958 | ;; unconditionally. | |
6e54e488 LC |
959 | (default-guile)) |
960 | ||
961 | (when (and (< pull-version 1) | |
962 | (not (string=? (package-version guile) guile-version))) | |
963 | ;; Guix < 0.15.0 has PULL-VERSION = 0, where the host Guile is reused and | |
964 | ;; can be any version. When that happens and Guile is not current (e.g., | |
965 | ;; it's Guile 2.0), just bail out. | |
966 | (raise (condition | |
967 | (&message | |
968 | (message "Guix is too old and cannot be upgraded"))))) | |
eaae07ec LC |
969 | |
970 | (mbegin %store-monad | |
971 | (set-guile-for-build guile) | |
8a0d9bc8 LC |
972 | (let ((guix (compiled-guix source |
973 | #:version version | |
974 | #:name (string-append "guix-" | |
975 | (shorten version)) | |
976 | #:pull-version pull-version | |
099bb017 | 977 | #:guile-version (if (>= pull-version 1) |
d02bb02f | 978 | "2.2" guile-version) |
8a0d9bc8 LC |
979 | #:guile-for-build guile))) |
980 | (if guix | |
981 | (lower-object guix) | |
982 | (return #f))))) |