gnu: Add python-ueberzug.
[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)
996b5edf
MO
69 #:export (derivation->job
70 image->job
71
72 %core-packages
76bea3f8 73 %cross-targets
f292c501 74 channel-source->package
3034f3d0
MO
75
76 arguments->systems
76bea3f8 77 cuirass-jobs))
59fb5c1c
LC
78
79;;; Commentary:
80;;;
76bea3f8 81;;; This file defines build jobs for Cuirass.
59fb5c1c
LC
82;;;
83;;; Code:
84
76bea3f8
MO
85(define* (derivation->job name drv
86 #:key
76bea3f8
MO
87 (max-silent-time 3600)
88 (timeout 3600))
14ada964 89 "Return a Cuirass job called NAME and describing DRV.
76bea3f8
MO
90
91MAX-SILENT-TIME and TIMEOUT are build options passed to the daemon when
92building the derivation."
93 `((#:job-name . ,name)
94 (#:derivation . ,(derivation-file-name drv))
a5c2e0dc
MO
95 (#:inputs . ,(map (compose derivation-file-name
96 derivation-input-derivation)
97 (derivation-inputs drv)))
76bea3f8
MO
98 (#:outputs . ,(filter-map
99 (lambda (res)
100 (match res
101 ((name . path)
102 `(,name . ,path))))
103 (derivation->output-paths drv)))
104 (#:nix-name . ,(derivation-name drv))
105 (#:system . ,(derivation-system drv))
76bea3f8
MO
106 (#:max-silent-time . ,max-silent-time)
107 (#:timeout . ,timeout)))
108
109(define* (package-job store job-name package system
110 #:key cross? target)
59fb5c1c 111 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
76bea3f8
MO
112 (let ((job-name (string-append job-name "." system)))
113 (parameterize ((%graft? #f))
114 (let* ((drv (if cross?
115 (package-cross-derivation store package target system
116 #:graft? #f)
117 (package-derivation store package system
118 #:graft? #f)))
119 (max-silent-time (or (assoc-ref (package-properties package)
120 'max-silent-time)
121 3600))
122 (timeout (or (assoc-ref (package-properties package)
123 'timeout)
124 72000)))
125 (derivation->job job-name drv
126 #:max-silent-time max-silent-time
127 #:timeout timeout)))))
59fb5c1c
LC
128
129(define (package-cross-job store job-name package target system)
130 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
131SYSTEM."
76bea3f8
MO
132 (let ((name (string-append target "." job-name "." system)))
133 (package-job store name package system
134 #:cross? #t
135 #:target target)))
59fb5c1c
LC
136
137(define %core-packages
138 ;; Note: Don't put the '-final' package variants because (1) that's
139 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
140 ;; chain.)
84f38f03 141 (list gcc-7 gcc-8 gcc-9 gcc-10 glibc binutils
59fb5c1c
LC
142 gmp mpfr mpc coreutils findutils diffutils patch sed grep
143 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
144 %bootstrap-binaries-tarball
145 %binutils-bootstrap-tarball
146 (%glibc-bootstrap-tarball)
147 %gcc-bootstrap-tarball
148 %guile-bootstrap-tarball
149 %bootstrap-tarballs))
150
668a5198
LC
151(define (packages-to-cross-build target)
152 "Return the list of packages to cross-build for TARGET."
153 ;; Don't cross-build the bootstrap tarballs for MinGW.
154 (if (string-contains target "mingw")
155 (drop-right %core-packages 6)
156 %core-packages))
59fb5c1c
LC
157
158(define %cross-targets
159 '("mips64el-linux-gnu"
59fb5c1c
LC
160 "arm-linux-gnueabihf"
161 "aarch64-linux-gnu"
162 "powerpc-linux-gnu"
8d9aece8 163 "powerpc64le-linux-gnu"
2032d847 164 "riscv64-linux-gnu"
59fb5c1c 165 "i586-pc-gnu" ;aka. GNU/Hurd
67dac6b8
CD
166 "i686-w64-mingw32"
167 "x86_64-w64-mingw32"))
59fb5c1c 168
3046e73b
LC
169(define (cross-jobs store system)
170 "Return a list of cross-compilation jobs for SYSTEM."
171 (define (from-32-to-64? target)
172 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
173 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
174 ;; mips64el-linux-gnuabi64.
175 (and (or (string-prefix? "i686-" system)
176 (string-prefix? "i586-" system)
177 (string-prefix? "armhf-" system))
178 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
179
180 (define (same? target)
181 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
182 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
183 ;; 'mips64el-linux'.
184 (or (string-contains target system)
185 (and (string-prefix? "armhf" system) ;armhf-linux
186 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
187
188 (define (pointless? target)
189 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
190 (match system
191 ((or "x86_64-linux" "i686-linux")
192 (if (string-contains target "mingw")
193 (not (string=? "x86_64-linux" system))
194 #f))
195 (_
196 ;; Don't try to cross-compile from non-Intel platforms: this isn't
197 ;; very useful and these are often brittle configurations.
198 #t)))
199
200 (define (either proc1 proc2 proc3)
201 (lambda (x)
202 (or (proc1 x) (proc2 x) (proc3 x))))
203
204 (append-map (lambda (target)
205 (map (lambda (package)
206 (package-cross-job store (job-name package)
207 package target system))
50b99c90 208 (packages-to-cross-build target)))
3046e73b
LC
209 (remove (either from-32-to-64? same? pointless?)
210 %cross-targets)))
211
76bea3f8
MO
212(define* (guix-jobs store systems #:key source commit)
213 "Return a list of jobs for Guix itself."
214 (define build
215 (primitive-load (string-append source "/build-aux/build-self.scm")))
216
217 (map
218 (lambda (system)
219 (let ((name (string->symbol
220 (string-append "guix." system)))
221 (drv (run-with-store store
222 (build source #:version commit #:system system
223 #:pull-version 1
224 #:guile-version "2.2"))))
225 (derivation->job name drv)))
226 systems))
227
b06ba9e0
MO
228;; Architectures that are able to build or cross-build Guix System images.
229;; This does not mean that other architectures are not supported, only that
230;; they are often not fast enough to support Guix System images building.
231(define %guix-system-supported-systems
232 '("x86_64-linux" "i686-linux"))
59fb5c1c 233
b06ba9e0 234(define %guix-system-images
8a4f1eef 235 (list hurd-barebones-qcow2-image
17d9a91e 236 pine64-barebones-raw-image
846e5240
DM
237 pinebook-pro-barebones-raw-image
238 novena-barebones-raw-image))
59fb5c1c 239
fc2fa7ad
MO
240(define (hours hours)
241 (* 3600 hours))
242
996b5edf
MO
243(define* (image->job store image
244 #:key name system)
245 "Return the job for IMAGE on SYSTEM. If NAME is passed, use it as job name,
246otherwise use the IMAGE name."
247 (let* ((image-name (or name
248 (symbol->string (image-name image))))
249 (name (string-append image-name "." system))
250 (drv (run-with-store store
251 (mbegin %store-monad
252 (set-guile-for-build (default-guile))
253 (lower-object (system-image image))))))
254 (parameterize ((%graft? #f))
255 (derivation->job name drv))))
256
b06ba9e0 257(define (image-jobs store system)
14ada964 258 "Return a list of jobs that build images for SYSTEM."
59fb5c1c
LC
259 (define MiB
260 (expt 2 20))
261
b06ba9e0 262 (if (member system %guix-system-supported-systems)
996b5edf
MO
263 `(,(image->job store
264 (image
265 (inherit efi-disk-image)
266 (operating-system installation-os))
267 #:name "usb-image"
268 #:system system)
269 ,(image->job
270 store
271 (image
272 (inherit (image-with-label
273 iso9660-image
274 (string-append "GUIX_" system "_"
275 (if (> (string-length %guix-version) 7)
276 (substring %guix-version 0 7)
277 %guix-version))))
278 (operating-system installation-os))
279 #:name "iso9660-image"
280 #:system system)
b06ba9e0
MO
281 ;; Only cross-compile Guix System images from x86_64-linux for now.
282 ,@(if (string=? system "x86_64-linux")
996b5edf
MO
283 (map (cut image->job store <>
284 #:system system)
b06ba9e0
MO
285 %guix-system-images)
286 '()))
1189f405 287 '()))
59fb5c1c 288
7e6d8d36
LC
289(define channel-build-system
290 ;; Build system used to "convert" a channel instance to a package.
291 (let* ((build (lambda* (store name inputs
dd1ee160 292 #:key source commit system
c3ab921e 293 #:allow-other-keys)
7e6d8d36 294 (run-with-store store
bc8b2ffd
LC
295 ;; SOURCE can be a lowerable object such as <local-file>
296 ;; or a file name. Adjust accordingly.
297 (mlet* %store-monad ((source (if (string? source)
298 (return source)
299 (lower-object source)))
dd1ee160
LC
300 (instance
301 -> (checkout->channel-instance
302 source #:commit commit)))
303 (channel-instances->derivation (list instance)))
c3ab921e 304 #:system system)))
dd1ee160
LC
305 (lower (lambda* (name #:key system source commit
306 #:allow-other-keys)
7e6d8d36
LC
307 (bag
308 (name name)
309 (system system)
310 (build build)
dd1ee160
LC
311 (arguments `(#:source ,source
312 #:commit ,commit))))))
7e6d8d36
LC
313 (build-system (name 'channel)
314 (description "Turn a channel instance into a package.")
315 (lower lower))))
316
dd1ee160
LC
317(define* (channel-source->package source #:key commit)
318 "Return a package for the given channel SOURCE, a lowerable object."
7e6d8d36
LC
319 (package
320 (inherit guix)
dd1ee160 321 (version (string-append (package-version guix) "+"))
7e6d8d36 322 (build-system channel-build-system)
dd1ee160
LC
323 (arguments `(#:source ,source
324 #:commit ,commit))
7e6d8d36
LC
325 (inputs '())
326 (native-inputs '())
327 (propagated-inputs '())))
328
329(define* (system-test-jobs store system
330 #:key source commit)
59fb5c1c 331 "Return a list of jobs for the system tests."
59fb5c1c 332 (define (->job test)
fc37346f
MO
333 (let ((name (string-append "test." (system-test-name test)
334 "." system))
335 (drv (run-with-store store
336 (mbegin %store-monad
337 (set-current-system system)
338 (set-grafting #f)
339 (set-guile-for-build (default-guile))
340 (system-test-value test)))))
76bea3f8 341
fc37346f 342 (derivation->job name drv)))
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.
fc37346f
MO
349 (parameterize ((current-guix-package
350 (channel-source->package source #:commit commit)))
351 (map ->job (all-system-tests)))
59fb5c1c
LC
352 '()))
353
354(define (tarball-jobs store system)
76bea3f8 355 "Return jobs to build the self-contained Guix binary tarball."
59fb5c1c 356 (define (->job name drv)
76bea3f8
MO
357 (let ((name (string-append name "." system)))
358 (parameterize ((%graft? #f))
14ada964 359 (derivation->job name drv))))
59fb5c1c
LC
360
361 ;; XXX: Add a job for the stable Guix?
76bea3f8
MO
362 (list
363 (->job "binary-tarball"
364 (run-with-store store
365 (mbegin %store-monad
366 (set-guile-for-build (default-guile))
367 (>>= (profile-derivation (packages->manifest (list guix)))
368 (lambda (profile)
369 (self-contained-tarball "guix-binary" profile
2ccb715a 370 #:profile-name "current-guix"
76bea3f8
MO
371 #:localstatedir? #t
372 #:compressor
373 (lookup-compressor "xz")))))
374 #:system system))))
59fb5c1c
LC
375
376(define job-name
377 ;; Return the name of a package's job.
76bea3f8 378 package-name)
59fb5c1c
LC
379
380(define package->job
381 (let ((base-packages
382 (delete-duplicates
383 (append-map (match-lambda
76bea3f8
MO
384 ((_ package _ ...)
385 (match (package-transitive-inputs package)
386 (((_ inputs _ ...) ...)
387 inputs))))
59fb5c1c
LC
388 (%final-inputs)))))
389 (lambda (store package system)
390 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
391valid."
392 (cond ((member package base-packages)
76bea3f8 393 (package-job store (string-append "base." (job-name package))
59fb5c1c
LC
394 package system))
395 ((supported-package? package system)
396 (let ((drv (package-derivation store package system
397 #:graft? #f)))
398 (and (substitutable-derivation? drv)
399 (package-job store (job-name package)
400 package system))))
401 (else
402 #f)))))
403
404(define (all-packages)
405 "Return the list of packages to build."
406 (define (adjust package result)
407 (cond ((package-replacement package)
f00ff8db
LC
408 ;; XXX: If PACKAGE and its replacement have the same name/version,
409 ;; then both Cuirass jobs will have the same name, which
410 ;; effectively means that the second one will be ignored. Thus,
411 ;; return the replacement first.
412 (cons* (package-replacement package) ;build both
413 package
59fb5c1c
LC
414 result))
415 ((package-superseded package)
416 result) ;don't build it
417 (else
418 (cons package result))))
419
420 (fold-packages adjust
421 (fold adjust '() ;include base packages
422 (match (%final-inputs)
423 (((labels packages _ ...) ...)
424 packages)))
425 #:select? (const #t))) ;include hidden packages
426
76bea3f8 427(define (arguments->manifests arguments channels)
59fb5c1c 428 "Return the list of manifests extracted from ARGUMENTS."
862af8c2
MO
429 (map (lambda (manifest)
430 (any (lambda (checkout)
431 (let ((path (in-vicinity checkout manifest)))
432 (and (file-exists? path)
433 path)))
434 (map channel-url channels)))
76bea3f8 435 arguments))
59fb5c1c
LC
436
437(define (manifests->packages store manifests)
438 "Return the list of packages found in MANIFESTS."
439 (define (load-manifest manifest)
440 (save-module-excursion
441 (lambda ()
442 (set-current-module (make-user-module '((guix profiles) (gnu))))
443 (primitive-load manifest))))
444
445 (delete-duplicates!
446 (map manifest-entry-item
447 (append-map (compose manifest-entries
448 load-manifest)
449 manifests))))
450
3034f3d0
MO
451(define (arguments->systems arguments)
452 "Return the systems list from ARGUMENTS."
453 (match (assoc-ref arguments 'systems)
454 (#f %cuirass-supported-systems)
455 ((lst ...) lst)
456 ((? string? str) (call-with-input-string str read))))
457
59fb5c1c
LC
458\f
459;;;
76bea3f8 460;;; Cuirass entry point.
59fb5c1c
LC
461;;;
462
76bea3f8
MO
463(define (cuirass-jobs store arguments)
464 "Register Cuirass jobs."
59fb5c1c 465 (define subset
76bea3f8 466 (assoc-ref arguments 'subset))
59fb5c1c
LC
467
468 (define systems
3034f3d0 469 (arguments->systems arguments))
59fb5c1c 470
76bea3f8
MO
471 (define channels
472 (let ((channels (assq-ref arguments 'channels)))
473 (map sexp->channel channels)))
474
475 (define guix
476 (find guix-channel? channels))
7e6d8d36
LC
477
478 (define commit
76bea3f8 479 (channel-commit guix))
7e6d8d36
LC
480
481 (define source
76bea3f8 482 (channel-url guix))
7e6d8d36 483
59fb5c1c
LC
484 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
485 (parameterize ((%graft? #f))
486 ;; Return one job for each package, except bootstrap packages.
76bea3f8
MO
487 (append-map
488 (lambda (system)
489 (format (current-error-port)
490 "evaluating for '~a' (heap size: ~a MiB)...~%"
491 system
492 (round
493 (/ (assoc-ref (gc-stats) 'heap-size)
494 (expt 2. 20))))
495 (invalidate-derivation-caches!)
496 (match subset
497 ('all
498 ;; Build everything, including replacements.
499 (let ((all (all-packages))
500 (job (lambda (package)
501 (package->job store package system))))
502 (append
503 (filter-map job all)
76bea3f8
MO
504 (cross-jobs store system))))
505 ('core
506 ;; Build core packages only.
507 (append
508 (map (lambda (package)
509 (package-job store (job-name package)
510 package system))
511 %core-packages)
512 (cross-jobs store system)))
513 ('guix
514 ;; Build Guix modules only.
515 (guix-jobs store systems
516 #:source source
517 #:commit commit))
518 ('hello
519 ;; Build hello package only.
520 (let ((hello (specification->package "hello")))
521 (list (package-job store (job-name hello)
522 hello system))))
2afc79b5
MO
523 ('images
524 ;; Build Guix System images only.
525 (image-jobs store system))
526 ('system-tests
527 ;; Build Guix System tests only.
528 (system-test-jobs store system
529 #:source source
530 #:commit commit))
531 ('tarball
532 ;; Build Guix tarball only.
533 (tarball-jobs store system))
f97e220b
MO
534 (('custom . modules)
535 ;; Build custom modules jobs only.
536 (append-map
537 (lambda (module)
538 (let ((proc (module-ref
539 (resolve-interface module)
540 'cuirass-jobs)))
541 (proc store arguments)))
542 modules))
61a11653
MO
543 (('channels . channels)
544 ;; Build only the packages from CHANNELS.
545 (let ((all (all-packages)))
546 (filter-map
547 (lambda (package)
cbfcbb79
MO
548 (any (lambda (channel)
549 (and (member (channel-name channel) channels)
550 (package->job store package system)))
551 (package-channels package)))
61a11653 552 all)))
76bea3f8
MO
553 (('packages . rest)
554 ;; Build selected list of packages only.
555 (let ((packages (map specification->package rest)))
556 (map (lambda (package)
557 (package-job store (job-name package)
558 package system))
559 packages)))
560 (('manifests . rest)
561 ;; Build packages in the list of manifests.
562 (let* ((manifests (arguments->manifests rest channels))
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)))