summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-11-26 22:14:11 +0100
committerLudovic Courtès <ludo@gnu.org>2018-11-28 10:39:58 +0100
commit8856f409d13cd7376be4319b9f75df0692c009d6 (patch)
tree74855d6b0c022dc1409b98301b799d93524e2a0d
parent01e7ca5410e45f63a39f16a6e8156f3e0898141a (diff)
derivations: Add properties.
* guix/derivations.scm (derivation): Add #:properties parameter. [user+system-env-vars]: Honor it. (derivation-properties): New procedure. (build-expression->derivation): Add #:properties and pass it to 'derivation'. * guix/gexp.scm (gexp->derivation): Likewise. * tests/derivations.scm ("derivation-properties"): New test. * tests/gexp.scm ("gexp->derivation properties"): New test. * doc/guix.texi (Derivations, G-Expressions): Adjust accordingly.
-rw-r--r--doc/guix.texi8
-rw-r--r--guix/derivations.scm30
-rw-r--r--guix/gexp.scm4
-rw-r--r--tests/derivations.scm10
-rw-r--r--tests/gexp.scm10
5 files changed, 53 insertions, 9 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 917a3e9d57b..c040a8531ab 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -5060,7 +5060,7 @@ a derivation is the @code{derivation} procedure:
5060 [#:system (%current-system)] [#:references-graphs #f] @ 5060 [#:system (%current-system)] [#:references-graphs #f] @
5061 [#:allowed-references #f] [#:disallowed-references #f] @ 5061 [#:allowed-references #f] [#:disallowed-references #f] @
5062 [#:leaked-env-vars #f] [#:local-build? #f] @ 5062 [#:leaked-env-vars #f] [#:local-build? #f] @
5063 [#:substitutable? #t] 5063 [#:substitutable? #t] [#:properties '()]
5064Build a derivation with the given arguments, and return the resulting 5064Build a derivation with the given arguments, and return the resulting
5065@code{<derivation>} object. 5065@code{<derivation>} object.
5066 5066
@@ -5097,6 +5097,9 @@ When @var{substitutable?} is false, declare that substitutes of the
5097derivation's output should not be used (@pxref{Substitutes}). This is 5097derivation's output should not be used (@pxref{Substitutes}). This is
5098useful, for instance, when building packages that capture details of the 5098useful, for instance, when building packages that capture details of the
5099host CPU instruction set. 5099host CPU instruction set.
5100
5101@var{properties} must be an association list describing ``properties'' of the
5102derivation. It is kept as-is, uninterpreted, in the derivation.
5100@end deffn 5103@end deffn
5101 5104
5102@noindent 5105@noindent
@@ -5790,7 +5793,8 @@ information about monads.)
5790 [#:leaked-env-vars #f] @ 5793 [#:leaked-env-vars #f] @
5791 [#:script-name (string-append @var{name} "-builder")] @ 5794 [#:script-name (string-append @var{name} "-builder")] @
5792 [#:deprecation-warnings #f] @ 5795 [#:deprecation-warnings #f] @
5793 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f] 5796 [#:local-build? #f] [#:substitutable? #t] @
5797 [#:properties '()] [#:guile-for-build #f]
5794Return a derivation @var{name} that runs @var{exp} (a gexp) with 5798Return a derivation @var{name} that runs @var{exp} (a gexp) with
5795@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is 5799@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
5796stored in a file called @var{script-name}. When @var{target} is true, 5800stored in a file called @var{script-name}. When @var{target} is true,
diff --git a/guix/derivations.scm b/guix/derivations.scm
index 7afecb10cc9..f6176a78fdd 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -80,6 +80,7 @@
80 substitutable-derivation? 80 substitutable-derivation?
81 substitution-oracle 81 substitution-oracle
82 derivation-hash 82 derivation-hash
83 derivation-properties
83 84
84 read-derivation 85 read-derivation
85 read-derivation-from-file 86 read-derivation-from-file
@@ -681,7 +682,8 @@ name of each input with that input's hash."
681 references-graphs 682 references-graphs
682 allowed-references disallowed-references 683 allowed-references disallowed-references
683 leaked-env-vars local-build? 684 leaked-env-vars local-build?
684 (substitutable? #t)) 685 (substitutable? #t)
686 (properties '()))
685 "Build a derivation with the given arguments, and return the resulting 687 "Build a derivation with the given arguments, and return the resulting
686<derivation> object. When HASH and HASH-ALGO are given, a 688<derivation> object. When HASH and HASH-ALGO are given, a
687fixed-output derivation is created---i.e., one whose result is known in 689fixed-output derivation is created---i.e., one whose result is known in
@@ -708,7 +710,10 @@ for offloading and should rather be built locally. This is the case for small
708derivations where the costs of data transfers would outweigh the benefits. 710derivations where the costs of data transfers would outweigh the benefits.
709 711
710When SUBSTITUTABLE? is false, declare that substitutes of the derivation's 712When SUBSTITUTABLE? is false, declare that substitutes of the derivation's
711output should not be used." 713output should not be used.
714
715PROPERTIES must be an association list describing \"properties\" of the
716derivation. It is kept as-is, uninterpreted, in the derivation."
712 (define (add-output-paths drv) 717 (define (add-output-paths drv)
713 ;; Return DRV with an actual store path for each of its output and the 718 ;; Return DRV with an actual store path for each of its output and the
714 ;; corresponding environment variable. 719 ;; corresponding environment variable.
@@ -763,6 +768,10 @@ output should not be used."
763 `(("impureEnvVars" 768 `(("impureEnvVars"
764 . ,(string-join leaked-env-vars))) 769 . ,(string-join leaked-env-vars)))
765 '()) 770 '())
771 ,@(match properties
772 (() '())
773 (lst `(("guix properties"
774 . ,(object->string properties)))))
766 ,@env-vars))) 775 ,@env-vars)))
767 (match references-graphs 776 (match references-graphs
768 (((file . path) ...) 777 (((file . path) ...)
@@ -851,6 +860,14 @@ long-running processes that know what they're doing. Use with care!"
851 (invalidate-memoization! derivation-path->base16-hash) 860 (invalidate-memoization! derivation-path->base16-hash)
852 (hash-clear! %derivation-cache)) 861 (hash-clear! %derivation-cache))
853 862
863(define derivation-properties
864 (mlambdaq (drv)
865 "Return the property alist associated with DRV."
866 (match (assoc "guix properties"
867 (derivation-builder-environment-vars drv))
868 ((_ . str) (call-with-input-string str read))
869 (#f '()))))
870
854(define* (map-derivation store drv mapping 871(define* (map-derivation store drv mapping
855 #:key (system (%current-system))) 872 #:key (system (%current-system)))
856 "Given MAPPING, a list of pairs of derivations, return a derivation based on 873 "Given MAPPING, a list of pairs of derivations, return a derivation based on
@@ -1129,7 +1146,8 @@ they can refer to each other."
1129 references-graphs 1146 references-graphs
1130 allowed-references 1147 allowed-references
1131 disallowed-references 1148 disallowed-references
1132 local-build? (substitutable? #t)) 1149 local-build? (substitutable? #t)
1150 (properties '()))
1133 "Return a derivation that executes Scheme expression EXP as a builder 1151 "Return a derivation that executes Scheme expression EXP as a builder
1134for derivation NAME. INPUTS must be a list of (NAME DRV-PATH SUB-DRV) 1152for derivation NAME. INPUTS must be a list of (NAME DRV-PATH SUB-DRV)
1135tuples; when SUB-DRV is omitted, \"out\" is assumed. MODULES is a list 1153tuples; when SUB-DRV is omitted, \"out\" is assumed. MODULES is a list
@@ -1149,7 +1167,8 @@ EXP is built using GUILE-FOR-BUILD (a derivation). When GUILE-FOR-BUILD is
1149omitted or is #f, the value of the `%guile-for-build' fluid is used instead. 1167omitted or is #f, the value of the `%guile-for-build' fluid is used instead.
1150 1168
1151See the `derivation' procedure for the meaning of REFERENCES-GRAPHS, 1169See the `derivation' procedure for the meaning of REFERENCES-GRAPHS,
1152ALLOWED-REFERENCES, DISALLOWED-REFERENCES, LOCAL-BUILD?, and SUBSTITUTABLE?." 1170ALLOWED-REFERENCES, DISALLOWED-REFERENCES, LOCAL-BUILD?, SUBSTITUTABLE?,
1171and PROPERTIES."
1153 (define guile-drv 1172 (define guile-drv
1154 (or guile-for-build (%guile-for-build))) 1173 (or guile-for-build (%guile-for-build)))
1155 1174
@@ -1277,7 +1296,8 @@ ALLOWED-REFERENCES, DISALLOWED-REFERENCES, LOCAL-BUILD?, and SUBSTITUTABLE?."
1277 #:allowed-references allowed-references 1296 #:allowed-references allowed-references
1278 #:disallowed-references disallowed-references 1297 #:disallowed-references disallowed-references
1279 #:local-build? local-build? 1298 #:local-build? local-build?
1280 #:substitutable? substitutable?))) 1299 #:substitutable? substitutable?
1300 #:properties properties)))
1281 1301
1282 1302
1283;;; 1303;;;
diff --git a/guix/gexp.scm b/guix/gexp.scm
index f33fb198e48..786e3783087 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -631,6 +631,7 @@ names and file names suitable for the #:allowed-references argument to
631 allowed-references disallowed-references 631 allowed-references disallowed-references
632 leaked-env-vars 632 leaked-env-vars
633 local-build? (substitutable? #t) 633 local-build? (substitutable? #t)
634 (properties '())
634 635
635 ;; TODO: This parameter is transitional; it's here 636 ;; TODO: This parameter is transitional; it's here
636 ;; to avoid a full rebuild. Remove it on the next 637 ;; to avoid a full rebuild. Remove it on the next
@@ -800,7 +801,8 @@ The other arguments are as for 'derivation'."
800 #:disallowed-references disallowed 801 #:disallowed-references disallowed
801 #:leaked-env-vars leaked-env-vars 802 #:leaked-env-vars leaked-env-vars
802 #:local-build? local-build? 803 #:local-build? local-build?
803 #:substitutable? substitutable?)))) 804 #:substitutable? substitutable?
805 #:properties properties))))
804 806
805(define* (gexp-inputs exp #:key native?) 807(define* (gexp-inputs exp #:key native?)
806 "Return the input list for EXP. When NATIVE? is true, return only native 808 "Return the input list for EXP. When NATIVE? is true, return only native
diff --git a/tests/derivations.scm b/tests/derivations.scm
index 159a6971b39..5f294c18278 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -1132,6 +1132,16 @@
1132 ((p2 . _) 1132 ((p2 . _)
1133 (string<? p1 p2))))))))))))) 1133 (string<? p1 p2)))))))))))))
1134 1134
1135(test-equal "derivation-properties"
1136 (list '() '((type . test)))
1137 (let ((drv1 (build-expression->derivation %store "bar"
1138 '(mkdir %output)))
1139 (drv2 (build-expression->derivation %store "foo"
1140 '(mkdir %output)
1141 #:properties '((type . test)))))
1142 (list (derivation-properties drv1)
1143 (derivation-properties drv2))))
1144
1135(test-equal "map-derivation" 1145(test-equal "map-derivation"
1136 "hello" 1146 "hello"
1137 (let* ((joke (package-derivation %store guile-1.8)) 1147 (let* ((joke (package-derivation %store guile-1.8))
diff --git a/tests/gexp.scm b/tests/gexp.scm
index ab60bdab682..7ae9201c81e 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -476,7 +476,15 @@
476 (return (and (string=? (readlink (string-append out "/foo")) guile) 476 (return (and (string=? (readlink (string-append out "/foo")) guile)
477 (string=? (readlink out2) file) 477 (string=? (readlink out2) file)
478 (equal? refs (list (dirname (dirname guile)))) 478 (equal? refs (list (dirname (dirname guile))))
479 (equal? refs2 (list file)))))) 479 (equal? refs2 (list file))
480 (null? (derivation-properties drv))))))
481
482(test-assertm "gexp->derivation properties"
483 (mlet %store-monad ((drv (gexp->derivation "foo"
484 #~(mkdir #$output)
485 #:properties '((type . test)))))
486 (return (equal? '((type . test))
487 (derivation-properties drv)))))
480 488
481(test-assertm "gexp->derivation vs. grafts" 489(test-assertm "gexp->derivation vs. grafts"
482 (mlet* %store-monad ((graft? (set-grafting #f)) 490 (mlet* %store-monad ((graft? (set-grafting #f))