packages.scm 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014, 2015, 2017 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
  5. ;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
  6. ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  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.
  14. ;;;
  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.
  19. ;;;
  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/>.
  22. (define-module (guix packages)
  23. #:use-module (guix utils)
  24. #:use-module (guix records)
  25. #:use-module (guix store)
  26. #:use-module (guix monads)
  27. #:use-module (guix gexp)
  28. #:use-module (guix base32)
  29. #:use-module (guix grafts)
  30. #:use-module (guix derivations)
  31. #:use-module (guix memoization)
  32. #:use-module (guix build-system)
  33. #:use-module (guix search-paths)
  34. #:use-module (guix sets)
  35. #:use-module (ice-9 match)
  36. #:use-module (ice-9 vlist)
  37. #:use-module (srfi srfi-1)
  38. #:use-module (srfi srfi-9 gnu)
  39. #:use-module (srfi srfi-11)
  40. #:use-module (srfi srfi-26)
  41. #:use-module (srfi srfi-34)
  42. #:use-module (srfi srfi-35)
  43. #:use-module (web uri)
  44. #:re-export (%current-system
  45. %current-target-system
  46. search-path-specification) ;for convenience
  47. #:export (origin
  48. origin?
  49. origin-uri
  50. origin-method
  51. origin-sha256
  52. origin-file-name
  53. origin-actual-file-name
  54. origin-patches
  55. origin-patch-flags
  56. origin-patch-inputs
  57. origin-patch-guile
  58. origin-snippet
  59. origin-modules
  60. base32
  61. package
  62. package?
  63. package-name
  64. package-upstream-name
  65. package-version
  66. package-full-name
  67. package-source
  68. package-build-system
  69. package-arguments
  70. package-inputs
  71. package-native-inputs
  72. package-propagated-inputs
  73. package-outputs
  74. package-native-search-paths
  75. package-search-paths
  76. package-replacement
  77. package-synopsis
  78. package-description
  79. package-license
  80. package-home-page
  81. package-supported-systems
  82. package-maintainers
  83. package-properties
  84. package-location
  85. hidden-package
  86. hidden-package?
  87. package-superseded
  88. deprecated-package
  89. package-field-location
  90. package-direct-sources
  91. package-transitive-sources
  92. package-direct-inputs
  93. package-transitive-inputs
  94. package-transitive-target-inputs
  95. package-transitive-native-inputs
  96. package-transitive-propagated-inputs
  97. package-transitive-native-search-paths
  98. package-transitive-supported-systems
  99. package-mapping
  100. package-input-rewriting
  101. package-source-derivation
  102. package-derivation
  103. package-cross-derivation
  104. package-output
  105. package-grafts
  106. package/inherit
  107. transitive-input-references
  108. %supported-systems
  109. %hurd-systems
  110. %hydra-supported-systems
  111. supported-package?
  112. &package-error
  113. package-error?
  114. package-error-package
  115. &package-input-error
  116. package-input-error?
  117. package-error-invalid-input
  118. &package-cross-build-system-error
  119. package-cross-build-system-error?
  120. package->bag
  121. bag->derivation
  122. bag-direct-inputs
  123. bag-transitive-inputs
  124. bag-transitive-host-inputs
  125. bag-transitive-build-inputs
  126. bag-transitive-target-inputs
  127. default-guile
  128. default-guile-derivation
  129. set-guile-for-build
  130. package-file
  131. package->derivation
  132. package->cross-derivation
  133. origin->derivation))
  134. ;;; Commentary:
  135. ;;;
  136. ;;; This module provides a high-level mechanism to define packages in a
  137. ;;; Guix-based distribution.
  138. ;;;
  139. ;;; Code:
  140. ;; The source of a package, such as a tarball URL and fetcher---called
  141. ;; "origin" to avoid name clash with `package-source', `source', etc.
  142. (define-record-type* <origin>
  143. origin make-origin
  144. origin?
  145. (uri origin-uri) ; string
  146. (method origin-method) ; procedure
  147. (sha256 origin-sha256) ; bytevector
  148. (file-name origin-file-name (default #f)) ; optional file name
  149. ;; Patches are delayed so that the 'search-patch' calls are made lazily,
  150. ;; which reduces I/O on startup and allows patch-not-found errors to be
  151. ;; gracefully handled at run time.
  152. (patches origin-patches ; list of file names
  153. (default '()) (delayed))
  154. (snippet origin-snippet (default #f)) ; sexp or #f
  155. (patch-flags origin-patch-flags ; list of strings
  156. (default '("-p1")))
  157. ;; Patching requires Guile, GNU Patch, and a few more. These two fields are
  158. ;; used to specify these dependencies when needed.
  159. (patch-inputs origin-patch-inputs ; input list or #f
  160. (default #f))
  161. (modules origin-modules ; list of module names
  162. (default '()))
  163. (patch-guile origin-patch-guile ; package or #f
  164. (default #f)))
  165. (define (print-origin origin port)
  166. "Write a concise representation of ORIGIN to PORT."
  167. (match origin
  168. (($ <origin> uri method sha256 file-name patches)
  169. (simple-format port "#<origin ~s ~a ~s ~a>"
  170. uri (bytevector->base32-string sha256)
  171. (force patches)
  172. (number->string (object-address origin) 16)))))
  173. (set-record-type-printer! <origin> print-origin)
  174. (define-syntax base32
  175. (lambda (s)
  176. "Return the bytevector corresponding to the given Nix-base32
  177. representation."
  178. (syntax-case s ()
  179. ((_ str)
  180. (string? (syntax->datum #'str))
  181. ;; A literal string: do the conversion at expansion time.
  182. (with-syntax ((bv (nix-base32-string->bytevector
  183. (syntax->datum #'str))))
  184. #''bv))
  185. ((_ str)
  186. #'(nix-base32-string->bytevector str)))))
  187. (define (origin-actual-file-name origin)
  188. "Return the file name of ORIGIN, either its 'file-name' field or the file
  189. name of its URI."
  190. (define (uri->file-name uri)
  191. ;; Return the 'base name' of URI or URI itself, where URI is a string.
  192. (let ((path (and=> (string->uri uri) uri-path)))
  193. (if path
  194. (basename path)
  195. uri)))
  196. (or (origin-file-name origin)
  197. (match (origin-uri origin)
  198. ((head . tail)
  199. (uri->file-name head))
  200. ((? string? uri)
  201. (uri->file-name uri))
  202. (else
  203. ;; git, svn, cvs, etc. reference
  204. #f))))
  205. (define %supported-systems
  206. ;; This is the list of system types that are supported. By default, we
  207. ;; expect all packages to build successfully here.
  208. '("x86_64-linux" "i686-linux" "armhf-linux" "aarch64-linux" "mips64el-linux"))
  209. (define %hurd-systems
  210. ;; The GNU/Hurd systems for which support is being developed.
  211. '("i585-gnu" "i686-gnu"))
  212. (define %hydra-supported-systems
  213. ;; This is the list of system types for which build machines are available.
  214. ;;
  215. ;; XXX: MIPS is temporarily unavailable on Hydra:
  216. ;; <https://lists.gnu.org/archive/html/guix-devel/2017-03/msg00790.html>.
  217. (fold delete %supported-systems '("aarch64-linux" "mips64el-linux")))
  218. ;; A package.
  219. (define-record-type* <package>
  220. package make-package
  221. package?
  222. (name package-name) ; string
  223. (version package-version) ; string
  224. (source package-source) ; <origin> instance
  225. (build-system package-build-system) ; build system
  226. (arguments package-arguments ; arguments for the build method
  227. (default '()) (thunked))
  228. (inputs package-inputs ; input packages or derivations
  229. (default '()) (thunked))
  230. (propagated-inputs package-propagated-inputs ; same, but propagated
  231. (default '()) (thunked))
  232. (native-inputs package-native-inputs ; native input packages/derivations
  233. (default '()) (thunked))
  234. (self-native-input? package-self-native-input? ; whether to use itself as
  235. ; a native input when cross-
  236. (default #f)) ; compiling
  237. (outputs package-outputs ; list of strings
  238. (default '("out")))
  239. ; lists of
  240. ; <search-path-specification>,
  241. ; for native and cross
  242. ; inputs
  243. (native-search-paths package-native-search-paths (default '()))
  244. (search-paths package-search-paths (default '()))
  245. ;; The 'replacement' field is marked as "innate" because it never makes
  246. ;; sense to inherit a replacement as is. See the 'package/inherit' macro.
  247. (replacement package-replacement ; package | #f
  248. (default #f) (thunked) (innate))
  249. (synopsis package-synopsis) ; one-line description
  250. (description package-description) ; one or two paragraphs
  251. (license package-license)
  252. (home-page package-home-page)
  253. (supported-systems package-supported-systems ; list of strings
  254. (default %supported-systems))
  255. (maintainers package-maintainers (default '()))
  256. (properties package-properties (default '())) ; alist for anything else
  257. (location package-location
  258. (default (and=> (current-source-location)
  259. source-properties->location))
  260. (innate)))
  261. (set-record-type-printer! <package>
  262. (lambda (package port)
  263. (let ((loc (package-location package))
  264. (format simple-format))
  265. (format port "#<package ~a@~a ~a~a>"
  266. (package-name package)
  267. (package-version package)
  268. (if loc
  269. (format #f "~a:~a "
  270. (location-file loc)
  271. (location-line loc))
  272. "")
  273. (number->string (object-address
  274. package)
  275. 16)))))
  276. (define (package-upstream-name package)
  277. "Return the upstream name of PACKAGE, which could be different from the name
  278. it has in Guix."
  279. (or (assq-ref (package-properties package) 'upstream-name)
  280. (package-name package)))
  281. (define (hidden-package p)
  282. "Return a \"hidden\" version of P--i.e., one that 'fold-packages' and thus,
  283. user interfaces, ignores."
  284. (package
  285. (inherit p)
  286. (properties `((hidden? . #t)
  287. ,@(package-properties p)))))
  288. (define (hidden-package? p)
  289. "Return true if P is \"hidden\"--i.e., must not be visible to user
  290. interfaces."
  291. (assoc-ref (package-properties p) 'hidden?))
  292. (define (package-superseded p)
  293. "Return the package the supersedes P, or #f if P is still current."
  294. (assoc-ref (package-properties p) 'superseded))
  295. (define (deprecated-package old-name p)
  296. "Return a package called OLD-NAME and marked as superseded by P, a package
  297. object."
  298. (package
  299. (inherit p)
  300. (name old-name)
  301. (properties `((superseded . ,p)))))
  302. (define (package-field-location package field)
  303. "Return the source code location of the definition of FIELD for PACKAGE, or
  304. #f if it could not be determined."
  305. (define (goto port line column)
  306. (unless (and (= (port-column port) (- column 1))
  307. (= (port-line port) (- line 1)))
  308. (unless (eof-object? (read-char port))
  309. (goto port line column))))
  310. (match (package-location package)
  311. (($ <location> file line column)
  312. (catch 'system
  313. (lambda ()
  314. ;; In general we want to keep relative file names for modules.
  315. (with-fluids ((%file-port-name-canonicalization 'relative))
  316. (call-with-input-file (search-path %load-path file)
  317. (lambda (port)
  318. (goto port line column)
  319. (match (read port)
  320. (('package inits ...)
  321. (let ((field (assoc field inits)))
  322. (match field
  323. ((_ value)
  324. ;; Put the `or' here, and not in the first argument of
  325. ;; `and=>', to work around a compiler bug in 2.0.5.
  326. (or (and=> (source-properties value)
  327. source-properties->location)
  328. (and=> (source-properties field)
  329. source-properties->location)))
  330. (_
  331. #f))))
  332. (_
  333. #f))))))
  334. (lambda _
  335. #f)))
  336. (_ #f)))
  337. ;; Error conditions.
  338. (define-condition-type &package-error &error
  339. package-error?
  340. (package package-error-package))
  341. (define-condition-type &package-input-error &package-error
  342. package-input-error?
  343. (input package-error-invalid-input))
  344. (define-condition-type &package-cross-build-system-error &package-error
  345. package-cross-build-system-error?)
  346. (define (package-full-name package)
  347. "Return the full name of PACKAGE--i.e., `NAME-VERSION'."
  348. (string-append (package-name package) "-" (package-version package)))
  349. (define (%standard-patch-inputs)
  350. (let* ((canonical (module-ref (resolve-interface '(gnu packages base))
  351. 'canonical-package))
  352. (ref (lambda (module var)
  353. (canonical
  354. (module-ref (resolve-interface module) var)))))
  355. `(("tar" ,(ref '(gnu packages base) 'tar))
  356. ("xz" ,(ref '(gnu packages compression) 'xz))
  357. ("bzip2" ,(ref '(gnu packages compression) 'bzip2))
  358. ("gzip" ,(ref '(gnu packages compression) 'gzip))
  359. ("lzip" ,(ref '(gnu packages compression) 'lzip))
  360. ("unzip" ,(ref '(gnu packages compression) 'unzip))
  361. ("patch" ,(ref '(gnu packages base) 'patch))
  362. ("locales" ,(ref '(gnu packages base) 'glibc-utf8-locales)))))
  363. (define (default-guile)
  364. "Return the default Guile package used to run the build code of
  365. derivations."
  366. (let ((distro (resolve-interface '(gnu packages commencement))))
  367. (module-ref distro 'guile-final)))
  368. (define (guile-2.0)
  369. "Return Guile 2.0."
  370. ;; FIXME: This is used as a workaround for <https://bugs.gnu.org/28211> when
  371. ;; grafting packages.
  372. (let ((distro (resolve-interface '(gnu packages guile))))
  373. (module-ref distro 'guile-2.0)))
  374. (define* (default-guile-derivation #:optional (system (%current-system)))
  375. "Return the derivation for SYSTEM of the default Guile package used to run
  376. the build code of derivation."
  377. (package->derivation (default-guile) system
  378. #:graft? #f))
  379. (define* (patch-and-repack source patches
  380. #:key
  381. inputs
  382. (snippet #f)
  383. (flags '("-p1"))
  384. (modules '())
  385. (guile-for-build (%guile-for-build))
  386. (system (%current-system)))
  387. "Unpack SOURCE (a derivation or store path), apply all of PATCHES, and
  388. repack the tarball using the tools listed in INPUTS. When SNIPPET is true,
  389. it must be an s-expression that will run from within the directory where
  390. SOURCE was unpacked, after all of PATCHES have been applied. MODULES
  391. specifies modules in scope when evaluating SNIPPET."
  392. (define source-file-name
  393. ;; SOURCE is usually a derivation, but it could be a store file.
  394. (if (derivation? source)
  395. (derivation->output-path source)
  396. source))
  397. (define lookup-input
  398. ;; The default value of the 'patch-inputs' field, and thus INPUTS is #f,
  399. ;; so deal with that.
  400. (let ((inputs (or inputs (%standard-patch-inputs))))
  401. (lambda (name)
  402. (match (assoc-ref inputs name)
  403. ((package) package)
  404. (#f #f)))))
  405. (define decompression-type
  406. (cond ((string-suffix? "gz" source-file-name) "gzip")
  407. ((string-suffix? "Z" source-file-name) "gzip")
  408. ((string-suffix? "bz2" source-file-name) "bzip2")
  409. ((string-suffix? "lz" source-file-name) "lzip")
  410. ((string-suffix? "zip" source-file-name) "unzip")
  411. (else "xz")))
  412. (define original-file-name
  413. ;; Remove the store prefix plus the slash, hash, and hyphen.
  414. (let* ((sans (string-drop source-file-name
  415. (+ (string-length (%store-prefix)) 1)))
  416. (dash (string-index sans #\-)))
  417. (string-drop sans (+ 1 dash))))
  418. (define (numeric-extension? file-name)
  419. ;; Return true if FILE-NAME ends with digits.
  420. (and=> (file-extension file-name)
  421. (cut string-every char-set:hex-digit <>)))
  422. (define (tarxz-name file-name)
  423. ;; Return a '.tar.xz' file name based on FILE-NAME.
  424. (let ((base (if (numeric-extension? file-name)
  425. original-file-name
  426. (file-sans-extension file-name))))
  427. (string-append base
  428. (if (equal? (file-extension base) "tar")
  429. ".xz"
  430. ".tar.xz"))))
  431. (define instantiate-patch
  432. (match-lambda
  433. ((? string? patch) ;deprecated
  434. (interned-file patch #:recursive? #t))
  435. ((? struct? patch) ;origin, local-file, etc.
  436. (lower-object patch system))))
  437. (mlet %store-monad ((tar -> (lookup-input "tar"))
  438. (xz -> (lookup-input "xz"))
  439. (patch -> (lookup-input "patch"))
  440. (locales -> (lookup-input "locales"))
  441. (decomp -> (lookup-input decompression-type))
  442. (patches (sequence %store-monad
  443. (map instantiate-patch patches))))
  444. (define build
  445. (with-imported-modules '((guix build utils))
  446. #~(begin
  447. (use-modules (ice-9 ftw)
  448. (srfi srfi-1)
  449. (guix build utils))
  450. ;; The --sort option was added to GNU tar in version 1.28, released
  451. ;; 2014-07-28. During bootstrap we must cope with older versions.
  452. (define tar-supports-sort?
  453. (zero? (system* (string-append #+tar "/bin/tar")
  454. "cf" "/dev/null" "--files-from=/dev/null"
  455. "--sort=name")))
  456. (define (apply-patch patch)
  457. (format (current-error-port) "applying '~a'...~%" patch)
  458. ;; Use '--force' so that patches that do not apply perfectly are
  459. ;; rejected. Use '--no-backup-if-mismatch' to prevent making
  460. ;; "*.orig" file if a patch is applied with offset.
  461. (zero? (system* (string-append #+patch "/bin/patch")
  462. "--force" "--no-backup-if-mismatch"
  463. #+@flags "--input" patch)))
  464. (define (first-file directory)
  465. ;; Return the name of the first file in DIRECTORY.
  466. (car (scandir directory
  467. (lambda (name)
  468. (not (member name '("." "..")))))))
  469. ;; Encoding/decoding errors shouldn't be silent.
  470. (fluid-set! %default-port-conversion-strategy 'error)
  471. (when #+locales
  472. ;; First of all, install a UTF-8 locale so that UTF-8 file names
  473. ;; are correctly interpreted. During bootstrap, LOCALES is #f.
  474. (setenv "LOCPATH"
  475. (string-append #+locales "/lib/locale/"
  476. #+(and locales
  477. (package-version locales))))
  478. (setlocale LC_ALL "en_US.utf8"))
  479. (setenv "PATH" (string-append #+xz "/bin" ":"
  480. #+decomp "/bin"))
  481. ;; SOURCE may be either a directory or a tarball.
  482. (and (if (file-is-directory? #+source)
  483. (let* ((store (%store-directory))
  484. (len (+ 1 (string-length store)))
  485. (base (string-drop #+source len))
  486. (dash (string-index base #\-))
  487. (directory (string-drop base (+ 1 dash))))
  488. (mkdir directory)
  489. (copy-recursively #+source directory)
  490. #t)
  491. #+(if (string=? decompression-type "unzip")
  492. #~(zero? (system* "unzip" #+source))
  493. #~(zero? (system* (string-append #+tar "/bin/tar")
  494. "xvf" #+source))))
  495. (let ((directory (first-file ".")))
  496. (format (current-error-port)
  497. "source is under '~a'~%" directory)
  498. (chdir directory)
  499. (and (every apply-patch '#+patches)
  500. #+@(if snippet
  501. #~((let ((module (make-fresh-user-module)))
  502. (module-use-interfaces!
  503. module
  504. (map resolve-interface '#+modules))
  505. ((@ (system base compile) compile)
  506. '#+snippet
  507. #:to 'value
  508. #:opts %auto-compilation-options
  509. #:env module)))
  510. #~())
  511. (begin (chdir "..") #t)
  512. (unless tar-supports-sort?
  513. (call-with-output-file ".file_list"
  514. (lambda (port)
  515. (for-each (lambda (name)
  516. (format port "~a~%" name))
  517. (find-files directory
  518. #:directories? #t
  519. #:fail-on-error? #t)))))
  520. (zero? (apply system*
  521. (string-append #+tar "/bin/tar")
  522. "cvf" #$output
  523. ;; The bootstrap xz does not support
  524. ;; threaded compression (introduced in
  525. ;; 5.2.0), but it ignores the extra flag.
  526. (string-append "--use-compress-program="
  527. #+xz "/bin/xz --threads=0")
  528. ;; avoid non-determinism in the archive
  529. "--mtime=@0"
  530. "--owner=root:0"
  531. "--group=root:0"
  532. (if tar-supports-sort?
  533. `("--sort=name"
  534. ,directory)
  535. '("--no-recursion"
  536. "--files-from=.file_list"))))))))))
  537. (let ((name (tarxz-name original-file-name)))
  538. (gexp->derivation name build
  539. #:graft? #f
  540. #:system system
  541. #:deprecation-warnings #t ;to avoid a rebuild
  542. #:guile-for-build guile-for-build))))
  543. (define (transitive-inputs inputs)
  544. "Return the closure of INPUTS when considering the 'propagated-inputs'
  545. edges. Omit duplicate inputs, except for those already present in INPUTS
  546. itself.
  547. This is implemented as a breadth-first traversal such that INPUTS is
  548. preserved, and only duplicate propagated inputs are removed."
  549. (define (seen? seen item outputs)
  550. (match (vhash-assq item seen)
  551. ((_ . o) (equal? o outputs))
  552. (_ #f)))
  553. (let loop ((inputs inputs)
  554. (result '())
  555. (propagated '())
  556. (first? #t)
  557. (seen vlist-null))
  558. (match inputs
  559. (()
  560. (if (null? propagated)
  561. (reverse result)
  562. (loop (reverse (concatenate propagated)) result '() #f seen)))
  563. (((and input (label (? package? package) outputs ...)) rest ...)
  564. (if (and (not first?) (seen? seen package outputs))
  565. (loop rest result propagated first? seen)
  566. (loop rest
  567. (cons input result)
  568. (cons (package-propagated-inputs package) propagated)
  569. first?
  570. (vhash-consq package outputs seen))))
  571. ((input rest ...)
  572. (loop rest (cons input result) propagated first? seen)))))
  573. (define (package-direct-sources package)
  574. "Return all source origins associated with PACKAGE; including origins in
  575. PACKAGE's inputs."
  576. `(,@(or (and=> (package-source package) list) '())
  577. ,@(filter-map (match-lambda
  578. ((_ (? origin? orig) _ ...)
  579. orig)
  580. (_ #f))
  581. (package-direct-inputs package))))
  582. (define (package-transitive-sources package)
  583. "Return PACKAGE's direct sources, and their direct sources, recursively."
  584. (delete-duplicates
  585. (concatenate (filter-map (match-lambda
  586. ((_ (? origin? orig) _ ...)
  587. (list orig))
  588. ((_ (? package? p) _ ...)
  589. (package-direct-sources p))
  590. (_ #f))
  591. (bag-transitive-inputs
  592. (package->bag package))))))
  593. (define (package-direct-inputs package)
  594. "Return all the direct inputs of PACKAGE---i.e, its direct inputs along
  595. with their propagated inputs."
  596. (append (package-native-inputs package)
  597. (package-inputs package)
  598. (package-propagated-inputs package)))
  599. (define (package-transitive-inputs package)
  600. "Return the transitive inputs of PACKAGE---i.e., its direct inputs along
  601. with their propagated inputs, recursively."
  602. (transitive-inputs (package-direct-inputs package)))
  603. (define (package-transitive-target-inputs package)
  604. "Return the transitive target inputs of PACKAGE---i.e., its direct inputs
  605. along with their propagated inputs, recursively. This only includes inputs
  606. for the target system, and not native inputs."
  607. (transitive-inputs (append (package-inputs package)
  608. (package-propagated-inputs package))))
  609. (define (package-transitive-native-inputs package)
  610. "Return the transitive native inputs of PACKAGE---i.e., its direct inputs
  611. along with their propagated inputs, recursively. This only includes inputs
  612. for the host system (\"native inputs\"), and not target inputs."
  613. (transitive-inputs (package-native-inputs package)))
  614. (define (package-transitive-propagated-inputs package)
  615. "Return the propagated inputs of PACKAGE, and their propagated inputs,
  616. recursively."
  617. (transitive-inputs (package-propagated-inputs package)))
  618. (define (package-transitive-native-search-paths package)
  619. "Return the list of search paths for PACKAGE and its propagated inputs,
  620. recursively."
  621. (append (package-native-search-paths package)
  622. (append-map (match-lambda
  623. ((label (? package? p) _ ...)
  624. (package-native-search-paths p))
  625. (_
  626. '()))
  627. (package-transitive-propagated-inputs package))))
  628. (define (transitive-input-references alist inputs)
  629. "Return a list of (assoc-ref ALIST <label>) for each (<label> <package> . _)
  630. in INPUTS and their transitive propagated inputs."
  631. (define label
  632. (match-lambda
  633. ((label . _)
  634. label)))
  635. (map (lambda (input)
  636. `(assoc-ref ,alist ,(label input)))
  637. (transitive-inputs inputs)))
  638. (define package-transitive-supported-systems
  639. (mlambdaq (package)
  640. "Return the intersection of the systems supported by PACKAGE and those
  641. supported by its dependencies."
  642. (fold (lambda (input systems)
  643. (match input
  644. ((label (? package? p) . _)
  645. (lset-intersection
  646. string=? systems (package-transitive-supported-systems p)))
  647. (_
  648. systems)))
  649. (package-supported-systems package)
  650. (bag-direct-inputs (package->bag package)))))
  651. (define* (supported-package? package #:optional (system (%current-system)))
  652. "Return true if PACKAGE is supported on SYSTEM--i.e., if PACKAGE and all its
  653. dependencies are known to build on SYSTEM."
  654. (member system (package-transitive-supported-systems package)))
  655. (define (bag-direct-inputs bag)
  656. "Same as 'package-direct-inputs', but applied to a bag."
  657. (append (bag-build-inputs bag)
  658. (bag-host-inputs bag)
  659. (bag-target-inputs bag)))
  660. (define (bag-transitive-inputs bag)
  661. "Same as 'package-transitive-inputs', but applied to a bag."
  662. (transitive-inputs (bag-direct-inputs bag)))
  663. (define (bag-transitive-build-inputs bag)
  664. "Same as 'package-transitive-native-inputs', but applied to a bag."
  665. (transitive-inputs (bag-build-inputs bag)))
  666. (define (bag-transitive-host-inputs bag)
  667. "Same as 'package-transitive-target-inputs', but applied to a bag."
  668. (transitive-inputs (bag-host-inputs bag)))
  669. (define (bag-transitive-target-inputs bag)
  670. "Return the \"target inputs\" of BAG, recursively."
  671. (transitive-inputs (bag-target-inputs bag)))
  672. (define* (package-mapping proc #:optional (cut? (const #f)))
  673. "Return a procedure that, given a package, applies PROC to all the packages
  674. depended on and returns the resulting package. The procedure stops recursion
  675. when CUT? returns true for a given package."
  676. (define (rewrite input)
  677. (match input
  678. ((label (? package? package) outputs ...)
  679. (let ((proc (if (cut? package) proc replace)))
  680. (cons* label (proc package) outputs)))
  681. (_
  682. input)))
  683. (define replace
  684. (mlambdaq (p)
  685. ;; Return a variant of P with PROC applied to P and its explicit
  686. ;; dependencies, recursively. Memoize the transformations. Failing to
  687. ;; do that, we would build a huge object graph with lots of duplicates,
  688. ;; which in turns prevents us from benefiting from memoization in
  689. ;; 'package-derivation'.
  690. (let ((p (proc p)))
  691. (package
  692. (inherit p)
  693. (location (package-location p))
  694. (inputs (map rewrite (package-inputs p)))
  695. (native-inputs (map rewrite (package-native-inputs p)))
  696. (propagated-inputs (map rewrite (package-propagated-inputs p)))))))
  697. replace)
  698. (define* (package-input-rewriting replacements
  699. #:optional (rewrite-name identity))
  700. "Return a procedure that, when passed a package, replaces its direct and
  701. indirect dependencies (but not its implicit inputs) according to REPLACEMENTS.
  702. REPLACEMENTS is a list of package pairs; the first element of each pair is the
  703. package to replace, and the second one is the replacement.
  704. Optionally, REWRITE-NAME is a one-argument procedure that takes the name of a
  705. package and returns its new name after rewrite."
  706. (define (rewrite p)
  707. (match (assq-ref replacements p)
  708. (#f (package
  709. (inherit p)
  710. (name (rewrite-name (package-name p)))))
  711. (new new)))
  712. (package-mapping rewrite (cut assq <> replacements)))
  713. (define-syntax-rule (package/inherit p overrides ...)
  714. "Like (package (inherit P) OVERRIDES ...), except that the same
  715. transformation is done to the package replacement, if any. P must be a bare
  716. identifier, and will be bound to either P or its replacement when evaluating
  717. OVERRIDES."
  718. (let loop ((p p))
  719. (package (inherit p)
  720. overrides ...
  721. (replacement (and=> (package-replacement p) loop)))))
  722. ;;;
  723. ;;; Package derivations.
  724. ;;;
  725. (define %derivation-cache
  726. ;; Package to derivation-path mapping.
  727. (make-weak-key-hash-table 100))
  728. (define (cache! cache package system thunk)
  729. "Memoize in CACHE the return values of THUNK as the derivation of PACKAGE on
  730. SYSTEM."
  731. ;; FIXME: This memoization should be associated with the open store, because
  732. ;; otherwise it breaks when switching to a different store.
  733. (let ((vals (call-with-values thunk list)))
  734. ;; Use `hashq-set!' instead of `hash-set!' because `hash' returns the
  735. ;; same value for all structs (as of Guile 2.0.6), and because pointer
  736. ;; equality is sufficient in practice.
  737. (hashq-set! cache package
  738. `((,system ,@vals)
  739. ,@(or (hashq-ref cache package) '())))
  740. (apply values vals)))
  741. (define-syntax cached
  742. (syntax-rules (=>)
  743. "Memoize the result of BODY for the arguments PACKAGE and SYSTEM.
  744. Return the cached result when available."
  745. ((_ (=> cache) package system body ...)
  746. (let ((thunk (lambda () body ...))
  747. (key system))
  748. (match (hashq-ref cache package)
  749. ((alist (... ...))
  750. (match (assoc-ref alist key)
  751. ((vals (... ...))
  752. (apply values vals))
  753. (#f
  754. (cache! cache package key thunk))))
  755. (#f
  756. (cache! cache package key thunk)))))
  757. ((_ package system body ...)
  758. (cached (=> %derivation-cache) package system body ...))))
  759. (define* (expand-input store package input system #:optional cross-system)
  760. "Expand INPUT, an input tuple, such that it contains only references to
  761. derivation paths or store paths. PACKAGE is only used to provide contextual
  762. information in exceptions."
  763. (define (intern file)
  764. ;; Add FILE to the store. Set the `recursive?' bit to #t, so that
  765. ;; file permissions are preserved.
  766. (add-to-store store (basename file) #t "sha256" file))
  767. (define derivation
  768. (if cross-system
  769. (cut package-cross-derivation store <> cross-system system
  770. #:graft? #f)
  771. (cut package-derivation store <> system #:graft? #f)))
  772. (match input
  773. (((? string? name) (? package? package))
  774. (list name (derivation package)))
  775. (((? string? name) (? package? package)
  776. (? string? sub-drv))
  777. (list name (derivation package)
  778. sub-drv))
  779. (((? string? name)
  780. (and (? string?) (? derivation-path?) drv))
  781. (list name drv))
  782. (((? string? name)
  783. (and (? string?) (? file-exists? file)))
  784. ;; Add FILE to the store. When FILE is in the sub-directory of a
  785. ;; store path, it needs to be added anyway, so it can be used as a
  786. ;; source.
  787. (list name (intern file)))
  788. (((? string? name) (? struct? source))
  789. ;; 'package-source-derivation' calls 'lower-object', which can throw
  790. ;; '&gexp-input-error'. However '&gexp-input-error' lacks source
  791. ;; location info, so we catch and rethrow here (XXX: not optimal
  792. ;; performance-wise).
  793. (guard (c ((gexp-input-error? c)
  794. (raise (condition
  795. (&package-input-error
  796. (package package)
  797. (input (gexp-error-invalid-input c)))))))
  798. (list name (package-source-derivation store source system))))
  799. (x
  800. (raise (condition (&package-input-error
  801. (package package)
  802. (input x)))))))
  803. (define %bag-cache
  804. ;; 'eq?' cache mapping packages to system+target+graft?-dependent bags.
  805. ;; It significantly speeds things up when doing repeated calls to
  806. ;; 'package->bag' as is the case when building a profile.
  807. (make-weak-key-hash-table 200))
  808. (define* (package->bag package #:optional
  809. (system (%current-system))
  810. (target (%current-target-system))
  811. #:key (graft? (%graft?)))
  812. "Compile PACKAGE into a bag for SYSTEM, possibly cross-compiled to TARGET,
  813. and return it."
  814. (cached (=> %bag-cache)
  815. package (list system target graft?)
  816. ;; Bind %CURRENT-SYSTEM and %CURRENT-TARGET-SYSTEM so that thunked
  817. ;; field values can refer to it.
  818. (parameterize ((%current-system system)
  819. (%current-target-system target))
  820. (match (if graft?
  821. (or (package-replacement package) package)
  822. package)
  823. (($ <package> name version source build-system
  824. args inputs propagated-inputs native-inputs
  825. self-native-input? outputs)
  826. (or (make-bag build-system (string-append name "-" version)
  827. #:system system
  828. #:target target
  829. #:source source
  830. #:inputs (append (inputs)
  831. (propagated-inputs))
  832. #:outputs outputs
  833. #:native-inputs `(,@(if (and target
  834. self-native-input?)
  835. `(("self" ,package))
  836. '())
  837. ,@(native-inputs))
  838. #:arguments (args))
  839. (raise (if target
  840. (condition
  841. (&package-cross-build-system-error
  842. (package package)))
  843. (condition
  844. (&package-error
  845. (package package)))))))))))
  846. (define %graft-cache
  847. ;; 'eq?' cache mapping package objects to a graft corresponding to their
  848. ;; replacement package.
  849. (make-weak-key-hash-table 200))
  850. (define (input-graft store system)
  851. "Return a procedure that, given a package with a graft, returns a graft, and
  852. #f otherwise."
  853. (match-lambda
  854. ((? package? package)
  855. (let ((replacement (package-replacement package)))
  856. (and replacement
  857. (cached (=> %graft-cache) package system
  858. (let ((orig (package-derivation store package system
  859. #:graft? #f))
  860. (new (package-derivation store replacement system
  861. #:graft? #t)))
  862. (graft
  863. (origin orig)
  864. (replacement new)))))))
  865. (x
  866. #f)))
  867. (define (input-cross-graft store target system)
  868. "Same as 'input-graft', but for cross-compilation inputs."
  869. (match-lambda
  870. ((? package? package)
  871. (let ((replacement (package-replacement package)))
  872. (and replacement
  873. (let ((orig (package-cross-derivation store package target system
  874. #:graft? #f))
  875. (new (package-cross-derivation store replacement
  876. target system
  877. #:graft? #t)))
  878. (graft
  879. (origin orig)
  880. (replacement new))))))
  881. (_
  882. #f)))
  883. (define* (fold-bag-dependencies proc seed bag
  884. #:key (native? #t))
  885. "Fold PROC over the packages BAG depends on. Each package is visited only
  886. once, in depth-first order. If NATIVE? is true, restrict to native
  887. dependencies; otherwise, restrict to target dependencies."
  888. (define bag-direct-inputs*
  889. (if native?
  890. (lambda (bag)
  891. (append (bag-build-inputs bag)
  892. (bag-target-inputs bag)
  893. (if (bag-target bag)
  894. '()
  895. (bag-host-inputs bag))))
  896. bag-host-inputs))
  897. (define nodes
  898. (match (bag-direct-inputs* bag)
  899. (((labels things _ ...) ...)
  900. things)))
  901. (let loop ((nodes nodes)
  902. (result seed)
  903. (visited (setq)))
  904. (match nodes
  905. (()
  906. result)
  907. (((? package? head) . tail)
  908. (if (set-contains? visited head)
  909. (loop tail result visited)
  910. (let ((inputs (bag-direct-inputs* (package->bag head))))
  911. (loop (match inputs
  912. (((labels things _ ...) ...)
  913. (append things tail)))
  914. (proc head result)
  915. (set-insert head visited)))))
  916. ((head . tail)
  917. (loop tail result visited)))))
  918. (define* (bag-grafts store bag)
  919. "Return the list of grafts potentially applicable to BAG. Potentially
  920. applicable grafts are collected by looking at direct or indirect dependencies
  921. of BAG that have a 'replacement'. Whether a graft is actually applicable
  922. depends on whether the outputs of BAG depend on the items the grafts refer
  923. to (see 'graft-derivation'.)"
  924. (define system (bag-system bag))
  925. (define target (bag-target bag))
  926. (define native-grafts
  927. (let ((->graft (input-graft store system)))
  928. (fold-bag-dependencies (lambda (package grafts)
  929. (match (->graft package)
  930. (#f grafts)
  931. (graft (cons graft grafts))))
  932. '()
  933. bag)))
  934. (define target-grafts
  935. (if target
  936. (let ((->graft (input-cross-graft store target system)))
  937. (fold-bag-dependencies (lambda (package grafts)
  938. (match (->graft package)
  939. (#f grafts)
  940. (graft (cons graft grafts))))
  941. '()
  942. bag
  943. #:native? #f))
  944. '()))
  945. ;; We can end up with several identical grafts if we stumble upon packages
  946. ;; that are not 'eq?' but map to the same derivation (this can happen when
  947. ;; using things like 'package-with-explicit-inputs'.) Hence the
  948. ;; 'delete-duplicates' call.
  949. (delete-duplicates
  950. (append native-grafts target-grafts)))
  951. (define* (package-grafts store package
  952. #:optional (system (%current-system))
  953. #:key target)
  954. "Return the list of grafts applicable to PACKAGE as built for SYSTEM and
  955. TARGET."
  956. (let* ((package (or (package-replacement package) package))
  957. (bag (package->bag package system target)))
  958. (bag-grafts store bag)))
  959. (define* (bag->derivation store bag
  960. #:optional context)
  961. "Return the derivation to build BAG for SYSTEM. Optionally, CONTEXT can be
  962. a package object describing the context in which the call occurs, for improved
  963. error reporting."
  964. (if (bag-target bag)
  965. (bag->cross-derivation store bag)
  966. (let* ((system (bag-system bag))
  967. (inputs (bag-transitive-inputs bag))
  968. (input-drvs (map (cut expand-input store context <> system)
  969. inputs))
  970. (paths (delete-duplicates
  971. (append-map (match-lambda
  972. ((_ (? package? p) _ ...)
  973. (package-native-search-paths
  974. p))
  975. (_ '()))
  976. inputs))))
  977. (apply (bag-build bag)
  978. store (bag-name bag) input-drvs
  979. #:search-paths paths
  980. #:outputs (bag-outputs bag) #:system system
  981. (bag-arguments bag)))))
  982. (define* (bag->cross-derivation store bag
  983. #:optional context)
  984. "Return the derivation to build BAG, which is actually a cross build.
  985. Optionally, CONTEXT can be a package object denoting the context of the call.
  986. This is an internal procedure."
  987. (let* ((system (bag-system bag))
  988. (target (bag-target bag))
  989. (host (bag-transitive-host-inputs bag))
  990. (host-drvs (map (cut expand-input store context <> system target)
  991. host))
  992. (target* (bag-transitive-target-inputs bag))
  993. (target-drvs (map (cut expand-input store context <> system)
  994. target*))
  995. (build (bag-transitive-build-inputs bag))
  996. (build-drvs (map (cut expand-input store context <> system)
  997. build))
  998. (all (append build target* host))
  999. (paths (delete-duplicates
  1000. (append-map (match-lambda
  1001. ((_ (? package? p) _ ...)
  1002. (package-search-paths p))
  1003. (_ '()))
  1004. all)))
  1005. (npaths (delete-duplicates
  1006. (append-map (match-lambda
  1007. ((_ (? package? p) _ ...)
  1008. (package-native-search-paths
  1009. p))
  1010. (_ '()))
  1011. all))))
  1012. (apply (bag-build bag)
  1013. store (bag-name bag)
  1014. #:native-drvs build-drvs
  1015. #:target-drvs (append host-drvs target-drvs)
  1016. #:search-paths paths
  1017. #:native-search-paths npaths
  1018. #:outputs (bag-outputs bag)
  1019. #:system system #:target target
  1020. (bag-arguments bag))))
  1021. (define* (package-derivation store package
  1022. #:optional (system (%current-system))
  1023. #:key (graft? (%graft?)))
  1024. "Return the <derivation> object of PACKAGE for SYSTEM."
  1025. ;; Compute the derivation and cache the result. Caching is important
  1026. ;; because some derivations, such as the implicit inputs of the GNU build
  1027. ;; system, will be queried many, many times in a row.
  1028. (cached package (cons system graft?)
  1029. (let* ((bag (package->bag package system #f #:graft? graft?))
  1030. (drv (bag->derivation store bag package)))
  1031. (if graft?
  1032. (match (bag-grafts store bag)
  1033. (()
  1034. drv)
  1035. (grafts
  1036. (let ((guile (package-derivation store (guile-2.0)
  1037. system #:graft? #f)))
  1038. ;; TODO: As an optimization, we can simply graft the tip
  1039. ;; of the derivation graph since 'graft-derivation'
  1040. ;; recurses anyway.
  1041. (graft-derivation store drv grafts
  1042. #:system system
  1043. #:guile guile))))
  1044. drv))))
  1045. (define* (package-cross-derivation store package target
  1046. #:optional (system (%current-system))
  1047. #:key (graft? (%graft?)))
  1048. "Cross-build PACKAGE for TARGET (a GNU triplet) from host SYSTEM (a Guix
  1049. system identifying string)."
  1050. (cached package (list system target graft?)
  1051. (let* ((bag (package->bag package system target #:graft? graft?))
  1052. (drv (bag->derivation store bag package)))
  1053. (if graft?
  1054. (match (bag-grafts store bag)
  1055. (()
  1056. drv)
  1057. (grafts
  1058. (graft-derivation store drv grafts
  1059. #:system system
  1060. #:guile
  1061. (package-derivation store (guile-2.0)
  1062. system #:graft? #f))))
  1063. drv))))
  1064. (define* (package-output store package
  1065. #:optional (output "out") (system (%current-system)))
  1066. "Return the output path of PACKAGE's OUTPUT for SYSTEM---where OUTPUT is the
  1067. symbolic output name, such as \"out\". Note that this procedure calls
  1068. `package-derivation', which is costly."
  1069. (let ((drv (package-derivation store package system)))
  1070. (derivation->output-path drv output)))
  1071. ;;;
  1072. ;;; Monadic interface.
  1073. ;;;
  1074. (define (set-guile-for-build guile)
  1075. "This monadic procedure changes the Guile currently used to run the build
  1076. code of derivations to GUILE, a package object."
  1077. (lambda (store)
  1078. (let ((guile (package-derivation store guile)))
  1079. (values (%guile-for-build guile) store))))
  1080. (define* (package-file package
  1081. #:optional file
  1082. #:key
  1083. system (output "out") target)
  1084. "Return as a monadic value the absolute file name of FILE within the
  1085. OUTPUT directory of PACKAGE. When FILE is omitted, return the name of the
  1086. OUTPUT directory of PACKAGE. When TARGET is true, use it as a
  1087. cross-compilation target triplet."
  1088. (lambda (store)
  1089. (define compute-derivation
  1090. (if target
  1091. (cut package-cross-derivation <> <> target <>)
  1092. package-derivation))
  1093. (let* ((system (or system (%current-system)))
  1094. (drv (compute-derivation store package system))
  1095. (out (derivation->output-path drv output)))
  1096. (values (if file
  1097. (string-append out "/" file)
  1098. out)
  1099. store))))
  1100. (define package->derivation
  1101. (store-lift package-derivation))
  1102. (define package->cross-derivation
  1103. (store-lift package-cross-derivation))
  1104. (define-gexp-compiler (package-compiler (package <package>) system target)
  1105. ;; Compile PACKAGE to a derivation for SYSTEM, optionally cross-compiled for
  1106. ;; TARGET. This is used when referring to a package from within a gexp.
  1107. (if target
  1108. (package->cross-derivation package target system)
  1109. (package->derivation package system)))
  1110. (define* (origin->derivation origin
  1111. #:optional (system (%current-system)))
  1112. "Return the derivation corresponding to ORIGIN."
  1113. (match origin
  1114. (($ <origin> uri method sha256 name (= force ()) #f)
  1115. ;; No patches, no snippet: this is a fixed-output derivation.
  1116. (method uri 'sha256 sha256 name #:system system))
  1117. (($ <origin> uri method sha256 name (= force (patches ...)) snippet
  1118. (flags ...) inputs (modules ...) guile-for-build)
  1119. ;; Patches and/or a snippet.
  1120. (mlet %store-monad ((source (method uri 'sha256 sha256 name
  1121. #:system system))
  1122. (guile (package->derivation (or guile-for-build
  1123. (default-guile))
  1124. system
  1125. #:graft? #f)))
  1126. (patch-and-repack source patches
  1127. #:inputs inputs
  1128. #:snippet snippet
  1129. #:flags flags
  1130. #:system system
  1131. #:modules modules
  1132. #:guile-for-build guile)))))
  1133. (define-gexp-compiler (origin-compiler (origin <origin>) system target)
  1134. ;; Compile ORIGIN to a derivation for SYSTEM. This is used when referring
  1135. ;; to an origin from within a gexp.
  1136. (origin->derivation origin system))
  1137. (define package-source-derivation ;somewhat deprecated
  1138. (let ((lower (store-lower lower-object)))
  1139. (lambda* (store source #:optional (system (%current-system)))
  1140. "Return the derivation or file corresponding to SOURCE, which can be an
  1141. a file name or any object handled by 'lower-object', such as an <origin>.
  1142. When SOURCE is a file name, return either the interned file name (if SOURCE is
  1143. outside of the store) or SOURCE itself (if SOURCE is already a store item.)"
  1144. (match source
  1145. ((and (? string?) (? direct-store-path?) file)
  1146. file)
  1147. ((? string? file)
  1148. (add-to-store store (basename file) #t "sha256" file))
  1149. (_
  1150. (lower store source system))))))