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>
6 ;;; Copyright © 2020, 2021 Mathieu Othacehe <othacehe@gnu.org>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
23 (define-module (gnu ci)
24 #:use-module (guix channels)
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)
30 #:use-module (guix channels)
31 #:use-module (guix config)
32 #:use-module (guix derivations)
33 #:use-module (guix build-system)
34 #:use-module (guix monads)
35 #:use-module (guix gexp)
36 #:use-module (guix ui)
37 #:use-module ((guix licenses)
38 #:select (gpl3+ license? license-name))
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)
45 #:use-module (gnu image)
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)
57 #:use-module (gnu system image)
58 #:use-module (gnu system vm)
59 #:use-module (gnu system install)
60 #:use-module (gnu system images hurd)
61 #:use-module (gnu system images novena)
62 #:use-module (gnu system images pine64)
63 #:use-module (gnu system images pinebook-pro)
64 #:use-module (gnu tests)
65 #:use-module (srfi srfi-1)
66 #:use-module (srfi srfi-26)
67 #:use-module (ice-9 match)
68 #:export (%core-packages
70 channel-source->package
75 ;;; This file defines build jobs for Cuirass.
79 (define* (derivation->job name drv
82 (max-silent-time 3600)
84 "Return a Cuirass job called NAME and describing DRV. PERIOD is the minimal
85 duration that must separate two evaluations of the same job. If PERIOD is
86 false, then the job will be evaluated as soon as possible.
88 MAX-SILENT-TIME and TIMEOUT are build options passed to the daemon when
89 building the derivation."
90 `((#:job-name . ,name)
91 (#:derivation . ,(derivation-file-name drv))
92 (#:outputs . ,(filter-map
97 (derivation->output-paths drv)))
98 (#:nix-name . ,(derivation-name drv))
99 (#:system . ,(derivation-system drv))
101 (#:max-silent-time . ,max-silent-time)
102 (#:timeout . ,timeout)))
104 (define* (package-job store job-name package system
106 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
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
112 (package-derivation store package system
114 (max-silent-time (or (assoc-ref (package-properties package)
117 (timeout (or (assoc-ref (package-properties package)
120 (derivation->job job-name drv
121 #:max-silent-time max-silent-time
122 #:timeout timeout)))))
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
127 (let ((name (string-append target "." job-name "." system)))
128 (package-job store name package system
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
136 (list gcc-7 gcc-8 gcc-9 gcc-10 glibc binutils
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))
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)
153 (define %cross-targets
154 '("mips64el-linux-gnu"
155 "arm-linux-gnueabihf"
159 "i586-pc-gnu" ;aka. GNU/Hurd
161 "x86_64-w64-mingw32"))
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.
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
178 (or (string-contains target system)
179 (and (string-prefix? "armhf" system) ;armhf-linux
180 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
182 (define (pointless? target)
183 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
185 ((or "x86_64-linux" "i686-linux")
186 (if (string-contains target "mingw")
187 (not (string=? "x86_64-linux" system))
190 ;; Don't try to cross-compile from non-Intel platforms: this isn't
191 ;; very useful and these are often brittle configurations.
194 (define (either proc1 proc2 proc3)
196 (or (proc1 x) (proc2 x) (proc3 x))))
198 (append-map (lambda (target)
199 (map (lambda (package)
200 (package-cross-job store (job-name package)
201 package target system))
202 (packages-to-cross-build target)))
203 (remove (either from-32-to-64? same? pointless?)
206 (define* (guix-jobs store systems #:key source commit)
207 "Return a list of jobs for Guix itself."
209 (primitive-load (string-append source "/build-aux/build-self.scm")))
213 (let ((name (string->symbol
214 (string-append "guix." system)))
215 (drv (run-with-store store
216 (build source #:version commit #:system system
218 #:guile-version "2.2"))))
219 (derivation->job name drv)))
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"))
228 (define %guix-system-images
229 (list hurd-barebones-qcow2-image
230 pine64-barebones-raw-image
231 pinebook-pro-barebones-raw-image
232 novena-barebones-raw-image))
234 (define (hours hours)
237 (define (image-jobs store system)
238 "Return a list of jobs that build images for SYSTEM. Those jobs are
239 expensive in storage and I/O operations, hence their periodicity is limited by
240 passing the PERIOD argument."
241 (define (->job name drv)
242 (let ((name (string-append name "." system)))
243 (parameterize ((%graft? #f))
244 (derivation->job name drv
245 #:period (hours 48)))))
247 (define (build-image image)
248 (run-with-store store
250 (set-guile-for-build (default-guile))
251 (lower-object (system-image image)))))
256 (if (member system %guix-system-supported-systems)
257 `(,(->job "usb-image"
260 (inherit efi-disk-image)
261 (operating-system installation-os))))
262 ,(->job "iso9660-image"
265 (inherit (image-with-label
267 (string-append "GUIX_" system "_"
268 (if (> (string-length %guix-version) 7)
269 (substring %guix-version 0 7)
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")
275 (->job (symbol->string (image-name image))
276 (build-image image)))
281 (define channel-build-system
282 ;; Build system used to "convert" a channel instance to a package.
283 (let* ((build (lambda* (store name inputs
284 #:key source commit system
286 (run-with-store store
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)
291 (lower-object source)))
293 -> (checkout->channel-instance
294 source #:commit commit)))
295 (channel-instances->derivation (list instance)))
297 (lower (lambda* (name #:key system source commit
303 (arguments `(#:source ,source
304 #:commit ,commit))))))
305 (build-system (name 'channel)
306 (description "Turn a channel instance into a package.")
309 (define* (channel-source->package source #:key commit)
310 "Return a package for the given channel SOURCE, a lowerable object."
313 (version (string-append (package-version guix) "+"))
314 (build-system channel-build-system)
315 (arguments `(#:source ,source
319 (propagated-inputs '())))
321 (define* (system-test-jobs store system
323 "Return a list of jobs for the system tests."
325 (parameterize ((current-guix-package
326 (channel-source->package source #:commit commit)))
327 (let ((name (string-append "test." (system-test-name test)
329 (drv (run-with-store store
331 (set-current-system system)
333 (set-guile-for-build (default-guile))
334 (system-test-value test)))))
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
339 (derivation->job name drv
340 #:period (hours 24)))))
342 (if (member system %guix-system-supported-systems)
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.
347 (map ->job (all-system-tests))
350 (define (tarball-jobs store system)
351 "Return jobs to build the self-contained Guix binary tarball."
352 (define (->job name drv)
353 (let ((name (string-append name "." system)))
354 (parameterize ((%graft? #f))
355 (derivation->job name drv
356 #:period (hours 24)))))
358 ;; XXX: Add a job for the stable Guix?
360 (->job "binary-tarball"
361 (run-with-store store
363 (set-guile-for-build (default-guile))
364 (>>= (profile-derivation (packages->manifest (list guix)))
366 (self-contained-tarball "guix-binary" profile
369 (lookup-compressor "xz")))))
373 ;; Return the name of a package's job.
379 (append-map (match-lambda
381 (match (package-transitive-inputs package)
382 (((_ inputs _ ...) ...)
385 (lambda (store package system)
386 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
388 (cond ((member package base-packages)
389 (package-job store (string-append "base." (job-name package))
391 ((supported-package? package system)
392 (let ((drv (package-derivation store package system
394 (and (substitutable-derivation? drv)
395 (package-job store (job-name package)
400 (define (all-packages)
401 "Return the list of packages to build."
402 (define (adjust package result)
403 (cond ((package-replacement package)
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
411 ((package-superseded package)
412 result) ;don't build it
414 (cons package result))))
416 (fold-packages adjust
417 (fold adjust '() ;include base packages
418 (match (%final-inputs)
419 (((labels packages _ ...) ...)
421 #:select? (const #t))) ;include hidden packages
423 (define (arguments->manifests arguments channels)
424 "Return the list of manifests extracted from ARGUMENTS."
425 (define (channel-name->checkout name)
426 (let ((channel (find (lambda (channel)
427 (eq? (channel-name channel) name))
429 (channel-url channel)))
433 (let ((checkout (channel-name->checkout name)))
434 (in-vicinity checkout path))))
437 (define (manifests->packages store manifests)
438 "Return the list of packages found in MANIFESTS."
439 (define (load-manifest manifest)
440 (save-module-excursion
442 (set-current-module (make-user-module '((guix profiles) (gnu))))
443 (primitive-load manifest))))
446 (map manifest-entry-item
447 (append-map (compose manifest-entries
453 ;;; Cuirass entry point.
456 (define (cuirass-jobs store arguments)
457 "Register Cuirass jobs."
459 (assoc-ref arguments 'subset))
462 (match (assoc-ref arguments 'systems)
463 (#f %cuirass-supported-systems)
465 ((? string? str) (call-with-input-string str read))))
468 (let ((channels (assq-ref arguments 'channels)))
469 (map sexp->channel channels)))
472 (find guix-channel? channels))
475 (channel-commit guix))
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.
485 (format (current-error-port)
486 "evaluating for '~a' (heap size: ~a MiB)...~%"
489 (/ (assoc-ref (gc-stats) 'heap-size)
491 (invalidate-derivation-caches!)
494 ;; Build everything, including replacements.
495 (let ((all (all-packages))
496 (job (lambda (package)
497 (package->job store package system))))
500 (image-jobs store system)
501 (system-test-jobs store system
504 (tarball-jobs store system)
505 (cross-jobs store system))))
507 ;; Build core packages only.
509 (map (lambda (package)
510 (package-job store (job-name package)
513 (cross-jobs store system)))
515 ;; Build Guix modules only.
516 (guix-jobs store systems
520 ;; Build hello package only.
521 (let ((hello (specification->package "hello")))
522 (list (package-job store (job-name hello)
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)
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)
540 (error "unknown subset" subset))))