gnu: gnupg: Update to 2.2.25.
[jackhill/guix/guix.git] / gnu / ci.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2017, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
4 ;;; Copyright © 2018, 2019 Clément Lassieur <clement@lassieur.org>
5 ;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22 (define-module (gnu ci)
23 #:use-module (guix config)
24 #:use-module (guix store)
25 #:use-module (guix grafts)
26 #:use-module (guix profiles)
27 #:use-module (guix packages)
28 #:use-module (guix channels)
29 #:use-module (guix config)
30 #:use-module (guix derivations)
31 #:use-module (guix build-system)
32 #:use-module (guix monads)
33 #:use-module (guix gexp)
34 #:use-module (guix ui)
35 #:use-module ((guix licenses)
36 #:select (gpl3+ license? license-name))
37 #:use-module ((guix utils) #:select (%current-system))
38 #:use-module ((guix scripts system) #:select (read-operating-system))
39 #:use-module ((guix scripts pack)
40 #:select (lookup-compressor self-contained-tarball))
41 #:use-module (gnu bootloader)
42 #:use-module (gnu bootloader u-boot)
43 #:use-module (gnu image)
44 #:use-module (gnu packages)
45 #:use-module (gnu packages gcc)
46 #:use-module (gnu packages base)
47 #:use-module (gnu packages gawk)
48 #:use-module (gnu packages guile)
49 #:use-module (gnu packages gettext)
50 #:use-module (gnu packages compression)
51 #:use-module (gnu packages multiprecision)
52 #:use-module (gnu packages make-bootstrap)
53 #:use-module (gnu packages package-management)
54 #:use-module (gnu system)
55 #:use-module (gnu system image)
56 #:use-module (gnu system vm)
57 #:use-module (gnu system install)
58 #:use-module (gnu system images hurd)
59 #:use-module (gnu system images pine64)
60 #:use-module (gnu system images pinebook-pro)
61 #:use-module (gnu tests)
62 #:use-module (srfi srfi-1)
63 #:use-module (srfi srfi-26)
64 #:use-module (ice-9 match)
65 #:export (%cross-targets
66 channel-source->package
67 hydra-jobs))
68
69 ;;; Commentary:
70 ;;;
71 ;;; This file defines build jobs for the Hydra and Cuirass continuation
72 ;;; integration tools.
73 ;;;
74 ;;; Code:
75
76 (define* (package->alist store package system
77 #:optional (package-derivation package-derivation))
78 "Convert PACKAGE to an alist suitable for Hydra."
79 (parameterize ((%graft? #f))
80 (let ((drv (package-derivation store package system
81 #:graft? #f)))
82 `((derivation . ,(derivation-file-name drv))
83 (log . ,(log-file store (derivation-file-name drv)))
84 (outputs . ,(filter-map (lambda (res)
85 (match res
86 ((name . path)
87 `(,name . ,path))))
88 (derivation->output-paths drv)))
89 (nix-name . ,(derivation-name drv))
90 (system . ,(derivation-system drv))
91 (description . ,(package-synopsis package))
92 (long-description . ,(package-description package))
93
94 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
95 ;; list thereof.
96 (license . ,(let loop ((license (package-license package)))
97 (match license
98 ((? license?)
99 (license-name license))
100 ((lst ...)
101 (map loop license)))))
102
103 (home-page . ,(package-home-page package))
104 (maintainers . ("bug-guix@gnu.org"))
105 (max-silent-time . ,(or (assoc-ref (package-properties package)
106 'max-silent-time)
107 3600)) ;1 hour by default
108 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
109 72000)))))) ;20 hours by default
110
111 (define (package-job store job-name package system)
112 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
113 (let ((job-name (symbol-append job-name (string->symbol ".")
114 (string->symbol system))))
115 `(,job-name . ,(cut package->alist store package system))))
116
117 (define (package-cross-job store job-name package target system)
118 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
119 SYSTEM."
120 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
121 (string->symbol ".") (string->symbol system)) .
122 ,(cute package->alist store package system
123 (lambda* (store package system #:key graft?)
124 (package-cross-derivation store package target system
125 #:graft? graft?)))))
126
127 (define %core-packages
128 ;; Note: Don't put the '-final' package variants because (1) that's
129 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
130 ;; chain.)
131 (list gcc-7 gcc-8 gcc-9 gcc-10 glibc binutils
132 gmp mpfr mpc coreutils findutils diffutils patch sed grep
133 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
134 %bootstrap-binaries-tarball
135 %binutils-bootstrap-tarball
136 (%glibc-bootstrap-tarball)
137 %gcc-bootstrap-tarball
138 %guile-bootstrap-tarball
139 %bootstrap-tarballs))
140
141 (define (packages-to-cross-build target)
142 "Return the list of packages to cross-build for TARGET."
143 ;; Don't cross-build the bootstrap tarballs for MinGW.
144 (if (string-contains target "mingw")
145 (drop-right %core-packages 6)
146 %core-packages))
147
148 (define %cross-targets
149 '("mips64el-linux-gnu"
150 "arm-linux-gnueabihf"
151 "aarch64-linux-gnu"
152 "powerpc-linux-gnu"
153 "riscv64-linux-gnu"
154 "i586-pc-gnu" ;aka. GNU/Hurd
155 "i686-w64-mingw32"
156 "x86_64-w64-mingw32"))
157
158 (define (cross-jobs store system)
159 "Return a list of cross-compilation jobs for SYSTEM."
160 (define (from-32-to-64? target)
161 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
162 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
163 ;; mips64el-linux-gnuabi64.
164 (and (or (string-prefix? "i686-" system)
165 (string-prefix? "i586-" system)
166 (string-prefix? "armhf-" system))
167 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
168
169 (define (same? target)
170 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
171 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
172 ;; 'mips64el-linux'.
173 (or (string-contains target system)
174 (and (string-prefix? "armhf" system) ;armhf-linux
175 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
176
177 (define (pointless? target)
178 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
179 (match system
180 ((or "x86_64-linux" "i686-linux")
181 (if (string-contains target "mingw")
182 (not (string=? "x86_64-linux" system))
183 #f))
184 (_
185 ;; Don't try to cross-compile from non-Intel platforms: this isn't
186 ;; very useful and these are often brittle configurations.
187 #t)))
188
189 (define (either proc1 proc2 proc3)
190 (lambda (x)
191 (or (proc1 x) (proc2 x) (proc3 x))))
192
193 (append-map (lambda (target)
194 (map (lambda (package)
195 (package-cross-job store (job-name package)
196 package target system))
197 (packages-to-cross-build target)))
198 (remove (either from-32-to-64? same? pointless?)
199 %cross-targets)))
200
201 ;; Architectures that are able to build or cross-build Guix System images.
202 ;; This does not mean that other architectures are not supported, only that
203 ;; they are often not fast enough to support Guix System images building.
204 (define %guix-system-supported-systems
205 '("x86_64-linux" "i686-linux"))
206
207 (define %guix-system-images
208 (list hurd-barebones-qcow2-image
209 pine64-barebones-raw-image
210 pinebook-pro-barebones-raw-image))
211
212 (define (image-jobs store system)
213 "Return a list of jobs that build images for SYSTEM."
214 (define (->alist drv)
215 `((derivation . ,(derivation-file-name drv))
216 (log . ,(log-file store (derivation-file-name drv)))
217 (outputs . ,(filter-map (lambda (res)
218 (match res
219 ((name . path)
220 `(,name . ,path))))
221 (derivation->output-paths drv)))
222 (nix-name . ,(derivation-name drv))
223 (system . ,(derivation-system drv))
224 (description . "Stand-alone image of the GNU system")
225 (long-description . "This is a demo stand-alone image of the GNU
226 system.")
227 (license . ,(license-name gpl3+))
228 (max-silent-time . 600)
229 (timeout . 3600)
230 (home-page . ,%guix-home-page-url)
231 (maintainers . ("bug-guix@gnu.org"))))
232
233 (define (->job name drv)
234 (let ((name (symbol-append name (string->symbol ".")
235 (string->symbol system))))
236 `(,name . ,(lambda ()
237 (parameterize ((%graft? #f))
238 (->alist drv))))))
239
240 (define (build-image image)
241 (run-with-store store
242 (mbegin %store-monad
243 (set-guile-for-build (default-guile))
244 (lower-object (system-image image)))))
245
246 (define MiB
247 (expt 2 20))
248
249 (if (member system %guix-system-supported-systems)
250 `(,(->job 'usb-image
251 (build-image
252 (image
253 (inherit efi-disk-image)
254 (operating-system installation-os))))
255 ,(->job 'iso9660-image
256 (build-image
257 (image
258 (inherit (image-with-label
259 iso9660-image
260 (string-append "GUIX_" system "_"
261 (if (> (string-length %guix-version) 7)
262 (substring %guix-version 0 7)
263 %guix-version))))
264 (operating-system installation-os))))
265 ;; Only cross-compile Guix System images from x86_64-linux for now.
266 ,@(if (string=? system "x86_64-linux")
267 (map (lambda (image)
268 (->job (image-name image) (build-image image)))
269 %guix-system-images)
270 '()))
271 '()))
272
273 (define channel-build-system
274 ;; Build system used to "convert" a channel instance to a package.
275 (let* ((build (lambda* (store name inputs
276 #:key source commit system
277 #:allow-other-keys)
278 (run-with-store store
279 ;; SOURCE can be a lowerable object such as <local-file>
280 ;; or a file name. Adjust accordingly.
281 (mlet* %store-monad ((source (if (string? source)
282 (return source)
283 (lower-object source)))
284 (instance
285 -> (checkout->channel-instance
286 source #:commit commit)))
287 (channel-instances->derivation (list instance)))
288 #:system system)))
289 (lower (lambda* (name #:key system source commit
290 #:allow-other-keys)
291 (bag
292 (name name)
293 (system system)
294 (build build)
295 (arguments `(#:source ,source
296 #:commit ,commit))))))
297 (build-system (name 'channel)
298 (description "Turn a channel instance into a package.")
299 (lower lower))))
300
301 (define* (channel-source->package source #:key commit)
302 "Return a package for the given channel SOURCE, a lowerable object."
303 (package
304 (inherit guix)
305 (version (string-append (package-version guix) "+"))
306 (build-system channel-build-system)
307 (arguments `(#:source ,source
308 #:commit ,commit))
309 (inputs '())
310 (native-inputs '())
311 (propagated-inputs '())))
312
313 (define* (system-test-jobs store system
314 #:key source commit)
315 "Return a list of jobs for the system tests."
316 (define (test->thunk test)
317 (lambda ()
318 (define drv
319 (run-with-store store
320 (mbegin %store-monad
321 (set-current-system system)
322 (set-grafting #f)
323 (set-guile-for-build (default-guile))
324 (system-test-value test))))
325
326 `((derivation . ,(derivation-file-name drv))
327 (log . ,(log-file store (derivation-file-name drv)))
328 (outputs . ,(filter-map (lambda (res)
329 (match res
330 ((name . path)
331 `(,name . ,path))))
332 (derivation->output-paths drv)))
333 (nix-name . ,(derivation-name drv))
334 (system . ,(derivation-system drv))
335 (description . ,(format #f "Guix '~a' system test"
336 (system-test-name test)))
337 (long-description . ,(system-test-description test))
338 (license . ,(license-name gpl3+))
339 (max-silent-time . 600)
340 (timeout . 3600)
341 (home-page . ,%guix-home-page-url)
342 (maintainers . ("bug-guix@gnu.org")))))
343
344 (define (->job test)
345 (let ((name (string->symbol
346 (string-append "test." (system-test-name test)
347 "." system))))
348 (cons name (test->thunk test))))
349
350 (if (member system %guix-system-supported-systems)
351 ;; Override the value of 'current-guix' used by system tests. Using a
352 ;; channel instance makes tests that rely on 'current-guix' less
353 ;; expensive. It also makes sure we get a valid Guix package when this
354 ;; code is not running from a checkout.
355 (parameterize ((current-guix-package
356 (channel-source->package source #:commit commit)))
357 (map ->job (all-system-tests)))
358 '()))
359
360 (define (tarball-jobs store system)
361 "Return Hydra jobs to build the self-contained Guix binary tarball."
362 (define (->alist drv)
363 `((derivation . ,(derivation-file-name drv))
364 (log . ,(log-file store (derivation-file-name drv)))
365 (outputs . ,(filter-map (lambda (res)
366 (match res
367 ((name . path)
368 `(,name . ,path))))
369 (derivation->output-paths drv)))
370 (nix-name . ,(derivation-name drv))
371 (system . ,(derivation-system drv))
372 (description . "Stand-alone binary Guix tarball")
373 (long-description . "This is a tarball containing binaries of Guix and
374 all its dependencies, and ready to be installed on \"foreign\" distributions.")
375 (license . ,(license-name gpl3+))
376 (home-page . ,%guix-home-page-url)
377 (maintainers . ("bug-guix@gnu.org"))))
378
379 (define (->job name drv)
380 (let ((name (symbol-append name (string->symbol ".")
381 (string->symbol system))))
382 `(,name . ,(lambda ()
383 (parameterize ((%graft? #f))
384 (->alist drv))))))
385
386 ;; XXX: Add a job for the stable Guix?
387 (list (->job 'binary-tarball
388 (run-with-store store
389 (mbegin %store-monad
390 (set-guile-for-build (default-guile))
391 (>>= (profile-derivation (packages->manifest (list guix)))
392 (lambda (profile)
393 (self-contained-tarball "guix-binary" profile
394 #:localstatedir? #t
395 #:compressor
396 (lookup-compressor "xz")))))
397 #:system system))))
398
399 (define job-name
400 ;; Return the name of a package's job.
401 (compose string->symbol
402 (cut package-full-name <> "-")))
403
404 (define package->job
405 (let ((base-packages
406 (delete-duplicates
407 (append-map (match-lambda
408 ((_ package _ ...)
409 (match (package-transitive-inputs package)
410 (((_ inputs _ ...) ...)
411 inputs))))
412 (%final-inputs)))))
413 (lambda (store package system)
414 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
415 valid."
416 (cond ((member package base-packages)
417 (package-job store (symbol-append 'base. (job-name package))
418 package system))
419 ((supported-package? package system)
420 (let ((drv (package-derivation store package system
421 #:graft? #f)))
422 (and (substitutable-derivation? drv)
423 (package-job store (job-name package)
424 package system))))
425 (else
426 #f)))))
427
428 (define (all-packages)
429 "Return the list of packages to build."
430 (define (adjust package result)
431 (cond ((package-replacement package)
432 ;; XXX: If PACKAGE and its replacement have the same name/version,
433 ;; then both Cuirass jobs will have the same name, which
434 ;; effectively means that the second one will be ignored. Thus,
435 ;; return the replacement first.
436 (cons* (package-replacement package) ;build both
437 package
438 result))
439 ((package-superseded package)
440 result) ;don't build it
441 (else
442 (cons package result))))
443
444 (fold-packages adjust
445 (fold adjust '() ;include base packages
446 (match (%final-inputs)
447 (((labels packages _ ...) ...)
448 packages)))
449 #:select? (const #t))) ;include hidden packages
450
451 (define (arguments->manifests arguments)
452 "Return the list of manifests extracted from ARGUMENTS."
453 (map (match-lambda
454 ((input-name . relative-path)
455 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
456 (base (assq-ref checkout 'file-name)))
457 (in-vicinity base relative-path))))
458 (assq-ref arguments 'manifests)))
459
460 (define (manifests->packages store manifests)
461 "Return the list of packages found in MANIFESTS."
462 (define (load-manifest manifest)
463 (save-module-excursion
464 (lambda ()
465 (set-current-module (make-user-module '((guix profiles) (gnu))))
466 (primitive-load manifest))))
467
468 (delete-duplicates!
469 (map manifest-entry-item
470 (append-map (compose manifest-entries
471 load-manifest)
472 manifests))))
473
474 (define (find-current-checkout arguments)
475 "Find the first checkout of ARGUMENTS that provided the current file.
476 Return #f if no such checkout is found."
477 (let ((current-root
478 (canonicalize-path
479 (string-append (dirname (current-filename)) "/.."))))
480 (find (lambda (argument)
481 (and=> (assq-ref argument 'file-name)
482 (lambda (name)
483 (string=? name current-root)))) arguments)))
484
485 \f
486 ;;;
487 ;;; Hydra entry point.
488 ;;;
489
490 (define (hydra-jobs store arguments)
491 "Return Hydra jobs."
492 (define subset
493 (match (assoc-ref arguments 'subset)
494 ("core" 'core) ; only build core packages
495 ("hello" 'hello) ; only build hello
496 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
497 ("manifests" 'manifests) ; only build packages in the list of manifests
498 (_ 'all))) ; build everything
499
500 (define systems
501 (match (assoc-ref arguments 'systems)
502 (#f %hydra-supported-systems)
503 ((lst ...) lst)
504 ((? string? str) (call-with-input-string str read))))
505
506 (define checkout
507 (or (find-current-checkout arguments)
508 (assq-ref arguments 'superior-guix-checkout)))
509
510 (define commit
511 (assq-ref checkout 'revision))
512
513 (define source
514 (assq-ref checkout 'file-name))
515
516 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
517 (parameterize ((%graft? #f))
518 ;; Return one job for each package, except bootstrap packages.
519 (append-map (lambda (system)
520 (format (current-error-port)
521 "evaluating for '~a' (heap size: ~a MiB)...~%"
522 system
523 (round
524 (/ (assoc-ref (gc-stats) 'heap-size)
525 (expt 2. 20))))
526 (invalidate-derivation-caches!)
527 (case subset
528 ((all)
529 ;; Build everything, including replacements.
530 (let ((all (all-packages))
531 (job (lambda (package)
532 (package->job store package
533 system))))
534 (append (filter-map job all)
535 (image-jobs store system)
536 (system-test-jobs store system
537 #:source source
538 #:commit commit)
539 (tarball-jobs store system)
540 (cross-jobs store system))))
541 ((core)
542 ;; Build core packages only.
543 (append (map (lambda (package)
544 (package-job store (job-name package)
545 package system))
546 %core-packages)
547 (cross-jobs store system)))
548 ((hello)
549 ;; Build hello package only.
550 (let ((hello (specification->package "hello")))
551 (list (package-job store (job-name hello) hello system))))
552 ((list)
553 ;; Build selected list of packages only.
554 (let* ((names (assoc-ref arguments 'subset))
555 (packages (map specification->package names)))
556 (map (lambda (package)
557 (package-job store (job-name package)
558 package system))
559 packages)))
560 ((manifests)
561 ;; Build packages in the list of manifests.
562 (let* ((manifests (arguments->manifests arguments))
563 (packages (manifests->packages store manifests)))
564 (map (lambda (package)
565 (package-job store (job-name package)
566 package system))
567 packages)))
568 (else
569 (error "unknown subset" subset))))
570 systems)))