Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

743 lines
30 KiB

build-system: Introduce "bags" as an intermediate representation. * guix/build-system.scm (<build-system>)[build, cross-build]: Remove. [lower]: New field. (<bag>): New record type. (make-bag): New procedure. * guix/packages.scm (bag-transitive-inputs, bag-transitive-build-inputs, bag-transitive-host-inputs, bag-transitive-target-inputs, package->bag): New procedures. (package-derivation): Use it; use the bag, apply its build procedure, etc. (package-cross-derivation): Likewise. * gnu/packages/bootstrap.scm (raw-build, make-raw-bag): New procedure. (%bootstrap-guile): Use them. * guix/build-system/trivial.scm (lower): New procedure. (trivial-build, trivial-cross-build): Remove 'source' parameter. Pass INPUTS as is. (trivial-build-system): Adjust accordingly. * guix/build-system/gnu.scm (%store, inputs-search-paths, standard-search-paths, expand-inputs, standard-inputs): Remove. (gnu-lower): New procedure. (gnu-build): Remove 'source' and #:implicit-inputs? parameters. Remove 'implicit-inputs' and 'implicit-search-paths' variables. Get the source from INPUT-DRVS. (gnu-cross-build): Likewise. (standard-cross-packages): Remove call to 'standard-packages'. (standard-cross-inputs, standard-cross-search-paths): Remove. (gnu-build-system): Remove 'build' and 'cross-build'; add 'lower'. * guix/build-system/cmake.scm (lower): New procedure. (cmake-build): Remove 'source' and #:cmake parameters. Use INPUTS and SEARCH-PATHS as is. Get the source from INPUTS. * guix/build-system/perl.scm: Likewise. * guix/build-system/python.scm: Likewise. * guix/build-system/ruby.scm: Likewise. * gnu/packages/cross-base.scm (cross-gcc): Change "cross-linux-headers" to "linux-headers". (cross-libc)[xlinux-headers]: Pass #:implicit-cross-inputs? #f. Likewise. In 'propagated-inputs', change "cross-linux-headers" to "linux-headers". * guix/git-download.scm (git-fetch): Use 'standard-packages' instead of 'standard-inputs'. * tests/builders.scm ("gnu-build-system"): Remove use of 'build-system-builder'. ("gnu-build"): Remove 'source' and #:implicit-inputs? arguments to 'gnu-build'. * tests/packages.scm ("search paths"): Adjust to new build system API. ("package-cross-derivation, no cross builder"): Likewise. * doc/guix.texi (Build Systems): Add paragraph on bags.
7 years ago
build-system: Introduce "bags" as an intermediate representation. * guix/build-system.scm (<build-system>)[build, cross-build]: Remove. [lower]: New field. (<bag>): New record type. (make-bag): New procedure. * guix/packages.scm (bag-transitive-inputs, bag-transitive-build-inputs, bag-transitive-host-inputs, bag-transitive-target-inputs, package->bag): New procedures. (package-derivation): Use it; use the bag, apply its build procedure, etc. (package-cross-derivation): Likewise. * gnu/packages/bootstrap.scm (raw-build, make-raw-bag): New procedure. (%bootstrap-guile): Use them. * guix/build-system/trivial.scm (lower): New procedure. (trivial-build, trivial-cross-build): Remove 'source' parameter. Pass INPUTS as is. (trivial-build-system): Adjust accordingly. * guix/build-system/gnu.scm (%store, inputs-search-paths, standard-search-paths, expand-inputs, standard-inputs): Remove. (gnu-lower): New procedure. (gnu-build): Remove 'source' and #:implicit-inputs? parameters. Remove 'implicit-inputs' and 'implicit-search-paths' variables. Get the source from INPUT-DRVS. (gnu-cross-build): Likewise. (standard-cross-packages): Remove call to 'standard-packages'. (standard-cross-inputs, standard-cross-search-paths): Remove. (gnu-build-system): Remove 'build' and 'cross-build'; add 'lower'. * guix/build-system/cmake.scm (lower): New procedure. (cmake-build): Remove 'source' and #:cmake parameters. Use INPUTS and SEARCH-PATHS as is. Get the source from INPUTS. * guix/build-system/perl.scm: Likewise. * guix/build-system/python.scm: Likewise. * guix/build-system/ruby.scm: Likewise. * gnu/packages/cross-base.scm (cross-gcc): Change "cross-linux-headers" to "linux-headers". (cross-libc)[xlinux-headers]: Pass #:implicit-cross-inputs? #f. Likewise. In 'propagated-inputs', change "cross-linux-headers" to "linux-headers". * guix/git-download.scm (git-fetch): Use 'standard-packages' instead of 'standard-inputs'. * tests/builders.scm ("gnu-build-system"): Remove use of 'build-system-builder'. ("gnu-build"): Remove 'source' and #:implicit-inputs? arguments to 'gnu-build'. * tests/packages.scm ("search paths"): Adjust to new build system API. ("package-cross-derivation, no cross builder"): Likewise. * doc/guix.texi (Build Systems): Add paragraph on bags.
7 years ago
gnu: Split (gnu packages base), adding (gnu packages commencement). * gnu/packages/base.scm (gnu-make-boot0, diffutils-boot0, findutils-boot0, %boot0-inputs, nix-system->gnu-triplet, boot-triplet, binutils-boot0, gcc-boot0, perl-boot0, linux-libre-headers-boot0, texinfo-boot0, %boot1-inputs, glibc-final-with-bootstrap-bash, cross-gcc-wrapper, static-bash-for-glibc, glibc-final, gcc-boot0-wrapped, %boot2-inputs, binutils-final, libstdc++, gcc-final, ld-wrapper-boot3, %boot3-inputs, bash-final, %boot4-inputs, guile-final, gnu-make-final, ld-wrapper, coreutils-final, grep-final, %boot5-inputs, %final-inputs, canonical-package, gcc-toolchain, gcc-toolchain-4.8, gcc-toolchain-4.9): Move to... * gnu/packages/commencement.scm: ... here. New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. * build-aux/check-final-inputs-self-contained.scm: Adjust accordingly. * gnu/packages/cross-base.scm: Likewise. * gnu/packages/make-bootstrap.scm: Likewise. * guix/build-system/cmake.scm (cmake-build): Likewise. * guix/build-system/gnu.scm (standard-packages, gnu-build, gnu-cross-build): Likewise. * guix/build-system/perl.scm (perl-build): Likewise. * guix/build-system/python.scm (python-build): Likewise. * guix/build-system/trivial.scm (guile-for-build): Likewise. * guix/download.scm (url-fetch): Likewise. * guix/gexp.scm (default-guile): Likewise. * guix/git-download.scm (git-fetch): Likewise. * guix/monads.scm (run-with-store): Likewise. * guix/packages.scm (default-guile): Likewise. * guix/scripts/package.scm (guix-package): Likewise. * guix/scripts/refresh.scm: Likewise. * guix/svn-download.scm (svn-fetch): Likewise. * tests/builders.scm (%bootstrap-inputs, %bootstrap-search-paths): Likewise. * tests/packages.scm ("GNU Make, bootstrap"): Likewise. * tests/guix-package.sh: Likewise. * gnu/services/base.scm: Use 'canonical-package' instead of xxx-final. * gnu/services/xorg.scm: Likewise. * gnu/system/vm.scm: Likewise. * guix/scripts/pull.scm (guix-pull): Likewise.
8 years ago
build-system: Introduce "bags" as an intermediate representation. * guix/build-system.scm (<build-system>)[build, cross-build]: Remove. [lower]: New field. (<bag>): New record type. (make-bag): New procedure. * guix/packages.scm (bag-transitive-inputs, bag-transitive-build-inputs, bag-transitive-host-inputs, bag-transitive-target-inputs, package->bag): New procedures. (package-derivation): Use it; use the bag, apply its build procedure, etc. (package-cross-derivation): Likewise. * gnu/packages/bootstrap.scm (raw-build, make-raw-bag): New procedure. (%bootstrap-guile): Use them. * guix/build-system/trivial.scm (lower): New procedure. (trivial-build, trivial-cross-build): Remove 'source' parameter. Pass INPUTS as is. (trivial-build-system): Adjust accordingly. * guix/build-system/gnu.scm (%store, inputs-search-paths, standard-search-paths, expand-inputs, standard-inputs): Remove. (gnu-lower): New procedure. (gnu-build): Remove 'source' and #:implicit-inputs? parameters. Remove 'implicit-inputs' and 'implicit-search-paths' variables. Get the source from INPUT-DRVS. (gnu-cross-build): Likewise. (standard-cross-packages): Remove call to 'standard-packages'. (standard-cross-inputs, standard-cross-search-paths): Remove. (gnu-build-system): Remove 'build' and 'cross-build'; add 'lower'. * guix/build-system/cmake.scm (lower): New procedure. (cmake-build): Remove 'source' and #:cmake parameters. Use INPUTS and SEARCH-PATHS as is. Get the source from INPUTS. * guix/build-system/perl.scm: Likewise. * guix/build-system/python.scm: Likewise. * guix/build-system/ruby.scm: Likewise. * gnu/packages/cross-base.scm (cross-gcc): Change "cross-linux-headers" to "linux-headers". (cross-libc)[xlinux-headers]: Pass #:implicit-cross-inputs? #f. Likewise. In 'propagated-inputs', change "cross-linux-headers" to "linux-headers". * guix/git-download.scm (git-fetch): Use 'standard-packages' instead of 'standard-inputs'. * tests/builders.scm ("gnu-build-system"): Remove use of 'build-system-builder'. ("gnu-build"): Remove 'source' and #:implicit-inputs? arguments to 'gnu-build'. * tests/packages.scm ("search paths"): Adjust to new build system API. ("package-cross-derivation, no cross builder"): Likewise. * doc/guix.texi (Build Systems): Add paragraph on bags.
7 years ago
build-system: Introduce "bags" as an intermediate representation. * guix/build-system.scm (<build-system>)[build, cross-build]: Remove. [lower]: New field. (<bag>): New record type. (make-bag): New procedure. * guix/packages.scm (bag-transitive-inputs, bag-transitive-build-inputs, bag-transitive-host-inputs, bag-transitive-target-inputs, package->bag): New procedures. (package-derivation): Use it; use the bag, apply its build procedure, etc. (package-cross-derivation): Likewise. * gnu/packages/bootstrap.scm (raw-build, make-raw-bag): New procedure. (%bootstrap-guile): Use them. * guix/build-system/trivial.scm (lower): New procedure. (trivial-build, trivial-cross-build): Remove 'source' parameter. Pass INPUTS as is. (trivial-build-system): Adjust accordingly. * guix/build-system/gnu.scm (%store, inputs-search-paths, standard-search-paths, expand-inputs, standard-inputs): Remove. (gnu-lower): New procedure. (gnu-build): Remove 'source' and #:implicit-inputs? parameters. Remove 'implicit-inputs' and 'implicit-search-paths' variables. Get the source from INPUT-DRVS. (gnu-cross-build): Likewise. (standard-cross-packages): Remove call to 'standard-packages'. (standard-cross-inputs, standard-cross-search-paths): Remove. (gnu-build-system): Remove 'build' and 'cross-build'; add 'lower'. * guix/build-system/cmake.scm (lower): New procedure. (cmake-build): Remove 'source' and #:cmake parameters. Use INPUTS and SEARCH-PATHS as is. Get the source from INPUTS. * guix/build-system/perl.scm: Likewise. * guix/build-system/python.scm: Likewise. * guix/build-system/ruby.scm: Likewise. * gnu/packages/cross-base.scm (cross-gcc): Change "cross-linux-headers" to "linux-headers". (cross-libc)[xlinux-headers]: Pass #:implicit-cross-inputs? #f. Likewise. In 'propagated-inputs', change "cross-linux-headers" to "linux-headers". * guix/git-download.scm (git-fetch): Use 'standard-packages' instead of 'standard-inputs'. * tests/builders.scm ("gnu-build-system"): Remove use of 'build-system-builder'. ("gnu-build"): Remove 'source' and #:implicit-inputs? arguments to 'gnu-build'. * tests/packages.scm ("search paths"): Adjust to new build system API. ("package-cross-derivation, no cross builder"): Likewise. * doc/guix.texi (Build Systems): Add paragraph on bags.
7 years ago
build-system: Introduce "bags" as an intermediate representation. * guix/build-system.scm (<build-system>)[build, cross-build]: Remove. [lower]: New field. (<bag>): New record type. (make-bag): New procedure. * guix/packages.scm (bag-transitive-inputs, bag-transitive-build-inputs, bag-transitive-host-inputs, bag-transitive-target-inputs, package->bag): New procedures. (package-derivation): Use it; use the bag, apply its build procedure, etc. (package-cross-derivation): Likewise. * gnu/packages/bootstrap.scm (raw-build, make-raw-bag): New procedure. (%bootstrap-guile): Use them. * guix/build-system/trivial.scm (lower): New procedure. (trivial-build, trivial-cross-build): Remove 'source' parameter. Pass INPUTS as is. (trivial-build-system): Adjust accordingly. * guix/build-system/gnu.scm (%store, inputs-search-paths, standard-search-paths, expand-inputs, standard-inputs): Remove. (gnu-lower): New procedure. (gnu-build): Remove 'source' and #:implicit-inputs? parameters. Remove 'implicit-inputs' and 'implicit-search-paths' variables. Get the source from INPUT-DRVS. (gnu-cross-build): Likewise. (standard-cross-packages): Remove call to 'standard-packages'. (standard-cross-inputs, standard-cross-search-paths): Remove. (gnu-build-system): Remove 'build' and 'cross-build'; add 'lower'. * guix/build-system/cmake.scm (lower): New procedure. (cmake-build): Remove 'source' and #:cmake parameters. Use INPUTS and SEARCH-PATHS as is. Get the source from INPUTS. * guix/build-system/perl.scm: Likewise. * guix/build-system/python.scm: Likewise. * guix/build-system/ruby.scm: Likewise. * gnu/packages/cross-base.scm (cross-gcc): Change "cross-linux-headers" to "linux-headers". (cross-libc)[xlinux-headers]: Pass #:implicit-cross-inputs? #f. Likewise. In 'propagated-inputs', change "cross-linux-headers" to "linux-headers". * guix/git-download.scm (git-fetch): Use 'standard-packages' instead of 'standard-inputs'. * tests/builders.scm ("gnu-build-system"): Remove use of 'build-system-builder'. ("gnu-build"): Remove 'source' and #:implicit-inputs? arguments to 'gnu-build'. * tests/packages.scm ("search paths"): Adjust to new build system API. ("package-cross-derivation, no cross builder"): Likewise. * doc/guix.texi (Build Systems): Add paragraph on bags.
7 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
8 years ago
derivations: 'derivation' and related procedures return a single value. * guix/derivations.scm (derivation->output-path, derivation->output-paths): New procedures. (derivation-path->output-path): Use 'derivation->output-path'. (derivation-path->output-paths): Use 'derivation->output-paths'. (derivation): Accept 'derivation?' objects as inputs. Return a single value. (build-derivations): New procedure. (compiled-modules): Use 'derivation->output-paths'. (build-expression->derivation)[source-path]: Add case for when the input matches 'derivation?'. [prologue]: Accept 'derivation?' objects in INPUTS. [mod-dir, go-dir]: Use 'derivation->output-path'. * guix/download.scm (url-fetch): Adjust to the single-value return. * guix/packages.scm (package-output): Use 'derivation->output-path'. * guix/scripts/build.scm (guix-build): When the argument is 'derivation-path?', pass it through 'read-derivation'. Use 'derivation-file-name' to print out the .drv file names, and to register them. Use 'derivation->output-path' instead of 'derivation-path->output-path'. * guix/scripts/package.scm (roll-back): Adjust to the single-value return. (guix-package): Use 'derivation->output-path'. * guix/ui.scm (show-what-to-build): Adjust to deal with 'derivation?' objects instead of .drv file names. * gnu/system/grub.scm (grub-configuration-file): Use 'derivation->output-path' instead of 'derivation-path->output-path'. * gnu/system/vm.scm (qemu-image, system-qemu-image): Likewise. * tests/builders.scm, tests/derivations.scm, tests/packages.scm, tests/store.scm, tests/union.scm: Adjust to the new calling convention. * doc/guix.texi (Defining Packages, The Store, Derivations): Adjust accordingly.
8 years ago
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix packages)
  19. #:use-module (guix utils)
  20. #:use-module (guix records)
  21. #:use-module (guix store)
  22. #:use-module (guix base32)
  23. #:use-module (guix derivations)
  24. #:use-module (guix build-system)
  25. #:use-module (ice-9 match)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (srfi srfi-9 gnu)
  28. #:use-module (srfi srfi-26)
  29. #:use-module (srfi srfi-34)
  30. #:use-module (srfi srfi-35)
  31. #:re-export (%current-system
  32. %current-target-system)
  33. #:export (origin
  34. origin?
  35. origin-uri
  36. origin-method
  37. origin-sha256
  38. origin-file-name
  39. origin-patches
  40. origin-patch-flags
  41. origin-patch-inputs
  42. origin-patch-guile
  43. origin-snippet
  44. origin-modules
  45. origin-imported-modules
  46. base32
  47. <search-path-specification>
  48. search-path-specification
  49. search-path-specification?
  50. search-path-specification->sexp
  51. package
  52. package?
  53. package-name
  54. package-version
  55. package-full-name
  56. package-source
  57. package-build-system
  58. package-arguments
  59. package-inputs
  60. package-native-inputs
  61. package-propagated-inputs
  62. package-outputs
  63. package-native-search-paths
  64. package-search-paths
  65. package-synopsis
  66. package-description
  67. package-license
  68. package-home-page
  69. package-platforms
  70. package-maintainers
  71. package-properties
  72. package-location
  73. package-field-location
  74. package-direct-inputs
  75. package-transitive-inputs
  76. package-transitive-target-inputs
  77. package-transitive-native-inputs
  78. package-transitive-propagated-inputs
  79. package-source-derivation
  80. package-derivation
  81. package-cross-derivation
  82. package-output
  83. &package-error
  84. package-error?
  85. package-error-package
  86. &package-input-error
  87. package-input-error?
  88. package-error-invalid-input
  89. &package-cross-build-system-error
  90. package-cross-build-system-error?
  91. package->bag
  92. bag->derivation
  93. bag-transitive-inputs
  94. bag-transitive-host-inputs
  95. bag-transitive-build-inputs
  96. bag-transitive-target-inputs))
  97. ;;; Commentary:
  98. ;;;
  99. ;;; This module provides a high-level mechanism to define packages in a
  100. ;;; Guix-based distribution.
  101. ;;;
  102. ;;; Code:
  103. ;; The source of a package, such as a tarball URL and fetcher---called
  104. ;; "origin" to avoid name clash with `package-source', `source', etc.
  105. (define-record-type* <origin>
  106. origin make-origin
  107. origin?
  108. (uri origin-uri) ; string
  109. (method origin-method) ; procedure
  110. (sha256 origin-sha256) ; bytevector
  111. (file-name origin-file-name (default #f)) ; optional file name
  112. (patches origin-patches (default '())) ; list of file names
  113. (snippet origin-snippet (default #f)) ; sexp or #f
  114. (patch-flags origin-patch-flags ; list of strings
  115. (default '("-p1")))
  116. ;; Patching requires Guile, GNU Patch, and a few more. These two fields are
  117. ;; used to specify these dependencies when needed.
  118. (patch-inputs origin-patch-inputs ; input list or #f
  119. (default #f))
  120. (modules origin-modules ; list of module names
  121. (default '()))
  122. (imported-modules origin-imported-modules ; list of module names
  123. (default '()))
  124. (patch-guile origin-patch-guile ; package or #f
  125. (default #f)))
  126. (define (print-origin origin port)
  127. "Write a concise representation of ORIGIN to PORT."
  128. (match origin
  129. (($ <origin> uri method sha256 file-name patches)
  130. (simple-format port "#<origin ~s ~a ~s ~a>"
  131. uri (bytevector->base32-string sha256)
  132. patches
  133. (number->string (object-address origin) 16)))))
  134. (set-record-type-printer! <origin> print-origin)
  135. (define-syntax base32
  136. (lambda (s)
  137. "Return the bytevector corresponding to the given Nix-base32
  138. representation."
  139. (syntax-case s ()
  140. ((_ str)
  141. (string? (syntax->datum #'str))
  142. ;; A literal string: do the conversion at expansion time.
  143. (with-syntax ((bv (nix-base32-string->bytevector
  144. (syntax->datum #'str))))
  145. #''bv))
  146. ((_ str)
  147. #'(nix-base32-string->bytevector str)))))
  148. ;; The specification of a search path.
  149. (define-record-type* <search-path-specification>
  150. search-path-specification make-search-path-specification
  151. search-path-specification?
  152. (variable search-path-specification-variable)
  153. (directories search-path-specification-directories)
  154. (separator search-path-specification-separator (default ":")))
  155. (define (search-path-specification->sexp spec)
  156. "Return an sexp representing SPEC, a <search-path-specification>. The sexp
  157. corresponds to the arguments expected by `set-path-environment-variable'."
  158. (match spec
  159. (($ <search-path-specification> variable directories separator)
  160. `(,variable ,directories ,separator))))
  161. ;; A package.
  162. (define-record-type* <package>
  163. package make-package
  164. package?
  165. (name package-name) ; string
  166. (version package-version) ; string
  167. (source package-source) ; <origin> instance
  168. (build-system package-build-system) ; build system
  169. (arguments package-arguments ; arguments for the build method
  170. (default '()) (thunked))
  171. (inputs package-inputs ; input packages or derivations
  172. (default '()) (thunked))
  173. (propagated-inputs package-propagated-inputs ; same, but propagated
  174. (default '()) (thunked))
  175. (native-inputs package-native-inputs ; native input packages/derivations
  176. (default '()) (thunked))
  177. (self-native-input? package-self-native-input? ; whether to use itself as
  178. ; a native input when cross-
  179. (default #f)) ; compiling
  180. (outputs package-outputs ; list of strings
  181. (default '("out")))
  182. ; lists of
  183. ; <search-path-specification>,
  184. ; for native and cross
  185. ; inputs
  186. (native-search-paths package-native-search-paths (default '()))
  187. (search-paths package-search-paths (default '()))
  188. (synopsis package-synopsis) ; one-line description
  189. (description package-description) ; one or two paragraphs
  190. (license package-license)
  191. (home-page package-home-page)
  192. (platforms package-platforms (default '()))
  193. (maintainers package-maintainers (default '()))
  194. (properties package-properties (default '())) ; alist for anything else
  195. (location package-location
  196. (default (and=> (current-source-location)
  197. source-properties->location))))
  198. (set-record-type-printer! <package>
  199. (lambda (package port)
  200. (let ((loc (package-location package))
  201. (format simple-format))
  202. (format port "#<package ~a-~a ~a:~a ~a>"
  203. (package-name package)
  204. (package-version package)
  205. (location-file loc)
  206. (location-line loc)
  207. (number->string (object-address
  208. package)
  209. 16)))))
  210. (define (package-field-location package field)
  211. "Return the source code location of the definition of FIELD for PACKAGE, or
  212. #f if it could not be determined."
  213. (define (goto port line column)
  214. (unless (and (= (port-column port) (- column 1))
  215. (= (port-line port) (- line 1)))
  216. (unless (eof-object? (read-char port))
  217. (goto port line column))))
  218. (match (package-location package)
  219. (($ <location> file line column)
  220. (catch 'system
  221. (lambda ()
  222. ;; In general we want to keep relative file names for modules.
  223. (with-fluids ((%file-port-name-canonicalization 'relative))
  224. (call-with-input-file (search-path %load-path file)
  225. (lambda (port)
  226. (goto port line column)
  227. (match (read port)
  228. (('package inits ...)
  229. (let ((field (assoc field inits)))
  230. (match field
  231. ((_ value)
  232. ;; Put the `or' here, and not in the first argument of
  233. ;; `and=>', to work around a compiler bug in 2.0.5.
  234. (or (and=> (source-properties value)
  235. source-properties->location)
  236. (and=> (source-properties field)
  237. source-properties->location)))
  238. (_
  239. #f))))
  240. (_
  241. #f))))))
  242. (lambda _
  243. #f)))
  244. (_ #f)))
  245. ;; Error conditions.
  246. (define-condition-type &package-error &error
  247. package-error?
  248. (package package-error-package))
  249. (define-condition-type &package-input-error &package-error
  250. package-input-error?
  251. (input package-error-invalid-input))
  252. (define-condition-type &package-cross-build-system-error &package-error
  253. package-cross-build-system-error?)
  254. (define (package-full-name package)
  255. "Return the full name of PACKAGE--i.e., `NAME-VERSION'."
  256. (string-append (package-name package) "-" (package-version package)))
  257. (define (%standard-patch-inputs)
  258. (let ((ref (lambda (module var)
  259. (module-ref (resolve-interface module) var))))
  260. `(("tar" ,(ref '(gnu packages base) 'tar))
  261. ("xz" ,(ref '(gnu packages compression) 'xz))
  262. ("bzip2" ,(ref '(gnu packages compression) 'bzip2))
  263. ("gzip" ,(ref '(gnu packages compression) 'gzip))
  264. ("lzip" ,(ref '(gnu packages compression) 'lzip))
  265. ("patch" ,(ref '(gnu packages base) 'patch)))))
  266. (define (default-guile)
  267. "Return the default Guile package for SYSTEM."
  268. (let ((distro (resolve-interface '(gnu packages commencement))))
  269. (module-ref distro 'guile-final)))
  270. (define* (patch-and-repack store source patches
  271. #:key
  272. (inputs '())
  273. (snippet #f)
  274. (flags '("-p1"))
  275. (modules '())
  276. (imported-modules '())
  277. (guile-for-build (%guile-for-build))
  278. (system (%current-system)))
  279. "Unpack SOURCE (a derivation or store path), apply all of PATCHES, and
  280. repack the tarball using the tools listed in INPUTS. When SNIPPET is true,
  281. it must be an s-expression that will run from within the directory where
  282. SOURCE was unpacked, after all of PATCHES have been applied. MODULES and
  283. IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
  284. (define source-file-name
  285. ;; SOURCE is usually a derivation, but it could be a store file.
  286. (if (derivation? source)
  287. (derivation->output-path source)
  288. source))
  289. (define decompression-type
  290. (cond ((string-suffix? "gz" source-file-name) "gzip")
  291. ((string-suffix? "bz2" source-file-name) "bzip2")
  292. ((string-suffix? "lz" source-file-name) "lzip")
  293. (else "xz")))
  294. (define original-file-name
  295. ;; Remove the store prefix plus the slash, hash, and hyphen.
  296. (let* ((sans (string-drop source-file-name
  297. (+ (string-length (%store-prefix)) 1)))
  298. (dash (string-index sans #\-)))
  299. (string-drop sans (+ 1 dash))))
  300. (define (numeric-extension? file-name)
  301. ;; Return true if FILE-NAME ends with digits.
  302. (and=> (file-extension file-name)
  303. (cut string-every char-set:hex-digit <>)))
  304. (define (tarxz-name file-name)
  305. ;; Return a '.tar.xz' file name based on FILE-NAME.
  306. (let ((base (if (numeric-extension? file-name)
  307. original-file-name
  308. (file-sans-extension file-name))))
  309. (string-append base
  310. (if (equal? (file-extension base) "tar")
  311. ".xz"
  312. ".tar.xz"))))
  313. (define patch-inputs
  314. (map (lambda (number patch)
  315. (list (string-append "patch" (number->string number))
  316. (match patch
  317. ((? string?)
  318. (add-to-store store (basename patch) #t
  319. "sha256" patch))
  320. ((? origin?)
  321. (package-source-derivation store patch)))))
  322. (iota (length patches))
  323. patches))
  324. (define builder
  325. `(begin
  326. (use-modules (ice-9 ftw)
  327. (srfi srfi-1)
  328. (guix build utils))
  329. (let ((out (assoc-ref %outputs "out"))
  330. (xz (assoc-ref %build-inputs "xz"))
  331. (decomp (assoc-ref %build-inputs ,decompression-type))
  332. (source (assoc-ref %build-inputs "source"))
  333. (tar (string-append (assoc-ref %build-inputs "tar")
  334. "/bin/tar"))
  335. (patch (string-append (assoc-ref %build-inputs "patch")
  336. "/bin/patch")))
  337. (define (apply-patch input)
  338. (let ((patch* (assoc-ref %build-inputs input)))
  339. (format (current-error-port) "applying '~a'...~%" patch*)
  340. (zero? (system* patch "--batch" ,@flags "--input" patch*))))
  341. (define (first-file directory)
  342. ;; Return the name of the first file in DIRECTORY.
  343. (car (scandir directory
  344. (lambda (name)
  345. (not (member name '("." "..")))))))
  346. (setenv "PATH" (string-append xz "/bin" ":"
  347. decomp "/bin"))
  348. ;; SOURCE may be either a directory or a tarball.
  349. (and (if (file-is-directory? source)
  350. (let* ((store (or (getenv "NIX_STORE") "/gnu/store"))
  351. (len (+ 1 (string-length store)))
  352. (base (string-drop source len))
  353. (dash (string-index base #\-))
  354. (directory (string-drop base (+ 1 dash))))
  355. (mkdir directory)
  356. (copy-recursively source directory)
  357. #t)
  358. (zero? (system* tar "xvf" source)))
  359. (let ((directory (first-file ".")))
  360. (format (current-error-port)
  361. "source is under '~a'~%" directory)
  362. (chdir directory)
  363. (and (every apply-patch ',(map car patch-inputs))
  364. ,@(if snippet
  365. `((let ((module (make-fresh-user-module)))
  366. (module-use-interfaces! module
  367. (map resolve-interface
  368. ',modules))
  369. (module-define! module '%build-inputs
  370. %build-inputs)
  371. (module-define! module '%outputs %outputs)
  372. ((@ (system base compile) compile)
  373. ',snippet
  374. #:to 'value
  375. #:opts %auto-compilation-options
  376. #:env module)))
  377. '())
  378. (begin (chdir "..") #t)
  379. (zero? (system* tar "cvfa" out directory))))))))
  380. (let ((name (tarxz-name original-file-name))
  381. (inputs (filter-map (match-lambda
  382. ((name (? package? p))
  383. (and (member name (cons decompression-type
  384. '("tar" "xz" "patch")))
  385. (list name
  386. (package-derivation store p
  387. system)))))
  388. (or inputs (%standard-patch-inputs))))
  389. (modules (delete-duplicates (cons '(guix build utils) modules))))
  390. (build-expression->derivation store name builder
  391. #:inputs `(("source" ,source)
  392. ,@inputs
  393. ,@patch-inputs)
  394. #:system system
  395. #:modules modules
  396. #:guile-for-build guile-for-build)))
  397. (define* (package-source-derivation store source
  398. #:optional (system (%current-system)))
  399. "Return the derivation path for SOURCE, a package source, for SYSTEM."
  400. (match source
  401. (($ <origin> uri method sha256 name () #f)
  402. ;; No patches, no snippet: this is a fixed-output derivation.
  403. (method store uri 'sha256 sha256 name
  404. #:system system))
  405. (($ <origin> uri method sha256 name (patches ...) snippet
  406. (flags ...) inputs (modules ...) (imported-modules ...)
  407. guile-for-build)
  408. ;; Patches and/or a snippet.
  409. (let ((source (method store uri 'sha256 sha256 name
  410. #:system system))
  411. (guile (match (or guile-for-build (%guile-for-build)
  412. (default-guile))
  413. ((? package? p)
  414. (package-derivation store p system))
  415. ((? derivation? drv)
  416. drv))))
  417. (patch-and-repack store source patches
  418. #:inputs inputs
  419. #:snippet snippet
  420. #:flags flags
  421. #:system system
  422. #:modules modules
  423. #:imported-modules modules
  424. #:guile-for-build guile)))
  425. ((and (? string?) (? direct-store-path?) file)
  426. file)
  427. ((? string? file)
  428. (add-to-store store (basename file) #t "sha256" file))))
  429. (define (transitive-inputs inputs)
  430. (let loop ((inputs inputs)
  431. (result '()))
  432. (match inputs
  433. (()
  434. (delete-duplicates (reverse result))) ; XXX: efficiency
  435. (((and i (name (? package? p) sub ...)) rest ...)
  436. (let ((t (map (match-lambda
  437. ((dep-name derivation ...)
  438. (cons (string-append name "/" dep-name)
  439. derivation)))
  440. (package-propagated-inputs p))))
  441. (loop (append t rest)
  442. (append t (cons i result)))))
  443. ((input rest ...)
  444. (loop rest (cons input result))))))
  445. (define (package-direct-inputs package)
  446. "Return all the direct inputs of PACKAGE---i.e, its direct inputs along
  447. with their propagated inputs."
  448. (append (package-native-inputs package)
  449. (package-inputs package)
  450. (package-propagated-inputs package)))
  451. (define (package-transitive-inputs package)
  452. "Return the transitive inputs of PACKAGE---i.e., its direct inputs along
  453. with their propagated inputs, recursively."
  454. (transitive-inputs (package-direct-inputs package)))
  455. (define (package-transitive-target-inputs package)
  456. "Return the transitive target inputs of PACKAGE---i.e., its direct inputs
  457. along with their propagated inputs, recursively. This only includes inputs
  458. for the target system, and not native inputs."
  459. (transitive-inputs (append (package-inputs package)
  460. (package-propagated-inputs package))))
  461. (define (package-transitive-native-inputs package)
  462. "Return the transitive native inputs of PACKAGE---i.e., its direct inputs
  463. along with their propagated inputs, recursively. This only includes inputs
  464. for the host system (\"native inputs\"), and not target inputs."
  465. (transitive-inputs (package-native-inputs package)))
  466. (define (package-transitive-propagated-inputs package)
  467. "Return the propagated inputs of PACKAGE, and their propagated inputs,
  468. recursively."
  469. (transitive-inputs (package-propagated-inputs package)))
  470. (define (bag-transitive-inputs bag)
  471. "Same as 'package-transitive-inputs', but applied to a bag."
  472. (transitive-inputs (append (bag-build-inputs bag)
  473. (bag-host-inputs bag)
  474. (bag-target-inputs bag))))
  475. (define (bag-transitive-build-inputs bag)
  476. "Same as 'package-transitive-native-inputs', but applied to a bag."
  477. (transitive-inputs (bag-build-inputs bag)))
  478. (define (bag-transitive-host-inputs bag)
  479. "Same as 'package-transitive-target-inputs', but applied to a bag."
  480. (transitive-inputs (bag-host-inputs bag)))
  481. (define (bag-transitive-target-inputs bag)
  482. "Return the \"target inputs\" of BAG, recursively."
  483. (transitive-inputs (bag-target-inputs bag)))
  484. ;;;
  485. ;;; Package derivations.
  486. ;;;
  487. (define %derivation-cache
  488. ;; Package to derivation-path mapping.
  489. (make-weak-key-hash-table 100))
  490. (define (cache package system thunk)
  491. "Memoize the return values of THUNK as the derivation of PACKAGE on
  492. SYSTEM."
  493. ;; FIXME: This memoization should be associated with the open store, because
  494. ;; otherwise it breaks when switching to a different store.
  495. (let ((vals (call-with-values thunk list)))
  496. ;; Use `hashq-set!' instead of `hash-set!' because `hash' returns the
  497. ;; same value for all structs (as of Guile 2.0.6), and because pointer
  498. ;; equality is sufficient in practice.
  499. (hashq-set! %derivation-cache package `((,system ,@vals)))
  500. (apply values vals)))
  501. (define-syntax-rule (cached package system body ...)
  502. "Memoize the result of BODY for the arguments PACKAGE and SYSTEM.
  503. Return the cached result when available."
  504. (let ((thunk (lambda () body ...)))
  505. (match (hashq-ref %derivation-cache package)
  506. ((alist (... ...))
  507. (match (assoc-ref alist system)
  508. ((vals (... ...))
  509. (apply values vals))
  510. (#f
  511. (cache package system thunk))))
  512. (#f
  513. (cache package system thunk)))))
  514. (define* (expand-input store package input system #:optional cross-system)
  515. "Expand INPUT, an input tuple, such that it contains only references to
  516. derivation paths or store paths. PACKAGE is only used to provide contextual
  517. information in exceptions."
  518. (define (intern file)
  519. ;; Add FILE to the store. Set the `recursive?' bit to #t, so that
  520. ;; file permissions are preserved.
  521. (add-to-store store (basename file) #t "sha256" file))
  522. (define derivation
  523. (if cross-system
  524. (cut package-cross-derivation store <> cross-system system)
  525. (cut package-derivation store <> system)))
  526. (match input
  527. (((? string? name) (? package? package))
  528. (list name (derivation package)))
  529. (((? string? name) (? package? package)
  530. (? string? sub-drv))
  531. (list name (derivation package)
  532. sub-drv))
  533. (((? string? name)
  534. (and (? string?) (? derivation-path?) drv))
  535. (list name drv))
  536. (((? string? name)
  537. (and (? string?) (? file-exists? file)))
  538. ;; Add FILE to the store. When FILE is in the sub-directory of a
  539. ;; store path, it needs to be added anyway, so it can be used as a
  540. ;; source.
  541. (list name (intern file)))
  542. (((? string? name) (? origin? source))
  543. (list name (package-source-derivation store source system)))
  544. (x
  545. (raise (condition (&package-input-error
  546. (package package)
  547. (input x)))))))
  548. (define* (package->bag package #:optional
  549. (system (%current-system))
  550. (target (%current-target-system)))
  551. "Compile PACKAGE into a bag for SYSTEM, possibly cross-compiled to TARGET,
  552. and return it."
  553. ;; Bind %CURRENT-SYSTEM and %CURRENT-TARGET-SYSTEM so that thunked field
  554. ;; values can refer to it.
  555. (parameterize ((%current-system system)
  556. (%current-target-system target))
  557. (match package
  558. (($ <package> name version source build-system
  559. args inputs propagated-inputs native-inputs self-native-input?
  560. outputs)
  561. (or (make-bag build-system (package-full-name package)
  562. #:system system
  563. #:target target
  564. #:source source
  565. #:inputs (append (inputs)
  566. (propagated-inputs))
  567. #:outputs outputs
  568. #:native-inputs `(,@(if (and target self-native-input?)
  569. `(("self" ,package))
  570. '())
  571. ,@(native-inputs))
  572. #:arguments (args))
  573. (raise (if target
  574. (condition
  575. (&package-cross-build-system-error
  576. (package package)))
  577. (condition
  578. (&package-error
  579. (package package))))))))))
  580. (define* (bag->derivation store bag
  581. #:optional context)
  582. "Return the derivation to build BAG for SYSTEM. Optionally, CONTEXT can be
  583. a package object describing the context in which the call occurs, for improved
  584. error reporting."
  585. (if (bag-target bag)
  586. (bag->cross-derivation store bag)
  587. (let* ((system (bag-system bag))
  588. (inputs (bag-transitive-inputs bag))
  589. (input-drvs (map (cut expand-input store context <> system)
  590. inputs))
  591. (paths (delete-duplicates
  592. (append-map (match-lambda
  593. ((_ (? package? p) _ ...)
  594. (package-native-search-paths
  595. p))
  596. (_ '()))
  597. inputs))))
  598. (apply (bag-build bag)
  599. store (bag-name bag) input-drvs
  600. #:search-paths paths
  601. #:outputs (bag-outputs bag) #:system system
  602. (bag-arguments bag)))))
  603. (define* (bag->cross-derivation store bag
  604. #:optional context)
  605. "Return the derivation to build BAG, which is actually a cross build.
  606. Optionally, CONTEXT can be a package object denoting the context of the call.
  607. This is an internal procedure."
  608. (let* ((system (bag-system bag))
  609. (target (bag-target bag))
  610. (host (bag-transitive-host-inputs bag))
  611. (host-drvs (map (cut expand-input store context <> system target)
  612. host))
  613. (target* (bag-transitive-target-inputs bag))
  614. (target-drvs (map (cut expand-input store context <> system)
  615. target*))
  616. (build (bag-transitive-build-inputs bag))
  617. (build-drvs (map (cut expand-input store context <> system)
  618. build))
  619. (all (append build target* host))
  620. (paths (delete-duplicates
  621. (append-map (match-lambda
  622. ((_ (? package? p) _ ...)
  623. (package-search-paths p))
  624. (_ '()))
  625. all)))
  626. (npaths (delete-duplicates
  627. (append-map (match-lambda
  628. ((_ (? package? p) _ ...)
  629. (package-native-search-paths
  630. p))
  631. (_ '()))
  632. all))))
  633. (apply (bag-build bag)
  634. store (bag-name bag)
  635. #:native-drvs build-drvs
  636. #:target-drvs (append host-drvs target-drvs)
  637. #:search-paths paths
  638. #:native-search-paths npaths
  639. #:outputs (bag-outputs bag)
  640. #:system system #:target target
  641. (bag-arguments bag))))
  642. (define* (package-derivation store package
  643. #:optional (system (%current-system)))
  644. "Return the <derivation> object of PACKAGE for SYSTEM."
  645. ;; Compute the derivation and cache the result. Caching is important
  646. ;; because some derivations, such as the implicit inputs of the GNU build
  647. ;; system, will be queried many, many times in a row.
  648. (cached package system
  649. (bag->derivation store (package->bag package system #f)
  650. package)))
  651. (define* (package-cross-derivation store package target
  652. #:optional (system (%current-system)))
  653. "Cross-build PACKAGE for TARGET (a GNU triplet) from host SYSTEM (a Guix
  654. system identifying string)."
  655. (cached package (cons system target)
  656. (bag->derivation store (package->bag package system target)
  657. package)))
  658. (define* (package-output store package
  659. #:optional (output "out") (system (%current-system)))
  660. "Return the output path of PACKAGE's OUTPUT for SYSTEM---where OUTPUT is the
  661. symbolic output name, such as \"out\". Note that this procedure calls
  662. `package-derivation', which is costly."
  663. (let ((drv (package-derivation store package system)))
  664. (derivation->output-path drv output)))