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