1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix packages)
21 #:use-module (guix utils)
22 #:use-module (guix records)
23 #:use-module (guix store)
24 #:use-module (guix monads)
25 #:use-module (guix gexp)
26 #:use-module (guix base32)
27 #:use-module (guix derivations)
28 #:use-module (guix build-system)
29 #:use-module (guix search-paths)
30 #:use-module (guix gexp)
31 #:use-module (ice-9 match)
32 #:use-module (ice-9 vlist)
33 #:use-module (srfi srfi-1)
34 #:use-module (srfi srfi-9 gnu)
35 #:use-module (srfi srfi-11)
36 #:use-module (srfi srfi-26)
37 #:use-module (srfi srfi-34)
38 #:use-module (srfi srfi-35)
39 #:re-export (%current-system
40 %current-target-system
41 search-path-specification) ;for convenience
54 origin-imported-modules
67 package-propagated-inputs
69 package-native-search-paths
76 package-supported-systems
80 package-field-location
82 package-direct-sources
83 package-transitive-sources
85 package-transitive-inputs
86 package-transitive-target-inputs
87 package-transitive-native-inputs
88 package-transitive-propagated-inputs
89 package-transitive-supported-systems
90 package-source-derivation
92 package-cross-derivation
98 %hydra-supported-systems
103 package-error-package
106 package-error-invalid-input
107 &package-cross-build-system-error
108 package-cross-build-system-error?
113 bag-transitive-inputs
114 bag-transitive-host-inputs
115 bag-transitive-build-inputs
116 bag-transitive-target-inputs
119 default-guile-derivation
123 package->cross-derivation
128 ;;; This module provides a high-level mechanism to define packages in a
129 ;;; Guix-based distribution.
133 ;; The source of a package, such as a tarball URL and fetcher---called
134 ;; "origin" to avoid name clash with `package-source', `source', etc.
135 (define-record-type* <origin>
138 (uri origin-uri) ; string
139 (method origin-method) ; procedure
140 (sha256 origin-sha256) ; bytevector
141 (file-name origin-file-name (default #f)) ; optional file name
143 ;; Patches are delayed so that the 'search-patch' calls are made lazily,
144 ;; which reduces I/O on startup and allows patch-not-found errors to be
145 ;; gracefully handled at run time.
146 (patches origin-patches ; list of file names
147 (default '()) (delayed))
149 (snippet origin-snippet (default #f)) ; sexp or #f
150 (patch-flags origin-patch-flags ; list of strings
153 ;; Patching requires Guile, GNU Patch, and a few more. These two fields are
154 ;; used to specify these dependencies when needed.
155 (patch-inputs origin-patch-inputs ; input list or #f
157 (modules origin-modules ; list of module names
159 (imported-modules origin-imported-modules ; list of module names
161 (patch-guile origin-patch-guile ; package or #f
164 (define (print-origin origin port)
165 "Write a concise representation of ORIGIN to PORT."
167 (($ <origin> uri method sha256 file-name patches)
168 (simple-format port "#<origin ~s ~a ~s ~a>"
169 uri (bytevector->base32-string sha256)
171 (number->string (object-address origin) 16)))))
173 (set-record-type-printer! <origin> print-origin)
175 (define-syntax base32
177 "Return the bytevector corresponding to the given Nix-base32
181 (string? (syntax->datum #'str))
182 ;; A literal string: do the conversion at expansion time.
183 (with-syntax ((bv (nix-base32-string->bytevector
184 (syntax->datum #'str))))
187 #'(nix-base32-string->bytevector str)))))
189 (define %supported-systems
190 ;; This is the list of system types that are supported. By default, we
191 ;; expect all packages to build successfully here.
192 '("x86_64-linux" "i686-linux" "armhf-linux" "mips64el-linux"))
194 (define %hurd-systems
195 ;; The GNU/Hurd systems for which support is being developed.
196 '("i585-gnu" "i686-gnu"))
198 (define %hydra-supported-systems
199 ;; This is the list of system types for which build slaves are available.
204 (define-record-type* <package>
207 (name package-name) ; string
208 (version package-version) ; string
209 (source package-source) ; <origin> instance
210 (build-system package-build-system) ; build system
211 (arguments package-arguments ; arguments for the build method
212 (default '()) (thunked))
214 (inputs package-inputs ; input packages or derivations
215 (default '()) (thunked))
216 (propagated-inputs package-propagated-inputs ; same, but propagated
217 (default '()) (thunked))
218 (native-inputs package-native-inputs ; native input packages/derivations
219 (default '()) (thunked))
220 (self-native-input? package-self-native-input? ; whether to use itself as
221 ; a native input when cross-
222 (default #f)) ; compiling
224 (outputs package-outputs ; list of strings
228 ; <search-path-specification>,
229 ; for native and cross
231 (native-search-paths package-native-search-paths (default '()))
232 (search-paths package-search-paths (default '()))
233 (replacement package-replacement ; package | #f
234 (default #f) (thunked))
236 (synopsis package-synopsis) ; one-line description
237 (description package-description) ; one or two paragraphs
238 (license package-license)
239 (home-page package-home-page)
240 (supported-systems package-supported-systems ; list of strings
241 (default %supported-systems))
242 (maintainers package-maintainers (default '()))
244 (properties package-properties (default '())) ; alist for anything else
246 (location package-location
247 (default (and=> (current-source-location)
248 source-properties->location))
251 (set-record-type-printer! <package>
252 (lambda (package port)
253 (let ((loc (package-location package))
254 (format simple-format))
255 (format port "#<package ~a-~a ~a~a>"
256 (package-name package)
257 (package-version package)
263 (number->string (object-address
267 (define (package-field-location package field)
268 "Return the source code location of the definition of FIELD for PACKAGE, or
269 #f if it could not be determined."
270 (define (goto port line column)
271 (unless (and (= (port-column port) (- column 1))
272 (= (port-line port) (- line 1)))
273 (unless (eof-object? (read-char port))
274 (goto port line column))))
276 (match (package-location package)
277 (($ <location> file line column)
280 ;; In general we want to keep relative file names for modules.
281 (with-fluids ((%file-port-name-canonicalization 'relative))
282 (call-with-input-file (search-path %load-path file)
284 (goto port line column)
286 (('package inits ...)
287 (let ((field (assoc field inits)))
290 ;; Put the `or' here, and not in the first argument of
291 ;; `and=>', to work around a compiler bug in 2.0.5.
292 (or (and=> (source-properties value)
293 source-properties->location)
294 (and=> (source-properties field)
295 source-properties->location)))
307 (define-condition-type &package-error &error
309 (package package-error-package))
311 (define-condition-type &package-input-error &package-error
313 (input package-error-invalid-input))
315 (define-condition-type &package-cross-build-system-error &package-error
316 package-cross-build-system-error?)
319 (define (package-full-name package)
320 "Return the full name of PACKAGE--i.e., `NAME-VERSION'."
321 (string-append (package-name package) "-" (package-version package)))
323 (define (%standard-patch-inputs)
324 (let* ((canonical (module-ref (resolve-interface '(gnu packages base))
326 (ref (lambda (module var)
328 (module-ref (resolve-interface module) var)))))
329 `(("tar" ,(ref '(gnu packages base) 'tar))
330 ("xz" ,(ref '(gnu packages compression) 'xz))
331 ("bzip2" ,(ref '(gnu packages compression) 'bzip2))
332 ("gzip" ,(ref '(gnu packages compression) 'gzip))
333 ("lzip" ,(ref '(gnu packages compression) 'lzip))
334 ("unzip" ,(ref '(gnu packages zip) 'unzip))
335 ("patch" ,(ref '(gnu packages base) 'patch))
336 ("locales" ,(ref '(gnu packages base) 'glibc-utf8-locales)))))
338 (define (default-guile)
339 "Return the default Guile package used to run the build code of
341 (let ((distro (resolve-interface '(gnu packages commencement))))
342 (module-ref distro 'guile-final)))
344 (define* (default-guile-derivation #:optional (system (%current-system)))
345 "Return the derivation for SYSTEM of the default Guile package used to run
346 the build code of derivation."
347 (package->derivation (default-guile) system
350 (define* (patch-and-repack source patches
356 (imported-modules '())
357 (guile-for-build (%guile-for-build))
358 (system (%current-system)))
359 "Unpack SOURCE (a derivation or store path), apply all of PATCHES, and
360 repack the tarball using the tools listed in INPUTS. When SNIPPET is true,
361 it must be an s-expression that will run from within the directory where
362 SOURCE was unpacked, after all of PATCHES have been applied. MODULES and
363 IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
364 (define source-file-name
365 ;; SOURCE is usually a derivation, but it could be a store file.
366 (if (derivation? source)
367 (derivation->output-path source)
371 ;; The default value of the 'patch-inputs' field, and thus INPUTS is #f,
372 ;; so deal with that.
373 (let ((inputs (or inputs (%standard-patch-inputs))))
375 (match (assoc-ref inputs name)
379 (define decompression-type
380 (cond ((string-suffix? "gz" source-file-name) "gzip")
381 ((string-suffix? "bz2" source-file-name) "bzip2")
382 ((string-suffix? "lz" source-file-name) "lzip")
383 ((string-suffix? "zip" source-file-name) "unzip")
386 (define original-file-name
387 ;; Remove the store prefix plus the slash, hash, and hyphen.
388 (let* ((sans (string-drop source-file-name
389 (+ (string-length (%store-prefix)) 1)))
390 (dash (string-index sans #\-)))
391 (string-drop sans (+ 1 dash))))
393 (define (numeric-extension? file-name)
394 ;; Return true if FILE-NAME ends with digits.
395 (and=> (file-extension file-name)
396 (cut string-every char-set:hex-digit <>)))
398 (define (tarxz-name file-name)
399 ;; Return a '.tar.xz' file name based on FILE-NAME.
400 (let ((base (if (numeric-extension? file-name)
402 (file-sans-extension file-name))))
404 (if (equal? (file-extension base) "tar")
408 (define instantiate-patch
411 (interned-file patch #:recursive? #t))
413 (origin->derivation patch system))))
415 (mlet %store-monad ((tar -> (lookup-input "tar"))
416 (xz -> (lookup-input "xz"))
417 (patch -> (lookup-input "patch"))
418 (locales -> (lookup-input "locales"))
419 (decomp -> (lookup-input decompression-type))
420 (patches (sequence %store-monad
421 (map instantiate-patch patches))))
424 (use-modules (ice-9 ftw)
428 ;; The --sort option was added to GNU tar in version 1.28, released
429 ;; 2014-07-28. During bootstrap we must cope with older versions.
430 (define tar-supports-sort?
431 (zero? (system* (string-append #+tar "/bin/tar")
432 "cf" "/dev/null" "--files-from=/dev/null"
435 (define (apply-patch patch)
436 (format (current-error-port) "applying '~a'...~%" patch)
438 ;; Use '--force' so that patches that do not apply perfectly are
440 (zero? (system* (string-append #+patch "/bin/patch")
441 "--force" #+@flags "--input" patch)))
443 (define (first-file directory)
444 ;; Return the name of the first file in DIRECTORY.
445 (car (scandir directory
447 (not (member name '("." "..")))))))
449 ;; Encoding/decoding errors shouldn't be silent.
450 (fluid-set! %default-port-conversion-strategy 'error)
453 ;; First of all, install a UTF-8 locale so that UTF-8 file names
454 ;; are correctly interpreted. During bootstrap, LOCALES is #f.
455 (setenv "LOCPATH" (string-append #+locales "/lib/locale"))
456 (setlocale LC_ALL "en_US.UTF-8"))
458 (setenv "PATH" (string-append #+xz "/bin" ":"
461 ;; SOURCE may be either a directory or a tarball.
462 (and (if (file-is-directory? #+source)
463 (let* ((store (%store-directory))
464 (len (+ 1 (string-length store)))
465 (base (string-drop #+source len))
466 (dash (string-index base #\-))
467 (directory (string-drop base (+ 1 dash))))
469 (copy-recursively #+source directory)
471 #+(if (string=? decompression-type "unzip")
472 #~(zero? (system* "unzip" #+source))
473 #~(zero? (system* (string-append #+tar "/bin/tar")
475 (let ((directory (first-file ".")))
476 (format (current-error-port)
477 "source is under '~a'~%" directory)
480 (and (every apply-patch '#+patches)
482 #~((let ((module (make-fresh-user-module)))
483 (module-use-interfaces! module
484 (map resolve-interface
486 ((@ (system base compile) compile)
489 #:opts %auto-compilation-options
493 (begin (chdir "..") #t)
495 (unless tar-supports-sort?
496 (call-with-output-file ".file_list"
498 (for-each (lambda (name) (format port "~a~%" name))
499 (find-files directory
501 #:fail-on-error? #t)))))
502 (zero? (apply system* (string-append #+tar "/bin/tar")
504 ;; avoid non-determinism in the archive
508 (if tar-supports-sort?
512 "--files-from=.file_list")))))))))
514 (let ((name (tarxz-name original-file-name))
515 (modules (delete-duplicates (cons '(guix build utils) modules))))
516 (gexp->derivation name build
520 #:guile-for-build guile-for-build))))
522 (define (transitive-inputs inputs)
523 "Return the closure of INPUTS when considering the 'propagated-inputs'
524 edges. Omit duplicate inputs, except for those already present in INPUTS
527 This is implemented as a breadth-first traversal such that INPUTS is
528 preserved, and only duplicate propagated inputs are removed."
529 (define (seen? seen item outputs)
530 (match (vhash-assq item seen)
531 ((_ . o) (equal? o outputs))
534 (let loop ((inputs inputs)
541 (if (null? propagated)
543 (loop (reverse (concatenate propagated)) result '() #f seen)))
544 (((and input (label (? package? package) outputs ...)) rest ...)
545 (if (and (not first?) (seen? seen package outputs))
546 (loop rest result propagated first? seen)
549 (cons (package-propagated-inputs package) propagated)
551 (vhash-consq package outputs seen))))
553 (loop rest (cons input result) propagated first? seen)))))
555 (define (package-direct-sources package)
556 "Return all source origins associated with PACKAGE; including origins in
558 `(,@(or (and=> (package-source package) list) '())
559 ,@(filter-map (match-lambda
560 ((_ (? origin? orig) _ ...)
563 (package-direct-inputs package))))
565 (define (package-transitive-sources package)
566 "Return PACKAGE's direct sources, and their direct sources, recursively."
568 (concatenate (filter-map (match-lambda
569 ((_ (? origin? orig) _ ...)
571 ((_ (? package? p) _ ...)
572 (package-direct-sources p))
574 (bag-transitive-inputs
575 (package->bag package))))))
577 (define (package-direct-inputs package)
578 "Return all the direct inputs of PACKAGE---i.e, its direct inputs along
579 with their propagated inputs."
580 (append (package-native-inputs package)
581 (package-inputs package)
582 (package-propagated-inputs package)))
584 (define (package-transitive-inputs package)
585 "Return the transitive inputs of PACKAGE---i.e., its direct inputs along
586 with their propagated inputs, recursively."
587 (transitive-inputs (package-direct-inputs package)))
589 (define (package-transitive-target-inputs package)
590 "Return the transitive target inputs of PACKAGE---i.e., its direct inputs
591 along with their propagated inputs, recursively. This only includes inputs
592 for the target system, and not native inputs."
593 (transitive-inputs (append (package-inputs package)
594 (package-propagated-inputs package))))
596 (define (package-transitive-native-inputs package)
597 "Return the transitive native inputs of PACKAGE---i.e., its direct inputs
598 along with their propagated inputs, recursively. This only includes inputs
599 for the host system (\"native inputs\"), and not target inputs."
600 (transitive-inputs (package-native-inputs package)))
602 (define (package-transitive-propagated-inputs package)
603 "Return the propagated inputs of PACKAGE, and their propagated inputs,
605 (transitive-inputs (package-propagated-inputs package)))
607 (define-syntax define-memoized/v
609 "Define a memoized single-valued unary procedure with docstring.
610 The procedure argument is compared to cached keys using `eqv?'."
612 ((_ (proc arg) docstring body body* ...)
613 (string? (syntax->datum #'docstring))
615 (let ((cache (make-hash-table)))
618 (match (hashv-get-handle cache arg)
622 (let ((result (let () body body* ...)))
623 (hashv-set! cache arg result)
627 (define-memoized/v (package-transitive-supported-systems package)
628 "Return the intersection of the systems supported by PACKAGE and those
629 supported by its dependencies."
630 (fold (lambda (input systems)
632 ((label (? package? p) . _)
634 string=? systems (package-transitive-supported-systems p)))
637 (package-supported-systems package)
638 (bag-direct-inputs (package->bag package))))
640 (define* (supported-package? package #:optional (system (%current-system)))
641 "Return true if PACKAGE is supported on SYSTEM--i.e., if PACKAGE and all its
642 dependencies are known to build on SYSTEM."
643 (member system (package-transitive-supported-systems package)))
645 (define (bag-direct-inputs bag)
646 "Same as 'package-direct-inputs', but applied to a bag."
647 (append (bag-build-inputs bag)
648 (bag-host-inputs bag)
649 (bag-target-inputs bag)))
651 (define (bag-transitive-inputs bag)
652 "Same as 'package-transitive-inputs', but applied to a bag."
653 (transitive-inputs (bag-direct-inputs bag)))
655 (define (bag-transitive-build-inputs bag)
656 "Same as 'package-transitive-native-inputs', but applied to a bag."
657 (transitive-inputs (bag-build-inputs bag)))
659 (define (bag-transitive-host-inputs bag)
660 "Same as 'package-transitive-target-inputs', but applied to a bag."
661 (transitive-inputs (bag-host-inputs bag)))
663 (define (bag-transitive-target-inputs bag)
664 "Return the \"target inputs\" of BAG, recursively."
665 (transitive-inputs (bag-target-inputs bag)))
669 ;;; Package derivations.
672 (define %derivation-cache
673 ;; Package to derivation-path mapping.
674 (make-weak-key-hash-table 100))
676 (define (cache package system thunk)
677 "Memoize the return values of THUNK as the derivation of PACKAGE on
679 ;; FIXME: This memoization should be associated with the open store, because
680 ;; otherwise it breaks when switching to a different store.
681 (let ((vals (call-with-values thunk list)))
682 ;; Use `hashq-set!' instead of `hash-set!' because `hash' returns the
683 ;; same value for all structs (as of Guile 2.0.6), and because pointer
684 ;; equality is sufficient in practice.
685 (hashq-set! %derivation-cache package
687 ,@(or (hashq-ref %derivation-cache package)
689 (apply values vals)))
691 (define-syntax-rule (cached package system body ...)
692 "Memoize the result of BODY for the arguments PACKAGE and SYSTEM.
693 Return the cached result when available."
694 (let ((thunk (lambda () body ...))
696 (match (hashq-ref %derivation-cache package)
698 (match (assoc-ref alist key)
702 (cache package key thunk))))
704 (cache package key thunk)))))
706 (define* (expand-input store package input system #:optional cross-system)
707 "Expand INPUT, an input tuple, such that it contains only references to
708 derivation paths or store paths. PACKAGE is only used to provide contextual
709 information in exceptions."
710 (define (intern file)
711 ;; Add FILE to the store. Set the `recursive?' bit to #t, so that
712 ;; file permissions are preserved.
713 (add-to-store store (basename file) #t "sha256" file))
717 (cut package-cross-derivation store <> cross-system system
719 (cut package-derivation store <> system #:graft? #f)))
722 (((? string? name) (? package? package))
723 (list name (derivation package)))
724 (((? string? name) (? package? package)
726 (list name (derivation package)
729 (and (? string?) (? derivation-path?) drv))
732 (and (? string?) (? file-exists? file)))
733 ;; Add FILE to the store. When FILE is in the sub-directory of a
734 ;; store path, it needs to be added anyway, so it can be used as a
736 (list name (intern file)))
737 (((? string? name) (? origin? source))
738 (list name (package-source-derivation store source system)))
740 (raise (condition (&package-input-error
744 (define* (package->bag package #:optional
745 (system (%current-system))
746 (target (%current-target-system))
747 #:key (graft? (%graft?)))
748 "Compile PACKAGE into a bag for SYSTEM, possibly cross-compiled to TARGET,
750 ;; Bind %CURRENT-SYSTEM and %CURRENT-TARGET-SYSTEM so that thunked field
751 ;; values can refer to it.
752 (parameterize ((%current-system system)
753 (%current-target-system target))
755 (or (package-replacement package) package)
757 (($ <package> name version source build-system
758 args inputs propagated-inputs native-inputs self-native-input?
760 (or (make-bag build-system (string-append name "-" version)
764 #:inputs (append (inputs)
767 #:native-inputs `(,@(if (and target self-native-input?)
774 (&package-cross-build-system-error
778 (package package))))))))))
780 (define (input-graft store system)
781 "Return a procedure that, given an input referring to a package with a
782 graft, returns a pair with the original derivation and the graft's derivation,
783 and returns #f for other inputs."
785 ((label (? package? package) sub-drv ...)
786 (let ((replacement (package-replacement package)))
788 (let ((orig (package-derivation store package system
790 (new (package-derivation store replacement system)))
794 (origin-output (match sub-drv
797 (replacement-output origin-output))))))
801 (define (input-cross-graft store target system)
802 "Same as 'input-graft', but for cross-compilation inputs."
804 ((label (? package? package) sub-drv ...)
805 (let ((replacement (package-replacement package)))
807 (let ((orig (package-cross-derivation store package target system
809 (new (package-cross-derivation store replacement
814 (origin-output (match sub-drv
817 (replacement-output origin-output))))))
821 (define* (bag-grafts store bag)
822 "Return the list of grafts applicable to BAG. Each graft is a <graft>
824 (let ((target (bag-target bag))
825 (system (bag-system bag)))
826 (define native-grafts
827 (filter-map (input-graft store system)
828 (append (bag-transitive-build-inputs bag)
829 (bag-transitive-target-inputs bag)
832 (bag-transitive-host-inputs bag)))))
834 (define target-grafts
836 (filter-map (input-cross-graft store target system)
837 (bag-transitive-host-inputs bag))
840 (append native-grafts target-grafts)))
842 (define* (package-grafts store package
843 #:optional (system (%current-system))
845 "Return the list of grafts applicable to PACKAGE as built for SYSTEM and
847 (let* ((package (or (package-replacement package) package))
848 (bag (package->bag package system target)))
849 (bag-grafts store bag)))
851 (define* (bag->derivation store bag
853 "Return the derivation to build BAG for SYSTEM. Optionally, CONTEXT can be
854 a package object describing the context in which the call occurs, for improved
857 (bag->cross-derivation store bag)
858 (let* ((system (bag-system bag))
859 (inputs (bag-transitive-inputs bag))
860 (input-drvs (map (cut expand-input store context <> system)
862 (paths (delete-duplicates
863 (append-map (match-lambda
864 ((_ (? package? p) _ ...)
865 (package-native-search-paths
870 (apply (bag-build bag)
871 store (bag-name bag) input-drvs
873 #:outputs (bag-outputs bag) #:system system
874 (bag-arguments bag)))))
876 (define* (bag->cross-derivation store bag
878 "Return the derivation to build BAG, which is actually a cross build.
879 Optionally, CONTEXT can be a package object denoting the context of the call.
880 This is an internal procedure."
881 (let* ((system (bag-system bag))
882 (target (bag-target bag))
883 (host (bag-transitive-host-inputs bag))
884 (host-drvs (map (cut expand-input store context <> system target)
886 (target* (bag-transitive-target-inputs bag))
887 (target-drvs (map (cut expand-input store context <> system)
889 (build (bag-transitive-build-inputs bag))
890 (build-drvs (map (cut expand-input store context <> system)
892 (all (append build target* host))
893 (paths (delete-duplicates
894 (append-map (match-lambda
895 ((_ (? package? p) _ ...)
896 (package-search-paths p))
899 (npaths (delete-duplicates
900 (append-map (match-lambda
901 ((_ (? package? p) _ ...)
902 (package-native-search-paths
907 (apply (bag-build bag)
909 #:native-drvs build-drvs
910 #:target-drvs (append host-drvs target-drvs)
912 #:native-search-paths npaths
913 #:outputs (bag-outputs bag)
914 #:system system #:target target
915 (bag-arguments bag))))
917 (define* (package-derivation store package
918 #:optional (system (%current-system))
919 #:key (graft? (%graft?)))
920 "Return the <derivation> object of PACKAGE for SYSTEM."
922 ;; Compute the derivation and cache the result. Caching is important
923 ;; because some derivations, such as the implicit inputs of the GNU build
924 ;; system, will be queried many, many times in a row.
925 (cached package (cons system graft?)
926 (let* ((bag (package->bag package system #f #:graft? graft?))
927 (drv (bag->derivation store bag package)))
929 (match (bag-grafts store bag)
933 (let ((guile (package-derivation store (default-guile)
934 system #:graft? #f)))
935 (graft-derivation store (bag-name bag) drv grafts
940 (define* (package-cross-derivation store package target
941 #:optional (system (%current-system))
942 #:key (graft? (%graft?)))
943 "Cross-build PACKAGE for TARGET (a GNU triplet) from host SYSTEM (a Guix
944 system identifying string)."
945 (cached package (list system target graft?)
946 (let* ((bag (package->bag package system target #:graft? graft?))
947 (drv (bag->derivation store bag package)))
949 (match (bag-grafts store bag)
953 (graft-derivation store (bag-name bag) drv grafts
956 (package-derivation store (default-guile)
957 system #:graft? #f))))
960 (define* (package-output store package
961 #:optional (output "out") (system (%current-system)))
962 "Return the output path of PACKAGE's OUTPUT for SYSTEM---where OUTPUT is the
963 symbolic output name, such as \"out\". Note that this procedure calls
964 `package-derivation', which is costly."
965 (let ((drv (package-derivation store package system)))
966 (derivation->output-path drv output)))
970 ;;; Monadic interface.
973 (define (set-guile-for-build guile)
974 "This monadic procedure changes the Guile currently used to run the build
975 code of derivations to GUILE, a package object."
977 (let ((guile (package-derivation store guile)))
978 (values (%guile-for-build guile) store))))
980 (define* (package-file package
983 system (output "out") target)
984 "Return as a monadic value the absolute file name of FILE within the
985 OUTPUT directory of PACKAGE. When FILE is omitted, return the name of the
986 OUTPUT directory of PACKAGE. When TARGET is true, use it as a
987 cross-compilation target triplet."
989 (define compute-derivation
991 (cut package-cross-derivation <> <> target <>)
994 (let* ((system (or system (%current-system)))
995 (drv (compute-derivation store package system))
996 (out (derivation->output-path drv output)))
998 (string-append out "/" file)
1002 (define package->derivation
1003 (store-lift package-derivation))
1005 (define package->cross-derivation
1006 (store-lift package-cross-derivation))
1008 (define-gexp-compiler (package-compiler (package package?) system target)
1009 ;; Compile PACKAGE to a derivation for SYSTEM, optionally cross-compiled for
1010 ;; TARGET. This is used when referring to a package from within a gexp.
1012 (package->cross-derivation package target system)
1013 (package->derivation package system)))
1015 (define* (origin->derivation source
1016 #:optional (system (%current-system)))
1017 "When SOURCE is an <origin> object, return its derivation for SYSTEM. When
1018 SOURCE is a file name, return either the interned file name (if SOURCE is
1019 outside of the store) or SOURCE itself (if SOURCE is already a store item.)"
1021 (($ <origin> uri method sha256 name (= force ()) #f)
1022 ;; No patches, no snippet: this is a fixed-output derivation.
1023 (method uri 'sha256 sha256 name #:system system))
1024 (($ <origin> uri method sha256 name (= force (patches ...)) snippet
1025 (flags ...) inputs (modules ...) (imported-modules ...)
1027 ;; Patches and/or a snippet.
1028 (mlet %store-monad ((source (method uri 'sha256 sha256 name
1030 (guile (package->derivation (or guile-for-build
1034 (patch-and-repack source patches
1040 #:imported-modules modules
1041 #:guile-for-build guile)))
1042 ((and (? string?) (? direct-store-path?) file)
1043 (with-monad %store-monad
1046 (interned-file file (basename file)
1049 (define-gexp-compiler (origin-compiler (origin origin?) system target)
1050 ;; Compile ORIGIN to a derivation for SYSTEM. This is used when referring
1051 ;; to an origin from within a gexp.
1052 (origin->derivation origin system))
1054 (define package-source-derivation
1055 (store-lower origin->derivation))