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