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