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