gnu-system.scm 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. ;;;; gnu-system.scm - build jobs for Guix
  2. ;;;
  3. ;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
  5. ;;;
  6. ;;; This file is part of Cuirass.
  7. ;;;
  8. ;;; Cuirass 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.
  12. ;;;
  13. ;;; Cuirass 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.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
  20. ;; Attempt to use Guix modules from git repository.
  21. (eval-when (compile load eval)
  22. ;; Ignore any available .go, and force recompilation. This is because our
  23. ;; checkout in the store has mtime set to the epoch, and thus .go files look
  24. ;; newer, even though they may not correspond.
  25. (set! %fresh-auto-compile #t))
  26. (use-modules (guix config)
  27. (guix store)
  28. (guix grafts)
  29. (guix packages)
  30. (guix derivations)
  31. (guix monads)
  32. ((guix licenses)
  33. #:select (gpl3+ license-name license-uri license-comment))
  34. ((guix utils) #:select (%current-system))
  35. ((guix scripts system) #:select (read-operating-system))
  36. (gnu packages)
  37. (gnu packages commencement)
  38. (gnu packages guile)
  39. (gnu packages make-bootstrap)
  40. (gnu system)
  41. (gnu system vm)
  42. (gnu system install)
  43. (srfi srfi-1)
  44. (ice-9 match))
  45. (define (license->alist lcs)
  46. "Return LCS <license> object as an alist."
  47. ;; Sometimes 'license' field is a list of licenses.
  48. (if (list? lcs)
  49. (map license->alist lcs)
  50. `((name . ,(license-name lcs))
  51. (uri . ,(license-uri lcs))
  52. (comment . ,(license-comment lcs)))))
  53. (define (package-metadata package)
  54. "Convert PACKAGE to an alist suitable for Hydra."
  55. `((#:description . ,(package-synopsis package))
  56. (#:long-description . ,(package-description package))
  57. (#:license . ,(license->alist (package-license package)))
  58. (#:home-page . ,(package-home-page package))
  59. (#:maintainers . ("bug-guix@gnu.org"))
  60. (#:max-silent-time . ,(or (assoc-ref (package-properties package)
  61. 'max-silent-time)
  62. 3600)) ;1 hour by default
  63. (#:timeout . ,(or (assoc-ref (package-properties package) 'timeout)
  64. 72000)))) ;20 hours by default
  65. (define (package-job store job-name package system)
  66. "Return a job called JOB-NAME that builds PACKAGE on SYSTEM."
  67. (λ ()
  68. `((#:job-name . ,(string-append (symbol->string job-name) "." system))
  69. (#:derivation . ,(derivation-file-name
  70. (parameterize ((%graft? #f))
  71. (package-derivation store package system
  72. #:graft? #f))))
  73. ,@(package-metadata package))))
  74. (define (package-cross-job store job-name package target system)
  75. "Return a job called TARGET.JOB-NAME that cross-builds PACKAGE
  76. for TARGET on SYSTEM."
  77. (λ ()
  78. `((#:job-name . ,(string-join (list target (symbol->string job-name) system)
  79. "."))
  80. (#:derivation . ,(derivation-file-name
  81. (parameterize ((%graft? #f))
  82. (package-cross-derivation store package target system
  83. #:graft? #f))))
  84. ,@(package-metadata package))))
  85. (define %core-packages
  86. ;; Note: Don't put the '-final' package variants because (1) that's
  87. ;; implicit, and (2) they cannot be cross-built (due to the explicit input
  88. ;; chain.)
  89. (append (map specification->package
  90. '("gcc@4.8" "gcc@4.9" "gcc@5" "glibc" "binutils"
  91. "gmp" "mpfr" "mpc" "coreutils" "findutils" "diffutils" "patch" "sed" "grep"
  92. "gawk" "gettext" "hello" "zlib" "gzip" "xz"))
  93. (list guile-2.0
  94. %bootstrap-binaries-tarball
  95. %binutils-bootstrap-tarball
  96. %glibc-bootstrap-tarball
  97. %gcc-bootstrap-tarball
  98. %guile-bootstrap-tarball
  99. %bootstrap-tarballs)))
  100. (define %packages-to-cross-build
  101. %core-packages)
  102. (define %cross-targets
  103. '("mips64el-linux-gnu"
  104. "mips64el-linux-gnuabi64"))
  105. (define (tarball-job store system)
  106. "Return Hydra jobs to build the self-contained Guix binary tarball."
  107. (λ ()
  108. `((#:job-name . (string-append "binary-tarball." system))
  109. (#:derivation . ,(derivation-file-name
  110. (parameterize ((%graft? #f))
  111. (run-with-store store
  112. (mbegin %store-monad
  113. (set-guile-for-build (default-guile))
  114. (self-contained-tarball))
  115. #:system system))))
  116. (#:description . "Stand-alone binary Guix tarball")
  117. (#:long-description . "This is a tarball containing binaries of Guix
  118. and all its dependencies, and ready to be installed on non-GuixSD
  119. distributions.")
  120. (#:license . ,(license->alist gpl3+))
  121. (#:home-page . ,%guix-home-page-url)
  122. (#:maintainers . ("bug-guix@gnu.org")))))
  123. (define %job-name
  124. ;; Return the name of a package's job.
  125. (compose string->symbol package-full-name))
  126. (define package->job
  127. (let ((base-packages
  128. (delete-duplicates
  129. (append-map (match-lambda
  130. ((_ package _ ...)
  131. (match (package-transitive-inputs package)
  132. (((_ inputs _ ...) ...)
  133. inputs))))
  134. %final-inputs))))
  135. (lambda (store package system)
  136. "Return a job for PACKAGE on SYSTEM, or #f if this combination is not
  137. valid."
  138. (cond ((member package base-packages)
  139. #f)
  140. ((supported-package? package system)
  141. (package-job store (%job-name package) package system))
  142. (else
  143. #f)))))
  144. ;;;
  145. ;;; Hydra entry point.
  146. ;;;
  147. (define (hydra-jobs store arguments)
  148. "Return Hydra jobs."
  149. (define subset
  150. (match (assoc-ref arguments 'subset)
  151. ("core" 'core) ; only build core packages
  152. ("hello" 'hello) ; only build hello
  153. (_ 'all))) ; build everything
  154. (define (cross-jobs system)
  155. (define (from-32-to-64? target)
  156. ;; Return true if SYSTEM is 32-bit and TARGET is 64-bit. This hack
  157. ;; prevents known-to-fail cross-builds from i686-linux or armhf-linux to
  158. ;; mips64el-linux-gnuabi64.
  159. (and (or (string-prefix? "i686-" system)
  160. (string-prefix? "armhf-" system))
  161. (string-suffix? "64" target)))
  162. (define (same? target)
  163. ;; Return true if SYSTEM and TARGET are the same thing. This is so we
  164. ;; don't try to cross-compile to 'mips64el-linux-gnu' from
  165. ;; 'mips64el-linux'.
  166. (string-contains target system))
  167. (define (either proc1 proc2)
  168. (lambda (x)
  169. (or (proc1 x) (proc2 x))))
  170. (append-map (lambda (target)
  171. (map (lambda (package)
  172. (package-cross-job store (%job-name package)
  173. package target system))
  174. %packages-to-cross-build))
  175. (remove (either from-32-to-64? same?) %cross-targets)))
  176. ;; Turn off grafts. Grafting is meant to happen on the user's machines.
  177. (parameterize ((%graft? #f))
  178. ;; Return one job for each package, except bootstrap packages.
  179. (append-map (lambda (system)
  180. (case subset
  181. ((all)
  182. ;; Build everything, including replacements.
  183. (let ((pkgs (fold-packages
  184. (lambda (package result)
  185. (if (package-replacement package)
  186. (cons* package
  187. (package-replacement package)
  188. result)
  189. (cons package result)))
  190. '())))
  191. (append (filter-map (lambda (pkg)
  192. (package->job store pkg system))
  193. pkgs)
  194. (list (tarball-job store system))
  195. (cross-jobs system))))
  196. ((core)
  197. ;; Build core packages only.
  198. (append (map (lambda (package)
  199. (package-job store (%job-name package)
  200. package system))
  201. %core-packages)
  202. (cross-jobs system)))
  203. ((hello)
  204. ;; Build hello package only.
  205. (if (string=? system (%current-system))
  206. (let ((hello (specification->package "hello")))
  207. (list (package-job store (%job-name hello) hello system)))
  208. '()))
  209. (else
  210. (error "unknown subset" subset))))
  211. %hydra-supported-systems)))