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>
7 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 tests)
61 #:use-module (srfi srfi-1)
62 #:use-module (srfi srfi-26)
63 #:use-module (ice-9 match)
64 #:export (%cross-targets
65 channel-source->package
70 ;;; This file defines build jobs for the Hydra and Cuirass continuation
71 ;;; integration tools.
75 (define* (package->alist store package system
76 #:optional (package-derivation package-derivation))
77 "Convert PACKAGE to an alist suitable for Hydra."
78 (parameterize ((%graft? #f))
79 (let ((drv (package-derivation store package system
81 `((derivation . ,(derivation-file-name drv))
82 (log . ,(log-file store (derivation-file-name drv)))
83 (outputs . ,(filter-map (lambda (res)
87 (derivation->output-paths drv)))
88 (nix-name . ,(derivation-name drv))
89 (system . ,(derivation-system drv))
90 (description . ,(package-synopsis package))
91 (long-description . ,(package-description package))
92 (license . ,(and=> (package-license package) license-name))
93 (home-page . ,(package-home-page package))
94 (maintainers . ("bug-guix@gnu.org"))
95 (max-silent-time . ,(or (assoc-ref (package-properties package)
97 3600)) ;1 hour by default
98 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
99 72000)))))) ;20 hours by default
101 (define (package-job store job-name package system)
102 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
103 (let ((job-name (symbol-append job-name (string->symbol ".")
104 (string->symbol system))))
105 `(,job-name . ,(cut package->alist store package system))))
107 (define (package-cross-job store job-name package target system)
108 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
110 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
111 (string->symbol ".") (string->symbol system)) .
112 ,(cute package->alist store package system
113 (lambda* (store package system #:key graft?)
114 (package-cross-derivation store package target system
117 (define %core-packages
118 ;; Note: Don't put the '-final' package variants because (1) that's
119 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
121 (list gcc-7 gcc-8 gcc-9 gcc-10 glibc binutils
122 gmp mpfr mpc coreutils findutils diffutils patch sed grep
123 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
124 %bootstrap-binaries-tarball
125 %binutils-bootstrap-tarball
126 (%glibc-bootstrap-tarball)
127 %gcc-bootstrap-tarball
128 %guile-bootstrap-tarball
129 %bootstrap-tarballs))
131 (define (packages-to-cross-build target)
132 "Return the list of packages to cross-build for TARGET."
133 ;; Don't cross-build the bootstrap tarballs for MinGW.
134 (if (string-contains target "mingw")
135 (drop-right %core-packages 6)
138 (define %cross-targets
139 '("mips64el-linux-gnu"
140 "arm-linux-gnueabihf"
144 "i586-pc-gnu" ;aka. GNU/Hurd
146 "x86_64-w64-mingw32"))
148 (define (cross-jobs store system)
149 "Return a list of cross-compilation jobs for SYSTEM."
150 (define (from-32-to-64? target)
151 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
152 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
153 ;; mips64el-linux-gnuabi64.
154 (and (or (string-prefix? "i686-" system)
155 (string-prefix? "i586-" system)
156 (string-prefix? "armhf-" system))
157 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
159 (define (same? target)
160 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
161 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
163 (or (string-contains target system)
164 (and (string-prefix? "armhf" system) ;armhf-linux
165 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
167 (define (pointless? target)
168 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
170 ((or "x86_64-linux" "i686-linux")
171 (if (string-contains target "mingw")
172 (not (string=? "x86_64-linux" system))
175 ;; Don't try to cross-compile from non-Intel platforms: this isn't
176 ;; very useful and these are often brittle configurations.
179 (define (either proc1 proc2 proc3)
181 (or (proc1 x) (proc2 x) (proc3 x))))
183 (append-map (lambda (target)
184 (map (lambda (package)
185 (package-cross-job store (job-name package)
186 package target system))
187 (packages-to-cross-build target)))
188 (remove (either from-32-to-64? same? pointless?)
191 ;; Architectures that are able to build or cross-build Guix System images.
192 ;; This does not mean that other architectures are not supported, only that
193 ;; they are often not fast enough to support Guix System images building.
194 (define %guix-system-supported-systems
195 '("x86_64-linux" "i686-linux"))
197 (define %guix-system-images
198 (list hurd-barebones-qcow2-image
199 pine64-barebones-raw-image))
201 (define (image-jobs store system)
202 "Return a list of jobs that build images for SYSTEM."
203 (define (->alist drv)
204 `((derivation . ,(derivation-file-name drv))
205 (log . ,(log-file store (derivation-file-name drv)))
206 (outputs . ,(filter-map (lambda (res)
210 (derivation->output-paths drv)))
211 (nix-name . ,(derivation-name drv))
212 (system . ,(derivation-system drv))
213 (description . "Stand-alone image of the GNU system")
214 (long-description . "This is a demo stand-alone image of the GNU
216 (license . ,(license-name gpl3+))
217 (max-silent-time . 600)
219 (home-page . ,%guix-home-page-url)
220 (maintainers . ("bug-guix@gnu.org"))))
222 (define (->job name drv)
223 (let ((name (symbol-append name (string->symbol ".")
224 (string->symbol system))))
225 `(,name . ,(lambda ()
226 (parameterize ((%graft? #f))
229 (define (build-image image)
230 (run-with-store store
232 (set-guile-for-build (default-guile))
233 (lower-object (system-image image)))))
238 (if (member system %guix-system-supported-systems)
242 (inherit efi-disk-image)
243 (operating-system installation-os))))
244 ,(->job 'iso9660-image
247 (inherit (image-with-label
249 (string-append "GUIX_" system "_"
250 (if (> (string-length %guix-version) 7)
251 (substring %guix-version 0 7)
253 (operating-system installation-os))))
254 ;; Only cross-compile Guix System images from x86_64-linux for now.
255 ,@(if (string=? system "x86_64-linux")
257 (->job (image-name image) (build-image image)))
262 (define channel-build-system
263 ;; Build system used to "convert" a channel instance to a package.
264 (let* ((build (lambda* (store name inputs
265 #:key source commit system
267 (run-with-store store
268 ;; SOURCE can be a lowerable object such as <local-file>
269 ;; or a file name. Adjust accordingly.
270 (mlet* %store-monad ((source (if (string? source)
272 (lower-object source)))
274 -> (checkout->channel-instance
275 source #:commit commit)))
276 (channel-instances->derivation (list instance)))
278 (lower (lambda* (name #:key system source commit
284 (arguments `(#:source ,source
285 #:commit ,commit))))))
286 (build-system (name 'channel)
287 (description "Turn a channel instance into a package.")
290 (define* (channel-source->package source #:key commit)
291 "Return a package for the given channel SOURCE, a lowerable object."
294 (version (string-append (package-version guix) "+"))
295 (build-system channel-build-system)
296 (arguments `(#:source ,source
300 (propagated-inputs '())))
302 (define* (system-test-jobs store system
304 "Return a list of jobs for the system tests."
305 (define (test->thunk test)
308 (run-with-store store
310 (set-current-system system)
312 (set-guile-for-build (default-guile))
313 (system-test-value test))))
315 `((derivation . ,(derivation-file-name drv))
316 (log . ,(log-file store (derivation-file-name drv)))
317 (outputs . ,(filter-map (lambda (res)
321 (derivation->output-paths drv)))
322 (nix-name . ,(derivation-name drv))
323 (system . ,(derivation-system drv))
324 (description . ,(format #f "Guix '~a' system test"
325 (system-test-name test)))
326 (long-description . ,(system-test-description test))
327 (license . ,(license-name gpl3+))
328 (max-silent-time . 600)
330 (home-page . ,%guix-home-page-url)
331 (maintainers . ("bug-guix@gnu.org")))))
334 (let ((name (string->symbol
335 (string-append "test." (system-test-name test)
337 (cons name (test->thunk test))))
339 (if (member system %guix-system-supported-systems)
340 ;; Override the value of 'current-guix' used by system tests. Using a
341 ;; channel instance makes tests that rely on 'current-guix' less
342 ;; expensive. It also makes sure we get a valid Guix package when this
343 ;; code is not running from a checkout.
344 (parameterize ((current-guix-package
345 (channel-source->package source #:commit commit)))
346 (map ->job (all-system-tests)))
349 (define (tarball-jobs store system)
350 "Return Hydra jobs to build the self-contained Guix binary tarball."
351 (define (->alist drv)
352 `((derivation . ,(derivation-file-name drv))
353 (log . ,(log-file store (derivation-file-name drv)))
354 (outputs . ,(filter-map (lambda (res)
358 (derivation->output-paths drv)))
359 (nix-name . ,(derivation-name drv))
360 (system . ,(derivation-system drv))
361 (description . "Stand-alone binary Guix tarball")
362 (long-description . "This is a tarball containing binaries of Guix and
363 all its dependencies, and ready to be installed on \"foreign\" distributions.")
364 (license . ,(license-name gpl3+))
365 (home-page . ,%guix-home-page-url)
366 (maintainers . ("bug-guix@gnu.org"))))
368 (define (->job name drv)
369 (let ((name (symbol-append name (string->symbol ".")
370 (string->symbol system))))
371 `(,name . ,(lambda ()
372 (parameterize ((%graft? #f))
375 ;; XXX: Add a job for the stable Guix?
376 (list (->job 'binary-tarball
377 (run-with-store store
379 (set-guile-for-build (default-guile))
380 (>>= (profile-derivation (packages->manifest (list guix)))
382 (self-contained-tarball "guix-binary" profile
385 (lookup-compressor "xz")))))
389 ;; Return the name of a package's job.
390 (compose string->symbol
391 (cut package-full-name <> "-")))
396 (append-map (match-lambda
398 (match (package-transitive-inputs package)
399 (((_ inputs _ ...) ...)
402 (lambda (store package system)
403 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
405 (cond ((member package base-packages)
406 (package-job store (symbol-append 'base. (job-name package))
408 ((supported-package? package system)
409 (let ((drv (package-derivation store package system
411 (and (substitutable-derivation? drv)
412 (package-job store (job-name package)
417 (define (all-packages)
418 "Return the list of packages to build."
419 (define (adjust package result)
420 (cond ((package-replacement package)
421 ;; XXX: If PACKAGE and its replacement have the same name/version,
422 ;; then both Cuirass jobs will have the same name, which
423 ;; effectively means that the second one will be ignored. Thus,
424 ;; return the replacement first.
425 (cons* (package-replacement package) ;build both
428 ((package-superseded package)
429 result) ;don't build it
431 (cons package result))))
433 (fold-packages adjust
434 (fold adjust '() ;include base packages
435 (match (%final-inputs)
436 (((labels packages _ ...) ...)
438 #:select? (const #t))) ;include hidden packages
440 (define (arguments->manifests arguments)
441 "Return the list of manifests extracted from ARGUMENTS."
443 ((input-name . relative-path)
444 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
445 (base (assq-ref checkout 'file-name)))
446 (in-vicinity base relative-path))))
447 (assq-ref arguments 'manifests)))
449 (define (manifests->packages store manifests)
450 "Return the list of packages found in MANIFESTS."
451 (define (load-manifest manifest)
452 (save-module-excursion
454 (set-current-module (make-user-module '((guix profiles) (gnu))))
455 (primitive-load manifest))))
458 (map manifest-entry-item
459 (append-map (compose manifest-entries
463 (define (find-current-checkout arguments)
464 "Find the first checkout of ARGUMENTS that provided the current file.
465 Return #f if no such checkout is found."
468 (string-append (dirname (current-filename)) "/.."))))
469 (find (lambda (argument)
470 (and=> (assq-ref argument 'file-name)
472 (string=? name current-root)))) arguments)))
476 ;;; Hydra entry point.
479 (define (hydra-jobs store arguments)
482 (match (assoc-ref arguments 'subset)
483 ("core" 'core) ; only build core packages
484 ("hello" 'hello) ; only build hello
485 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
486 ("manifests" 'manifests) ; only build packages in the list of manifests
487 (_ 'all))) ; build everything
490 (match (assoc-ref arguments 'systems)
491 (#f %hydra-supported-systems)
493 ((? string? str) (call-with-input-string str read))))
496 (or (find-current-checkout arguments)
497 (assq-ref arguments 'superior-guix-checkout)))
500 (assq-ref checkout 'revision))
503 (assq-ref checkout 'file-name))
505 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
506 (parameterize ((%graft? #f))
507 ;; Return one job for each package, except bootstrap packages.
508 (append-map (lambda (system)
509 (format (current-error-port)
510 "evaluating for '~a' (heap size: ~a MiB)...~%"
513 (/ (assoc-ref (gc-stats) 'heap-size)
515 (invalidate-derivation-caches!)
518 ;; Build everything, including replacements.
519 (let ((all (all-packages))
520 (job (lambda (package)
521 (package->job store package
523 (append (filter-map job all)
524 (image-jobs store system)
525 (system-test-jobs store system
528 (tarball-jobs store system)
529 (cross-jobs store system))))
531 ;; Build core packages only.
532 (append (map (lambda (package)
533 (package-job store (job-name package)
536 (cross-jobs store system)))
538 ;; Build hello package only.
539 (let ((hello (specification->package "hello")))
540 (list (package-job store (job-name hello) hello system))))
542 ;; Build selected list of packages only.
543 (let* ((names (assoc-ref arguments 'subset))
544 (packages (map specification->package names)))
545 (map (lambda (package)
546 (package-job store (job-name package)
550 ;; Build packages in the list of manifests.
551 (let* ((manifests (arguments->manifests arguments))
552 (packages (manifests->packages store manifests)))
553 (map (lambda (package)
554 (package-job store (job-name package)
558 (error "unknown subset" subset))))