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 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;; Copyright © 2018, 2019 Clément Lassieur <clement@lassieur.org>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu ci)
22 #:use-module (guix config)
23 #:use-module (guix store)
24 #:use-module (guix grafts)
25 #:use-module (guix profiles)
26 #:use-module (guix packages)
27 #:use-module (guix channels)
28 #:use-module (guix derivations)
29 #:use-module (guix build-system)
30 #:use-module (guix monads)
31 #:use-module (guix gexp)
32 #:use-module (guix ui)
33 #:use-module ((guix licenses)
34 #:select (gpl3+ license? license-name))
35 #:use-module ((guix utils) #:select (%current-system))
36 #:use-module ((guix scripts system) #:select (read-operating-system))
37 #:use-module ((guix scripts pack)
38 #:select (lookup-compressor self-contained-tarball))
39 #:use-module (gnu bootloader)
40 #:use-module (gnu bootloader u-boot)
41 #:use-module (gnu image)
42 #:use-module (gnu packages)
43 #:use-module (gnu packages gcc)
44 #:use-module (gnu packages base)
45 #:use-module (gnu packages gawk)
46 #:use-module (gnu packages guile)
47 #:use-module (gnu packages gettext)
48 #:use-module (gnu packages compression)
49 #:use-module (gnu packages multiprecision)
50 #:use-module (gnu packages make-bootstrap)
51 #:use-module (gnu packages package-management)
52 #:use-module (gnu system)
53 #:use-module (gnu system image)
54 #:use-module (gnu system vm)
55 #:use-module (gnu system install)
56 #:use-module (gnu tests)
57 #:use-module (srfi srfi-1)
58 #:use-module (srfi srfi-26)
59 #:use-module (ice-9 match)
60 #:export (%cross-targets
61 channel-source->package
66 ;;; This file defines build jobs for the Hydra and Cuirass continuation
67 ;;; integration tools.
71 (define* (package->alist store package system
72 #:optional (package-derivation package-derivation))
73 "Convert PACKAGE to an alist suitable for Hydra."
74 (parameterize ((%graft? #f))
75 `((derivation . ,(derivation-file-name
76 (package-derivation store package system
78 (description . ,(package-synopsis package))
79 (long-description . ,(package-description package))
81 ;; XXX: Hydra ignores licenses that are not a <license> structure or a
83 (license . ,(let loop ((license (package-license package)))
86 (license-name license))
88 (map loop license)))))
90 (home-page . ,(package-home-page package))
91 (maintainers . ("bug-guix@gnu.org"))
92 (max-silent-time . ,(or (assoc-ref (package-properties package)
94 3600)) ;1 hour by default
95 (timeout . ,(or (assoc-ref (package-properties package) 'timeout)
96 72000))))) ;20 hours by default
98 (define (package-job store job-name package system)
99 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
100 (let ((job-name (symbol-append job-name (string->symbol ".")
101 (string->symbol system))))
102 `(,job-name . ,(cut package->alist store package system))))
104 (define (package-cross-job store job-name package target system)
105 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
107 `(,(symbol-append (string->symbol target) (string->symbol ".") job-name
108 (string->symbol ".") (string->symbol system)) .
109 ,(cute package->alist store package system
110 (lambda* (store package system #:key graft?)
111 (package-cross-derivation store package target system
114 (define %core-packages
115 ;; Note: Don't put the '-final' package variants because (1) that's
116 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
118 (list gcc-4.8 gcc-4.9 gcc-5 glibc binutils
119 gmp mpfr mpc coreutils findutils diffutils patch sed grep
120 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
121 %bootstrap-binaries-tarball
122 %binutils-bootstrap-tarball
123 (%glibc-bootstrap-tarball)
124 %gcc-bootstrap-tarball
125 %guile-bootstrap-tarball
126 %bootstrap-tarballs))
128 (define %packages-to-cross-build
131 (define %cross-targets
132 '("mips64el-linux-gnu"
133 "arm-linux-gnueabihf"
137 "i586-pc-gnu" ;aka. GNU/Hurd
139 "x86_64-w64-mingw32"))
141 (define (cross-jobs store system)
142 "Return a list of cross-compilation jobs for SYSTEM."
143 (define (from-32-to-64? target)
144 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
145 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
146 ;; mips64el-linux-gnuabi64.
147 (and (or (string-prefix? "i686-" system)
148 (string-prefix? "i586-" system)
149 (string-prefix? "armhf-" system))
150 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
152 (define (same? target)
153 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
154 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
156 (or (string-contains target system)
157 (and (string-prefix? "armhf" system) ;armhf-linux
158 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
160 (define (pointless? target)
161 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
163 ((or "x86_64-linux" "i686-linux")
164 (if (string-contains target "mingw")
165 (not (string=? "x86_64-linux" system))
168 ;; Don't try to cross-compile from non-Intel platforms: this isn't
169 ;; very useful and these are often brittle configurations.
172 (define (either proc1 proc2 proc3)
174 (or (proc1 x) (proc2 x) (proc3 x))))
176 (append-map (lambda (target)
177 (map (lambda (package)
178 (package-cross-job store (job-name package)
179 package target system))
180 %packages-to-cross-build))
181 (remove (either from-32-to-64? same? pointless?)
184 (define %guixsd-supported-systems
185 '("x86_64-linux" "i686-linux" "armhf-linux"))
187 (define %u-boot-systems
190 (define (qemu-jobs store system)
191 "Return a list of jobs that build QEMU images for SYSTEM."
192 (define (->alist drv)
193 `((derivation . ,(derivation-file-name drv))
194 (description . "Stand-alone QEMU image of the GNU system")
195 (long-description . "This is a demo stand-alone QEMU image of the GNU
197 (license . ,(license-name gpl3+))
198 (max-silent-time . 600)
200 (home-page . ,%guix-home-page-url)
201 (maintainers . ("bug-guix@gnu.org"))))
203 (define (->job name drv)
204 (let ((name (symbol-append name (string->symbol ".")
205 (string->symbol system))))
206 `(,name . ,(lambda ()
207 (parameterize ((%graft? #f))
213 (if (member system %guixsd-supported-systems)
214 (list (->job 'usb-image
215 (run-with-store store
217 (set-guile-for-build (default-guile))
220 (inherit efi-disk-image)
222 (operating-system installation-os))))))
223 (->job 'iso9660-image
224 (run-with-store store
226 (set-guile-for-build (default-guile))
229 (inherit iso9660-image)
230 (operating-system installation-os)))))))
233 (define channel-build-system
234 ;; Build system used to "convert" a channel instance to a package.
235 (let* ((build (lambda* (store name inputs
236 #:key source commit system
238 (run-with-store store
239 ;; SOURCE can be a lowerable object such as <local-file>
240 ;; or a file name. Adjust accordingly.
241 (mlet* %store-monad ((source (if (string? source)
243 (lower-object source)))
245 -> (checkout->channel-instance
246 source #:commit commit)))
247 (channel-instances->derivation (list instance)))
249 (lower (lambda* (name #:key system source commit
255 (arguments `(#:source ,source
256 #:commit ,commit))))))
257 (build-system (name 'channel)
258 (description "Turn a channel instance into a package.")
261 (define* (channel-source->package source #:key commit)
262 "Return a package for the given channel SOURCE, a lowerable object."
265 (version (string-append (package-version guix) "+"))
266 (build-system channel-build-system)
267 (arguments `(#:source ,source
271 (propagated-inputs '())))
273 (define* (system-test-jobs store system
275 "Return a list of jobs for the system tests."
276 (define (test->thunk test)
279 (run-with-store store
281 (set-current-system system)
283 (set-guile-for-build (default-guile))
284 (system-test-value test))))
286 `((derivation . ,(derivation-file-name drv))
287 (description . ,(format #f "Guix '~a' system test"
288 (system-test-name test)))
289 (long-description . ,(system-test-description test))
290 (license . ,(license-name gpl3+))
291 (max-silent-time . 600)
293 (home-page . ,%guix-home-page-url)
294 (maintainers . ("bug-guix@gnu.org")))))
297 (let ((name (string->symbol
298 (string-append "test." (system-test-name test)
300 (cons name (test->thunk test))))
302 (if (and (member system %guixsd-supported-systems)
304 ;; XXX: Our build farm has too few ARMv7 machines and they are very
305 ;; slow, so skip system tests there.
306 (not (string=? system "armhf-linux")))
307 ;; Override the value of 'current-guix' used by system tests. Using a
308 ;; channel instance makes tests that rely on 'current-guix' less
309 ;; expensive. It also makes sure we get a valid Guix package when this
310 ;; code is not running from a checkout.
311 (parameterize ((current-guix-package
312 (channel-source->package source #:commit commit)))
313 (map ->job (all-system-tests)))
316 (define (tarball-jobs store system)
317 "Return Hydra jobs to build the self-contained Guix binary tarball."
318 (define (->alist drv)
319 `((derivation . ,(derivation-file-name drv))
320 (description . "Stand-alone binary Guix tarball")
321 (long-description . "This is a tarball containing binaries of Guix and
322 all its dependencies, and ready to be installed on \"foreign\" distributions.")
323 (license . ,(license-name gpl3+))
324 (home-page . ,%guix-home-page-url)
325 (maintainers . ("bug-guix@gnu.org"))))
327 (define (->job name drv)
328 (let ((name (symbol-append name (string->symbol ".")
329 (string->symbol system))))
330 `(,name . ,(lambda ()
331 (parameterize ((%graft? #f))
334 ;; XXX: Add a job for the stable Guix?
335 (list (->job 'binary-tarball
336 (run-with-store store
338 (set-guile-for-build (default-guile))
339 (>>= (profile-derivation (packages->manifest (list guix)))
341 (self-contained-tarball "guix-binary" profile
344 (lookup-compressor "xz")))))
348 ;; Return the name of a package's job.
349 (compose string->symbol
350 (cut package-full-name <> "-")))
355 (append-map (match-lambda
357 (match (package-transitive-inputs package)
358 (((_ inputs _ ...) ...)
361 (lambda (store package system)
362 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
364 (cond ((member package base-packages)
365 (package-job store (symbol-append 'base. (job-name package))
367 ((supported-package? package system)
368 (let ((drv (package-derivation store package system
370 (and (substitutable-derivation? drv)
371 (package-job store (job-name package)
376 (define (all-packages)
377 "Return the list of packages to build."
378 (define (adjust package result)
379 (cond ((package-replacement package)
380 ;; XXX: If PACKAGE and its replacement have the same name/version,
381 ;; then both Cuirass jobs will have the same name, which
382 ;; effectively means that the second one will be ignored. Thus,
383 ;; return the replacement first.
384 (cons* (package-replacement package) ;build both
387 ((package-superseded package)
388 result) ;don't build it
390 (cons package result))))
392 (fold-packages adjust
393 (fold adjust '() ;include base packages
394 (match (%final-inputs)
395 (((labels packages _ ...) ...)
397 #:select? (const #t))) ;include hidden packages
399 (define (arguments->manifests arguments)
400 "Return the list of manifests extracted from ARGUMENTS."
402 ((input-name . relative-path)
403 (let* ((checkout (assq-ref arguments (string->symbol input-name)))
404 (base (assq-ref checkout 'file-name)))
405 (in-vicinity base relative-path))))
406 (assq-ref arguments 'manifests)))
408 (define (manifests->packages store manifests)
409 "Return the list of packages found in MANIFESTS."
410 (define (load-manifest manifest)
411 (save-module-excursion
413 (set-current-module (make-user-module '((guix profiles) (gnu))))
414 (primitive-load manifest))))
417 (map manifest-entry-item
418 (append-map (compose manifest-entries
422 (define (find-current-checkout arguments)
423 "Find the first checkout of ARGUMENTS that provided the current file.
424 Return #f if no such checkout is found."
427 (string-append (dirname (current-filename)) "/.."))))
428 (find (lambda (argument)
429 (and=> (assq-ref argument 'file-name)
431 (string=? name current-root)))) arguments)))
435 ;;; Hydra entry point.
438 (define (hydra-jobs store arguments)
441 (match (assoc-ref arguments 'subset)
442 ("core" 'core) ; only build core packages
443 ("hello" 'hello) ; only build hello
444 (((? string?) (? string?) ...) 'list) ; only build selected list of packages
445 ("manifests" 'manifests) ; only build packages in the list of manifests
446 (_ 'all))) ; build everything
449 (match (assoc-ref arguments 'systems)
450 (#f %hydra-supported-systems)
452 ((? string? str) (call-with-input-string str read))))
455 (or (find-current-checkout arguments)
456 (assq-ref arguments 'superior-guix-checkout)))
459 (assq-ref checkout 'revision))
462 (assq-ref checkout 'file-name))
464 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
465 (parameterize ((%graft? #f))
466 ;; Return one job for each package, except bootstrap packages.
467 (append-map (lambda (system)
468 (format (current-error-port)
469 "evaluating for '~a' (heap size: ~a MiB)...~%"
472 (/ (assoc-ref (gc-stats) 'heap-size)
474 (invalidate-derivation-caches!)
477 ;; Build everything, including replacements.
478 (let ((all (all-packages))
479 (job (lambda (package)
480 (package->job store package
482 (append (filter-map job all)
483 (qemu-jobs store system)
484 (system-test-jobs store system
487 (tarball-jobs store system)
488 (cross-jobs store system))))
490 ;; Build core packages only.
491 (append (map (lambda (package)
492 (package-job store (job-name package)
495 (cross-jobs store system)))
497 ;; Build hello package only.
498 (if (string=? system (%current-system))
499 (let ((hello (specification->package "hello")))
500 (list (package-job store (job-name hello) hello system)))
503 ;; Build selected list of packages only.
504 (if (string=? system (%current-system))
505 (let* ((names (assoc-ref arguments 'subset))
506 (packages (map specification->package names)))
507 (map (lambda (package)
508 (package-job store (job-name package)
513 ;; Build packages in the list of manifests.
514 (let* ((manifests (arguments->manifests arguments))
515 (packages (manifests->packages store manifests)))
516 (map (lambda (package)
517 (package-job store (job-name package)
521 (error "unknown subset" subset))))