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 describe)
27 #:use-module (guix store)
28 #:use-module (guix grafts)
29 #:use-module (guix profiles)
30 #:use-module (guix packages)
31 #:use-module (guix channels)
32 #:use-module (guix config)
33 #:use-module (guix derivations)
34 #:use-module (guix build-system)
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 system) #:select (read-operating-system))
42 #:use-module ((guix scripts pack)
43 #:select (lookup-compressor self-contained-tarball))
44 #:use-module (gnu bootloader)
45 #:use-module (gnu bootloader u-boot)
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 (gnu system)
58 #:use-module (gnu system image)
59 #:use-module (gnu system vm)
60 #:use-module (gnu system install)
61 #:use-module (gnu system images hurd)
62 #:use-module (gnu system images novena)
63 #:use-module (gnu system images pine64)
64 #:use-module (gnu system images pinebook-pro)
65 #:use-module (gnu tests)
66 #:use-module (srfi srfi-1)
67 #:use-module (srfi srfi-26)
68 #:use-module (ice-9 match)
69 #:export (%core-packages
71 channel-source->package
76 ;;; This file defines build jobs for Cuirass.
80 (define* (derivation->job name drv
83 (max-silent-time 3600)
85 "Return a Cuirass job called NAME and describing DRV. PERIOD is the minimal
86 duration that must separate two evaluations of the same job. If PERIOD is
87 false, then the job will be evaluated as soon as possible.
89 MAX-SILENT-TIME and TIMEOUT are build options passed to the daemon when
90 building the derivation."
91 `((#:job-name . ,name)
92 (#:derivation . ,(derivation-file-name drv))
93 (#:outputs . ,(filter-map
98 (derivation->output-paths drv)))
99 (#:nix-name . ,(derivation-name drv))
100 (#:system . ,(derivation-system drv))
102 (#:max-silent-time . ,max-silent-time)
103 (#:timeout . ,timeout)))
105 (define* (package-job store job-name package system
107 "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
108 (let ((job-name (string-append job-name "." system)))
109 (parameterize ((%graft? #f))
110 (let* ((drv (if cross?
111 (package-cross-derivation store package target system
113 (package-derivation store package system
115 (max-silent-time (or (assoc-ref (package-properties package)
118 (timeout (or (assoc-ref (package-properties package)
121 (derivation->job job-name drv
122 #:max-silent-time max-silent-time
123 #:timeout timeout)))))
125 (define (package-cross-job store job-name package target system)
126 "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE for TARGET on
128 (let ((name (string-append target "." job-name "." system)))
129 (package-job store name package system
133 (define %core-packages
134 ;; Note: Don't put the '-final' package variants because (1) that's
135 ;; implicit, and (2) they cannot be cross-built (due to the explicit input
137 (list gcc-7 gcc-8 gcc-9 gcc-10 glibc binutils
138 gmp mpfr mpc coreutils findutils diffutils patch sed grep
139 gawk gnu-gettext hello guile-2.0 guile-2.2 zlib gzip xz
140 %bootstrap-binaries-tarball
141 %binutils-bootstrap-tarball
142 (%glibc-bootstrap-tarball)
143 %gcc-bootstrap-tarball
144 %guile-bootstrap-tarball
145 %bootstrap-tarballs))
147 (define (packages-to-cross-build target)
148 "Return the list of packages to cross-build for TARGET."
149 ;; Don't cross-build the bootstrap tarballs for MinGW.
150 (if (string-contains target "mingw")
151 (drop-right %core-packages 6)
154 (define %cross-targets
155 '("mips64el-linux-gnu"
156 "arm-linux-gnueabihf"
159 "powerpc64le-linux-gnu"
161 "i586-pc-gnu" ;aka. GNU/Hurd
163 "x86_64-w64-mingw32"))
165 (define (cross-jobs store system)
166 "Return a list of cross-compilation jobs for SYSTEM."
167 (define (from-32-to-64? target)
168 ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
169 ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
170 ;; mips64el-linux-gnuabi64.
171 (and (or (string-prefix? "i686-" system)
172 (string-prefix? "i586-" system)
173 (string-prefix? "armhf-" system))
174 (string-contains target "64"))) ;x86_64, mips64el, aarch64, etc.
176 (define (same? target)
177 ;; Return true if SYSTEM and TARGET are the same thing. This is so we
178 ;; don't try to cross-compile to 'mips64el-linux-gnu' from
180 (or (string-contains target system)
181 (and (string-prefix? "armhf" system) ;armhf-linux
182 (string-prefix? "arm" target)))) ;arm-linux-gnueabihf
184 (define (pointless? target)
185 ;; Return #t if it makes no sense to cross-build to TARGET from SYSTEM.
187 ((or "x86_64-linux" "i686-linux")
188 (if (string-contains target "mingw")
189 (not (string=? "x86_64-linux" system))
192 ;; Don't try to cross-compile from non-Intel platforms: this isn't
193 ;; very useful and these are often brittle configurations.
196 (define (either proc1 proc2 proc3)
198 (or (proc1 x) (proc2 x) (proc3 x))))
200 (append-map (lambda (target)
201 (map (lambda (package)
202 (package-cross-job store (job-name package)
203 package target system))
204 (packages-to-cross-build target)))
205 (remove (either from-32-to-64? same? pointless?)
208 (define* (guix-jobs store systems #:key source commit)
209 "Return a list of jobs for Guix itself."
211 (primitive-load (string-append source "/build-aux/build-self.scm")))
215 (let ((name (string->symbol
216 (string-append "guix." system)))
217 (drv (run-with-store store
218 (build source #:version commit #:system system
220 #:guile-version "2.2"))))
221 (derivation->job name drv)))
224 ;; Architectures that are able to build or cross-build Guix System images.
225 ;; This does not mean that other architectures are not supported, only that
226 ;; they are often not fast enough to support Guix System images building.
227 (define %guix-system-supported-systems
228 '("x86_64-linux" "i686-linux"))
230 (define %guix-system-images
231 (list hurd-barebones-qcow2-image
232 pine64-barebones-raw-image
233 pinebook-pro-barebones-raw-image
234 novena-barebones-raw-image))
236 (define (hours hours)
239 (define (image-jobs store system)
240 "Return a list of jobs that build images for SYSTEM. Those jobs are
241 expensive in storage and I/O operations, hence their periodicity is limited by
242 passing the PERIOD argument."
243 (define (->job name drv)
244 (let ((name (string-append name "." system)))
245 (parameterize ((%graft? #f))
246 (derivation->job name drv
247 #:period (hours 48)))))
249 (define (build-image image)
250 (run-with-store store
252 (set-guile-for-build (default-guile))
253 (lower-object (system-image image)))))
258 (if (member system %guix-system-supported-systems)
259 `(,(->job "usb-image"
262 (inherit efi-disk-image)
263 (operating-system installation-os))))
264 ,(->job "iso9660-image"
267 (inherit (image-with-label
269 (string-append "GUIX_" system "_"
270 (if (> (string-length %guix-version) 7)
271 (substring %guix-version 0 7)
273 (operating-system installation-os))))
274 ;; Only cross-compile Guix System images from x86_64-linux for now.
275 ,@(if (string=? system "x86_64-linux")
277 (->job (symbol->string (image-name image))
278 (build-image image)))
283 (define channel-build-system
284 ;; Build system used to "convert" a channel instance to a package.
285 (let* ((build (lambda* (store name inputs
286 #:key source commit system
288 (run-with-store store
289 ;; SOURCE can be a lowerable object such as <local-file>
290 ;; or a file name. Adjust accordingly.
291 (mlet* %store-monad ((source (if (string? source)
293 (lower-object source)))
295 -> (checkout->channel-instance
296 source #:commit commit)))
297 (channel-instances->derivation (list instance)))
299 (lower (lambda* (name #:key system source commit
305 (arguments `(#:source ,source
306 #:commit ,commit))))))
307 (build-system (name 'channel)
308 (description "Turn a channel instance into a package.")
311 (define* (channel-source->package source #:key commit)
312 "Return a package for the given channel SOURCE, a lowerable object."
315 (version (string-append (package-version guix) "+"))
316 (build-system channel-build-system)
317 (arguments `(#:source ,source
321 (propagated-inputs '())))
323 (define* (system-test-jobs store system
325 "Return a list of jobs for the system tests."
327 (parameterize ((current-guix-package
328 (channel-source->package source #:commit commit)))
329 (let ((name (string-append "test." (system-test-name test)
331 (drv (run-with-store store
333 (set-current-system system)
335 (set-guile-for-build (default-guile))
336 (system-test-value test)))))
338 ;; Those tests are extremely expensive in I/O operations and storage
339 ;; size, use the "period" attribute to run them with a period of at
341 (derivation->job name drv
342 #:period (hours 24)))))
344 (if (member system %guix-system-supported-systems)
345 ;; Override the value of 'current-guix' used by system tests. Using a
346 ;; channel instance makes tests that rely on 'current-guix' less
347 ;; expensive. It also makes sure we get a valid Guix package when this
348 ;; code is not running from a checkout.
349 (map ->job (all-system-tests))
352 (define (tarball-jobs store system)
353 "Return jobs to build the self-contained Guix binary tarball."
354 (define (->job name drv)
355 (let ((name (string-append name "." system)))
356 (parameterize ((%graft? #f))
357 (derivation->job name drv
358 #:period (hours 24)))))
360 ;; XXX: Add a job for the stable Guix?
362 (->job "binary-tarball"
363 (run-with-store store
365 (set-guile-for-build (default-guile))
366 (>>= (profile-derivation (packages->manifest (list guix)))
368 (self-contained-tarball "guix-binary" profile
371 (lookup-compressor "xz")))))
375 ;; Return the name of a package's job.
381 (append-map (match-lambda
383 (match (package-transitive-inputs package)
384 (((_ inputs _ ...) ...)
387 (lambda (store package system)
388 "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
390 (cond ((member package base-packages)
391 (package-job store (string-append "base." (job-name package))
393 ((supported-package? package system)
394 (let ((drv (package-derivation store package system
396 (and (substitutable-derivation? drv)
397 (package-job store (job-name package)
402 (define (all-packages)
403 "Return the list of packages to build."
404 (define (adjust package result)
405 (cond ((package-replacement package)
406 ;; XXX: If PACKAGE and its replacement have the same name/version,
407 ;; then both Cuirass jobs will have the same name, which
408 ;; effectively means that the second one will be ignored. Thus,
409 ;; return the replacement first.
410 (cons* (package-replacement package) ;build both
413 ((package-superseded package)
414 result) ;don't build it
416 (cons package result))))
418 (fold-packages adjust
419 (fold adjust '() ;include base packages
420 (match (%final-inputs)
421 (((labels packages _ ...) ...)
423 #:select? (const #t))) ;include hidden packages
425 (define (arguments->manifests arguments channels)
426 "Return the list of manifests extracted from ARGUMENTS."
427 (map (lambda (manifest)
428 (any (lambda (checkout)
429 (let ((path (in-vicinity checkout manifest)))
430 (and (file-exists? path)
432 (map channel-url channels)))
435 (define (manifests->packages store manifests)
436 "Return the list of packages found in MANIFESTS."
437 (define (load-manifest manifest)
438 (save-module-excursion
440 (set-current-module (make-user-module '((guix profiles) (gnu))))
441 (primitive-load manifest))))
444 (map manifest-entry-item
445 (append-map (compose manifest-entries
451 ;;; Cuirass entry point.
454 (define (cuirass-jobs store arguments)
455 "Register Cuirass jobs."
457 (assoc-ref arguments 'subset))
460 (match (assoc-ref arguments 'systems)
461 (#f %cuirass-supported-systems)
463 ((? string? str) (call-with-input-string str read))))
466 (let ((channels (assq-ref arguments 'channels)))
467 (map sexp->channel channels)))
470 (find guix-channel? channels))
473 (channel-commit guix))
478 ;; Turn off grafts. Grafting is meant to happen on the user's machines.
479 (parameterize ((%graft? #f))
480 ;; Return one job for each package, except bootstrap packages.
483 (format (current-error-port)
484 "evaluating for '~a' (heap size: ~a MiB)...~%"
487 (/ (assoc-ref (gc-stats) 'heap-size)
489 (invalidate-derivation-caches!)
492 ;; Build everything, including replacements.
493 (let ((all (all-packages))
494 (job (lambda (package)
495 (package->job store package system))))
498 (image-jobs store system)
499 (system-test-jobs store system
502 (tarball-jobs store system)
503 (cross-jobs store system))))
505 ;; Build core packages only.
507 (map (lambda (package)
508 (package-job store (job-name package)
511 (cross-jobs store system)))
513 ;; Build Guix modules only.
514 (guix-jobs store systems
518 ;; Build hello package only.
519 (let ((hello (specification->package "hello")))
520 (list (package-job store (job-name hello)
522 (('channels . channels)
523 ;; Build only the packages from CHANNELS.
524 (let ((all (all-packages)))
527 (any (lambda (channel)
528 (and (member (channel-name channel) channels)
529 (package->job store package system)))
530 (package-channels package)))
533 ;; Build selected list of packages only.
534 (let ((packages (map specification->package rest)))
535 (map (lambda (package)
536 (package-job store (job-name package)
540 ;; Build packages in the list of manifests.
541 (let* ((manifests (arguments->manifests rest channels))
542 (packages (manifests->packages store manifests)))
543 (map (lambda (package)
544 (package-job store (job-name package)
548 (error "unknown subset" subset))))