guix package: Fix version and output for 'guix package -i /gnu/store/…'.
[jackhill/guix/guix.git] / tests / derivations.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
44ad3384 2;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
341c6fdd 3;;;
233e7676 4;;; This file is part of GNU Guix.
341c6fdd 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
341c6fdd
LC
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
233e7676 11;;; GNU Guix is distributed in the hope that it will be useful, but
341c6fdd
LC
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
233e7676 17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
341c6fdd 18
94d92c77
LC
19(unsetenv "http_proxy")
20
341c6fdd
LC
21(define-module (test-derivations)
22 #:use-module (guix derivations)
ef8de985 23 #:use-module (guix grafts)
26bbbb95 24 #:use-module (guix store)
de4c3f26 25 #:use-module (guix utils)
72626a71 26 #:use-module (guix hash)
ddc29a78 27 #:use-module (guix base32)
c1bc358f 28 #:use-module (guix tests)
94d92c77 29 #:use-module (guix tests http)
36bbbbd1
LC
30 #:use-module ((guix packages) #:select (package-derivation base32))
31 #:use-module ((guix build utils) #:select (executable-file?))
59a43334 32 #:use-module ((gnu packages) #:select (search-bootstrap-binary))
1ffa7090 33 #:use-module (gnu packages bootstrap)
e387ab7c 34 #:use-module ((gnu packages guile) #:select (guile-1.8))
b37eb5ed 35 #:use-module (srfi srfi-1)
fb3eec83 36 #:use-module (srfi srfi-11)
341c6fdd 37 #:use-module (srfi srfi-26)
99634e3f 38 #:use-module (srfi srfi-34)
341c6fdd 39 #:use-module (srfi srfi-64)
fb3eec83 40 #:use-module (rnrs io ports)
749c6567 41 #:use-module (rnrs bytevectors)
dd36b51b 42 #:use-module (web uri)
b37eb5ed 43 #:use-module (ice-9 rdelim)
db393b33 44 #:use-module (ice-9 regex)
99634e3f
LC
45 #:use-module (ice-9 ftw)
46 #:use-module (ice-9 match))
341c6fdd 47
26bbbb95 48(define %store
c1bc358f 49 (open-connection-for-tests))
b272c474 50
ef8de985
LC
51;; Globally disable grafts because they can trigger early builds.
52(%graft? #f)
53
5b0c9d16
LC
54(define (bootstrap-binary name)
55 (let ((bin (search-bootstrap-binary name (%current-system))))
97d3998e 56 (and %store
5b0c9d16
LC
57 (add-to-store %store name #t "sha256" bin))))
58
59(define %bash
60 (bootstrap-binary "bash"))
61(define %mkdir
62 (bootstrap-binary "mkdir"))
97d3998e 63
5b0c9d16 64(define* (directory-contents dir #:optional (slurp get-bytevector-all))
b37eb5ed
LC
65 "Return an alist representing the contents of DIR."
66 (define prefix-len (string-length dir))
67 (sort (file-system-fold (const #t) ; enter?
68 (lambda (path stat result) ; leaf
69 (alist-cons (string-drop path prefix-len)
5b0c9d16 70 (call-with-input-file path slurp)
b37eb5ed
LC
71 result))
72 (lambda (path stat result) result) ; down
73 (lambda (path stat result) result) ; up
74 (lambda (path stat result) result) ; skip
75 (lambda (path stat errno result) result) ; error
76 '()
77 dir)
78 (lambda (e1 e2)
79 (string<? (car e1) (car e2)))))
80
94d92c77
LC
81;; Avoid collisions with other tests.
82(%http-server-port 10500)
83
ef8de985 84\f
341c6fdd
LC
85(test-begin "derivations")
86
87(test-assert "parse & export"
33594aa4
LC
88 (let* ((f (search-path %load-path "tests/test.drv"))
89 (b1 (call-with-input-file f get-bytevector-all))
341c6fdd
LC
90 (d1 (read-derivation (open-bytevector-input-port b1)))
91 (b2 (call-with-bytevector-output-port (cut write-derivation d1 <>)))
92 (d2 (read-derivation (open-bytevector-input-port b2))))
93 (and (equal? b1 b2)
94 (equal? d1 d2))))
95
5b0c9d16 96(test-skip (if %store 0 12))
b37eb5ed 97
d1b1c424
LC
98(test-assert "add-to-store, flat"
99 (let* ((file (search-path %load-path "language/tree-il/spec.scm"))
a9ebd9ef 100 (drv (add-to-store %store "flat-test" #f "sha256" file)))
d1b1c424 101 (and (eq? 'regular (stat:type (stat drv)))
31ef99a8 102 (valid-path? %store drv)
d1b1c424
LC
103 (equal? (call-with-input-file file get-bytevector-all)
104 (call-with-input-file drv get-bytevector-all)))))
105
b37eb5ed
LC
106(test-assert "add-to-store, recursive"
107 (let* ((dir (dirname (search-path %load-path "language/tree-il/spec.scm")))
a9ebd9ef 108 (drv (add-to-store %store "dir-tree-test" #t "sha256" dir)))
b37eb5ed 109 (and (eq? 'directory (stat:type (stat drv)))
31ef99a8 110 (valid-path? %store drv)
b37eb5ed
LC
111 (equal? (directory-contents dir)
112 (directory-contents drv)))))
26bbbb95
LC
113
114(test-assert "derivation with no inputs"
31ef99a8 115 (let* ((builder (add-text-to-store %store "my-builder.sh"
97d3998e 116 "echo hello, world\n"
31ef99a8 117 '()))
59688fc4 118 (drv (derivation %store "foo"
97d3998e 119 %bash `("-e" ,builder)
a987d2c0 120 #:env-vars '(("HOME" . "/homeless")))))
59688fc4
LC
121 (and (store-path? (derivation-file-name drv))
122 (valid-path? %store (derivation-file-name drv)))))
26bbbb95 123
fb3eec83 124(test-assert "build derivation with 1 source"
59688fc4
LC
125 (let* ((builder (add-text-to-store %store "my-builder.sh"
126 "echo hello, world > \"$out\"\n"
127 '()))
128 (drv (derivation %store "foo"
129 %bash `(,builder)
130 #:env-vars '(("HOME" . "/homeless")
131 ("zzz" . "Z!")
132 ("AAA" . "A!"))
bde2d9cf 133 #:inputs `((,%bash) (,builder))))
59688fc4
LC
134 (succeeded?
135 (build-derivations %store (list drv))))
fb3eec83 136 (and succeeded?
59688fc4 137 (let ((path (derivation->output-path drv)))
31ef99a8
LC
138 (and (valid-path? %store path)
139 (string=? (call-with-input-file path read-line)
140 "hello, world"))))))
fb3eec83 141
860a6f1a
LC
142(test-assert "derivation with local file as input"
143 (let* ((builder (add-text-to-store
144 %store "my-builder.sh"
bbb76f6f 145 "(while read line ; do echo \"$line\" ; done) < $in > $out"
860a6f1a
LC
146 '()))
147 (input (search-path %load-path "ice-9/boot-9.scm"))
a987d2c0
LC
148 (input* (add-to-store %store (basename input)
149 #t "sha256" input))
59688fc4 150 (drv (derivation %store "derivation-with-input-file"
97d3998e 151 %bash `(,builder)
a987d2c0
LC
152
153 ;; Cheat to pass the actual file name to the
154 ;; builder.
155 #:env-vars `(("in" . ,input*))
156
bde2d9cf
LC
157 #:inputs `((,%bash)
158 (,builder)
a987d2c0 159 (,input))))) ; ← local file name
59688fc4 160 (and (build-derivations %store (list drv))
bbb76f6f
LC
161 ;; Note: we can't compare the files because the above trick alters
162 ;; the contents.
59688fc4 163 (valid-path? %store (derivation->output-path drv)))))
860a6f1a 164
0e510971
LC
165(test-assert "derivation fails but keep going"
166 ;; In keep-going mode, 'build-derivations' should fail because of D1, but it
167 ;; must return only after D2 has succeeded.
168 (with-store store
169 (let* ((d1 (derivation %store "fails"
170 %bash `("-c" "false")
171 #:inputs `((,%bash))))
172 (d2 (build-expression->derivation %store "sleep-then-succeed"
173 `(begin
174 ,(random-text)
175 ;; XXX: Hopefully that's long
176 ;; enough that D1 has already
177 ;; failed.
178 (sleep 2)
179 (mkdir %output)))))
180 (set-build-options %store
181 #:use-substitutes? #f
182 #:keep-going? #t)
183 (guard (c ((nix-protocol-error? c)
184 (and (= 100 (nix-protocol-error-status c))
185 (string-contains (nix-protocol-error-message c)
186 (derivation-file-name d1))
187 (not (valid-path? %store (derivation->output-path d1)))
188 (valid-path? %store (derivation->output-path d2)))))
189 (build-derivations %store (list d1 d2))
190 #f))))
191
44d43c7a
LC
192(test-assert "identical files are deduplicated"
193 (let* ((build1 (add-text-to-store %store "one.sh"
194 "echo hello, world > \"$out\"\n"
195 '()))
196 (build2 (add-text-to-store %store "two.sh"
197 "# Hey!\necho hello, world > \"$out\"\n"
198 '()))
199 (drv1 (derivation %store "foo"
200 %bash `(,build1)
201 #:inputs `((,%bash) (,build1))))
202 (drv2 (derivation %store "bar"
203 %bash `(,build2)
204 #:inputs `((,%bash) (,build2)))))
205 (and (build-derivations %store (list drv1 drv2))
206 (let ((file1 (derivation->output-path drv1))
207 (file2 (derivation->output-path drv2)))
208 (and (valid-path? %store file1) (valid-path? %store file2)
209 (string=? (call-with-input-file file1 get-string-all)
210 "hello, world\n")
211 (= (stat:ino (lstat file1))
212 (stat:ino (lstat file2))))))))
213
f9aefa2d
LC
214(test-equal "built-in-builders"
215 '("download")
216 (built-in-builders %store))
217
94d92c77
LC
218(test-assert "unknown built-in builder"
219 (let ((drv (derivation %store "ohoh" "builtin:does-not-exist" '())))
220 (guard (c ((nix-protocol-error? c)
221 (string-contains (nix-protocol-error-message c) "failed")))
222 (build-derivations %store (list drv))
223 #f)))
224
225(unless (force %http-server-socket)
226 (test-skip 1))
227(test-assert "'download' built-in builder"
228 (let ((text (random-text)))
229 (with-http-server 200 text
230 (let* ((drv (derivation %store "world"
231 "builtin:download" '()
232 #:env-vars `(("url"
233 . ,(object->string (%local-url))))
234 #:hash-algo 'sha256
235 #:hash (sha256 (string->utf8 text)))))
236 (and (build-derivations %store (list drv))
237 (string=? (call-with-input-file (derivation->output-path drv)
238 get-string-all)
239 text))))))
240
241(unless (force %http-server-socket)
242 (test-skip 1))
243(test-assert "'download' built-in builder, invalid hash"
244 (with-http-server 200 "hello, world!"
245 (let* ((drv (derivation %store "world"
246 "builtin:download" '()
247 #:env-vars `(("url"
248 . ,(object->string (%local-url))))
249 #:hash-algo 'sha256
250 #:hash (sha256 (random-bytevector 100))))) ;wrong
251 (guard (c ((nix-protocol-error? c)
252 (string-contains (nix-protocol-error-message c) "failed")))
253 (build-derivations %store (list drv))
254 #f))))
255
256(unless (force %http-server-socket)
257 (test-skip 1))
258(test-assert "'download' built-in builder, not found"
259 (with-http-server 404 "not found"
260 (let* ((drv (derivation %store "will-never-be-found"
261 "builtin:download" '()
262 #:env-vars `(("url"
263 . ,(object->string (%local-url))))
264 #:hash-algo 'sha256
265 #:hash (sha256 (random-bytevector 100)))))
266 (guard (c ((nix-protocol-error? c)
267 (string-contains (nix-protocol-error-message (pk c)) "failed")))
268 (build-derivations %store (list drv))
269 #f))))
270
271(test-assert "'download' built-in builder, not fixed-output"
272 (let* ((source (add-text-to-store %store "hello" "hi!"))
273 (url (string-append "file://" source))
274 (drv (derivation %store "world"
275 "builtin:download" '()
276 #:env-vars `(("url" . ,(object->string url))))))
277 (guard (c ((nix-protocol-error? c)
278 (string-contains (nix-protocol-error-message c) "failed")))
279 (build-derivations %store (list drv))
280 #f)))
281
e786293e
LC
282(test-equal "derivation-name"
283 "foo-0.0"
284 (let ((drv (derivation %store "foo-0.0" %bash '())))
285 (derivation-name drv)))
286
0b6af195
LC
287(test-equal "derivation-output-names"
288 '(("out") ("bar" "chbouib"))
289 (let ((drv1 (derivation %store "foo-0.0" %bash '()))
290 (drv2 (derivation %store "foo-0.0" %bash '()
291 #:outputs '("bar" "chbouib"))))
292 (list (derivation-output-names drv1)
293 (derivation-output-names drv2))))
294
fc93e309
LC
295(test-assert "offloadable-derivation?"
296 (and (offloadable-derivation? (derivation %store "foo" %bash '()))
4a6aeb67
LC
297 (offloadable-derivation? ;see <http://bugs.gnu.org/18747>
298 (derivation %store "foo" %bash '()
299 #:substitutable? #f))
fc93e309
LC
300 (not (offloadable-derivation?
301 (derivation %store "foo" %bash '()
302 #:local-build? #t)))))
303
4a6aeb67
LC
304(test-assert "substitutable-derivation?"
305 (and (substitutable-derivation? (derivation %store "foo" %bash '()))
306 (substitutable-derivation? ;see <http://bugs.gnu.org/18747>
307 (derivation %store "foo" %bash '()
cfc5d398 308 #:local-build? #t))
4a6aeb67
LC
309 (not (substitutable-derivation?
310 (derivation %store "foo" %bash '()
311 #:substitutable? #f)))))
312
99e17dc9
LC
313(test-assert "fixed-output-derivation?"
314 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
315 "echo -n hello > $out" '()))
316 (hash (sha256 (string->utf8 "hello")))
317 (drv (derivation %store "fixed"
318 %bash `(,builder)
319 #:inputs `((,builder))
320 #:hash hash #:hash-algo 'sha256)))
321 (fixed-output-derivation? drv)))
322
749c6567
LC
323(test-assert "fixed-output derivation"
324 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
325 "echo -n hello > $out" '()))
326 (hash (sha256 (string->utf8 "hello")))
59688fc4 327 (drv (derivation %store "fixed"
97d3998e 328 %bash `(,builder)
a987d2c0 329 #:inputs `((,builder)) ; optional
749c6567 330 #:hash hash #:hash-algo 'sha256))
59688fc4 331 (succeeded? (build-derivations %store (list drv))))
749c6567 332 (and succeeded?
59688fc4 333 (let ((p (derivation->output-path drv)))
82058eff
LC
334 (and (equal? (string->utf8 "hello")
335 (call-with-input-file p get-bytevector-all))
336 (bytevector? (query-path-hash %store p)))))))
749c6567 337
813986ac
LC
338(test-assert "fixed-output derivation: output paths are equal"
339 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
340 "echo -n hello > $out" '()))
341 (builder2 (add-text-to-store %store "fixed-builder2.sh"
342 "echo hey; echo -n hello > $out" '()))
343 (hash (sha256 (string->utf8 "hello")))
59688fc4 344 (drv1 (derivation %store "fixed"
97d3998e 345 %bash `(,builder1)
813986ac 346 #:hash hash #:hash-algo 'sha256))
59688fc4 347 (drv2 (derivation %store "fixed"
97d3998e 348 %bash `(,builder2)
813986ac 349 #:hash hash #:hash-algo 'sha256))
59688fc4 350 (succeeded? (build-derivations %store (list drv1 drv2))))
813986ac 351 (and succeeded?
59688fc4
LC
352 (equal? (derivation->output-path drv1)
353 (derivation->output-path drv2)))))
813986ac 354
36bbbbd1
LC
355(test-assert "fixed-output derivation, recursive"
356 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
357 "echo -n hello > $out" '()))
358 (hash (sha256 (string->utf8 "hello")))
359 (drv (derivation %store "fixed-rec"
360 %bash `(,builder)
361 #:inputs `((,builder))
362 #:hash (base32 "0sg9f58l1jj88w6pdrfdpj5x9b1zrwszk84j81zvby36q9whhhqa")
363 #:hash-algo 'sha256
364 #:recursive? #t))
365 (succeeded? (build-derivations %store (list drv))))
366 (and succeeded?
367 (let ((p (derivation->output-path drv)))
368 (and (equal? (string->utf8 "hello")
369 (call-with-input-file p get-bytevector-all))
370 (bytevector? (query-path-hash %store p)))))))
371
813986ac
LC
372(test-assert "derivation with a fixed-output input"
373 ;; A derivation D using a fixed-output derivation F doesn't has the same
374 ;; output path when passed F or F', as long as F and F' have the same output
375 ;; path.
376 (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"
377 "echo -n hello > $out" '()))
378 (builder2 (add-text-to-store %store "fixed-builder2.sh"
379 "echo hey; echo -n hello > $out" '()))
380 (hash (sha256 (string->utf8 "hello")))
a987d2c0 381 (fixed1 (derivation %store "fixed"
97d3998e 382 %bash `(,builder1)
813986ac 383 #:hash hash #:hash-algo 'sha256))
a987d2c0 384 (fixed2 (derivation %store "fixed"
97d3998e 385 %bash `(,builder2)
813986ac 386 #:hash hash #:hash-algo 'sha256))
59688fc4 387 (fixed-out (derivation->output-path fixed1))
813986ac
LC
388 (builder3 (add-text-to-store
389 %store "final-builder.sh"
390 ;; Use Bash hackery to avoid Coreutils.
391 "echo $in ; (read -u 3 c; echo $c) 3< $in > $out" '()))
a987d2c0 392 (final1 (derivation %store "final"
97d3998e 393 %bash `(,builder3)
a987d2c0 394 #:env-vars `(("in" . ,fixed-out))
bde2d9cf 395 #:inputs `((,%bash) (,builder3) (,fixed1))))
a987d2c0 396 (final2 (derivation %store "final"
97d3998e 397 %bash `(,builder3)
a987d2c0 398 #:env-vars `(("in" . ,fixed-out))
bde2d9cf 399 #:inputs `((,%bash) (,builder3) (,fixed2))))
813986ac
LC
400 (succeeded? (build-derivations %store
401 (list final1 final2))))
402 (and succeeded?
59688fc4
LC
403 (equal? (derivation->output-path final1)
404 (derivation->output-path final2)))))
813986ac 405
7946c4e7
LC
406(test-assert "multiple-output derivation"
407 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
408 "echo one > $out ; echo two > $second"
409 '()))
59688fc4 410 (drv (derivation %store "fixed"
97d3998e 411 %bash `(,builder)
a987d2c0
LC
412 #:env-vars '(("HOME" . "/homeless")
413 ("zzz" . "Z!")
414 ("AAA" . "A!"))
bde2d9cf 415 #:inputs `((,%bash) (,builder))
7946c4e7 416 #:outputs '("out" "second")))
59688fc4 417 (succeeded? (build-derivations %store (list drv))))
7946c4e7 418 (and succeeded?
59688fc4
LC
419 (let ((one (derivation->output-path drv "out"))
420 (two (derivation->output-path drv "second")))
7244a5f7 421 (and (lset= equal?
59688fc4 422 (derivation->output-paths drv)
7244a5f7
LC
423 `(("out" . ,one) ("second" . ,two)))
424 (eq? 'one (call-with-input-file one read))
7946c4e7
LC
425 (eq? 'two (call-with-input-file two read)))))))
426
4b1786aa
LC
427(test-assert "multiple-output derivation, non-alphabetic order"
428 ;; Here, the outputs are not listed in alphabetic order. Yet, the store
429 ;; path computation must reorder them first.
430 (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
431 "echo one > $out ; echo two > $AAA"
432 '()))
59688fc4 433 (drv (derivation %store "fixed"
97d3998e 434 %bash `(,builder)
bde2d9cf 435 #:inputs `((,%bash) (,builder))
4b1786aa 436 #:outputs '("out" "AAA")))
59688fc4 437 (succeeded? (build-derivations %store (list drv))))
4b1786aa 438 (and succeeded?
59688fc4
LC
439 (let ((one (derivation->output-path drv "out"))
440 (two (derivation->output-path drv "AAA")))
4b1786aa
LC
441 (and (eq? 'one (call-with-input-file one read))
442 (eq? 'two (call-with-input-file two read)))))))
443
97507ebe
LC
444(test-assert "read-derivation vs. derivation"
445 ;; Make sure 'derivation' and 'read-derivation' return objects that are
446 ;; identical.
447 (let* ((sources (unfold (cut >= <> 10)
448 (lambda (n)
449 (add-text-to-store %store
450 (format #f "input~a" n)
451 (random-text)))
452 1+
453 0))
454 (inputs (map (lambda (file)
455 (derivation %store "derivation-input"
456 %bash '()
457 #:inputs `((,%bash) (,file))))
458 sources))
459 (builder (add-text-to-store %store "builder.sh"
460 "echo one > $one ; echo two > $two"
461 '()))
462 (drv (derivation %store "derivation"
463 %bash `(,builder)
464 #:inputs `((,%bash) (,builder)
465 ,@(map list (append sources inputs)))
466 #:outputs '("two" "one")))
467 (drv* (call-with-input-file (derivation-file-name drv)
468 read-derivation)))
469 (equal? drv* drv)))
470
d0dc4907
LC
471(test-assert "multiple-output derivation, derivation-path->output-path"
472 (let* ((builder (add-text-to-store %store "builder.sh"
473 "echo one > $out ; echo two > $second"
474 '()))
475 (drv (derivation %store "multiple"
476 %bash `(,builder)
477 #:outputs '("out" "second")))
478 (drv-file (derivation-file-name drv))
479 (one (derivation->output-path drv "out"))
480 (two (derivation->output-path drv "second"))
481 (first (derivation-path->output-path drv-file "out"))
482 (second (derivation-path->output-path drv-file "second")))
483 (and (not (string=? one two))
484 (string-suffix? "-second" two)
485 (string=? first one)
486 (string=? second two))))
487
d66ac374
LC
488(test-assert "user of multiple-output derivation"
489 ;; Check whether specifying several inputs coming from the same
490 ;; multiple-output derivation works.
491 (let* ((builder1 (add-text-to-store %store "my-mo-builder.sh"
492 "echo one > $out ; echo two > $two"
493 '()))
a987d2c0 494 (mdrv (derivation %store "multiple-output"
97d3998e 495 %bash `(,builder1)
bde2d9cf 496 #:inputs `((,%bash) (,builder1))
d66ac374
LC
497 #:outputs '("out" "two")))
498 (builder2 (add-text-to-store %store "my-mo-user-builder.sh"
499 "read x < $one;
500 read y < $two;
501 echo \"($x $y)\" > $out"
502 '()))
503 (udrv (derivation %store "multiple-output-user"
97d3998e 504 %bash `(,builder2)
a987d2c0 505 #:env-vars `(("one"
59688fc4 506 . ,(derivation->output-path
a987d2c0
LC
507 mdrv "out"))
508 ("two"
59688fc4 509 . ,(derivation->output-path
a987d2c0 510 mdrv "two")))
bde2d9cf
LC
511 #:inputs `((,%bash)
512 (,builder2)
a987d2c0
LC
513 ;; two occurrences of MDRV:
514 (,mdrv)
515 (,mdrv "two")))))
d66ac374 516 (and (build-derivations %store (list (pk 'udrv udrv)))
59688fc4 517 (let ((p (derivation->output-path udrv)))
d66ac374
LC
518 (and (valid-path? %store p)
519 (equal? '(one two) (call-with-input-file p read)))))))
520
858e9282 521(test-assert "derivation with #:references-graphs"
5b0c9d16
LC
522 (let* ((input1 (add-text-to-store %store "foo" "hello"
523 (list %bash)))
524 (input2 (add-text-to-store %store "bar"
525 (number->string (random 7777))
526 (list input1)))
527 (builder (add-text-to-store %store "build-graph"
528 (format #f "
529~a $out
530 (while read l ; do echo $l ; done) < bash > $out/bash
531 (while read l ; do echo $l ; done) < input1 > $out/input1
532 (while read l ; do echo $l ; done) < input2 > $out/input2"
533 %mkdir)
534 (list %mkdir)))
535 (drv (derivation %store "closure-graphs"
536 %bash `(,builder)
858e9282 537 #:references-graphs
5b0c9d16
LC
538 `(("bash" . ,%bash)
539 ("input1" . ,input1)
540 ("input2" . ,input2))
541 #:inputs `((,%bash) (,builder))))
59688fc4 542 (out (derivation->output-path drv)))
5b0c9d16
LC
543 (define (deps path . deps)
544 (let ((count (length deps)))
545 (string-append path "\n\n" (number->string count) "\n"
546 (string-join (sort deps string<?) "\n")
547 (if (zero? count) "" "\n"))))
548
549 (and (build-derivations %store (list drv))
550 (equal? (directory-contents out get-string-all)
551 `(("/bash" . ,(string-append %bash "\n\n0\n"))
552 ("/input1" . ,(if (string>? input1 %bash)
553 (string-append (deps %bash)
554 (deps input1 %bash))
555 (string-append (deps input1 %bash)
556 (deps %bash))))
557 ("/input2" . ,(string-concatenate
558 (map cdr
559 (sort
560 (map (lambda (p d)
561 (cons p (apply deps p d)))
562 (list %bash input1 input2)
563 (list '() (list %bash) (list input1)))
564 (lambda (x y)
565 (match x
566 ((p1 . _)
567 (match y
568 ((p2 . _)
569 (string<? p1 p2)))))))))))))))
570
b53be755
LC
571(test-assert "derivation #:allowed-references, ok"
572 (let ((drv (derivation %store "allowed" %bash
573 '("-c" "echo hello > $out")
574 #:inputs `((,%bash))
575 #:allowed-references '())))
576 (build-derivations %store (list drv))))
577
578(test-assert "derivation #:allowed-references, not allowed"
579 (let* ((txt (add-text-to-store %store "foo" "Hello, world."))
580 (drv (derivation %store "disallowed" %bash
581 `("-c" ,(string-append "echo " txt "> $out"))
582 #:inputs `((,%bash) (,txt))
583 #:allowed-references '())))
584 (guard (c ((nix-protocol-error? c)
585 ;; There's no specific error message to check for.
586 #t))
587 (build-derivations %store (list drv))
588 #f)))
589
590(test-assert "derivation #:allowed-references, self allowed"
591 (let ((drv (derivation %store "allowed" %bash
592 '("-c" "echo $out > $out")
593 #:inputs `((,%bash))
594 #:allowed-references '("out"))))
595 (build-derivations %store (list drv))))
596
597(test-assert "derivation #:allowed-references, self not allowed"
598 (let ((drv (derivation %store "disallowed" %bash
599 `("-c" ,"echo $out > $out")
600 #:inputs `((,%bash))
601 #:allowed-references '())))
602 (guard (c ((nix-protocol-error? c)
603 ;; There's no specific error message to check for.
604 #t))
605 (build-derivations %store (list drv))
606 #f)))
607
35b5ca78
LC
608(test-assert "derivation #:disallowed-references, ok"
609 (let ((drv (derivation %store "disallowed" %bash
610 '("-c" "echo hello > $out")
611 #:inputs `((,%bash))
612 #:disallowed-references '("out"))))
613 (build-derivations %store (list drv))))
614
615(test-assert "derivation #:disallowed-references, not ok"
616 (let* ((txt (add-text-to-store %store "foo" "Hello, world."))
617 (drv (derivation %store "disdisallowed" %bash
618 `("-c" ,(string-append "echo " txt "> $out"))
619 #:inputs `((,%bash) (,txt))
620 #:disallowed-references (list txt))))
621 (guard (c ((nix-protocol-error? c)
622 ;; There's no specific error message to check for.
623 #t))
624 (build-derivations %store (list drv))
625 #f)))
626
44ad3384
LC
627;; Here we should get the value of $NIX_STATE_DIR that the daemon sees, which
628;; is a unique value for each test process; this value is the same as the one
629;; we see in the process executing this file since it is set by 'test-env'.
630(test-equal "derivation #:leaked-env-vars"
631 (getenv "NIX_STATE_DIR")
632 (let* ((value (getenv "NIX_STATE_DIR"))
633 (drv (derivation %store "leaked-env-vars" %bash
634 '("-c" "echo -n $NIX_STATE_DIR > $out")
635 #:hash (sha256 (string->utf8 value))
636 #:hash-algo 'sha256
637 #:inputs `((,%bash))
638 #:leaked-env-vars '("NIX_STATE_DIR"))))
639 (and (build-derivations %store (list drv))
640 (call-with-input-file (derivation->output-path drv)
641 get-string-all))))
642
de4c3f26
LC
643\f
644(define %coreutils
8f3ecbd7 645 (false-if-exception
12d720fd 646 (and (network-reachable?)
f073e523 647 (package-derivation %store %bootstrap-coreutils&co))))
de4c3f26
LC
648
649(test-skip (if %coreutils 0 1))
650
651(test-assert "build derivation with coreutils"
652 (let* ((builder
653 (add-text-to-store %store "build-with-coreutils.sh"
654 "echo $PATH ; mkdir --version ; mkdir $out ; touch $out/good"
655 '()))
59688fc4 656 (drv
a987d2c0 657 (derivation %store "foo"
97d3998e 658 %bash `(,builder)
a987d2c0
LC
659 #:env-vars `(("PATH" .
660 ,(string-append
59688fc4 661 (derivation->output-path %coreutils)
a987d2c0
LC
662 "/bin")))
663 #:inputs `((,builder)
664 (,%coreutils))))
de4c3f26 665 (succeeded?
59688fc4 666 (build-derivations %store (list drv))))
de4c3f26 667 (and succeeded?
59688fc4 668 (let ((p (derivation->output-path drv)))
31ef99a8
LC
669 (and (valid-path? %store p)
670 (file-exists? (string-append p "/good")))))))
de4c3f26 671
9c629a27 672(test-skip (if (%guile-for-build) 0 8))
9a20830e 673
d26e1967
LC
674(test-equal "build-expression->derivation and invalid module name"
675 '(file-search-error "guix/module/that/does/not/exist.scm")
676 (guard (c ((file-search-error? c)
677 (list 'file-search-error
678 (file-search-error-file-name c))))
679 (build-expression->derivation %store "foo" #t
680 #:modules '((guix module that
681 does not exist)))))
682
9a20830e 683(test-assert "build-expression->derivation and derivation-prerequisites"
dd1a5a15 684 (let ((drv (build-expression->derivation %store "fail" #f)))
9a20830e
LC
685 (any (match-lambda
686 (($ <derivation-input> path)
59688fc4 687 (string=? path (derivation-file-name (%guile-for-build)))))
9a20830e 688 (derivation-prerequisites drv))))
d9085c23 689
49c0a8d6 690(test-assert "derivation-prerequisites and valid-derivation-input?"
3681db5d
LC
691 (let* ((a (build-expression->derivation %store "a" '(mkdir %output)))
692 (b (build-expression->derivation %store "b" `(list ,(random-text))))
693 (c (build-expression->derivation %store "c" `(mkdir %output)
694 #:inputs `(("a" ,a) ("b" ,b)))))
49c0a8d6
LC
695 ;; Make sure both A and %BOOTSTRAP-GUILE are built (the latter could have
696 ;; be removed by tests/guix-gc.sh.)
697 (build-derivations %store
698 (list a (package-derivation %store %bootstrap-guile)))
699
3681db5d
LC
700 (match (derivation-prerequisites c
701 (cut valid-derivation-input? %store
702 <>))
703 ((($ <derivation-input> file ("out")))
704 (string=? file (derivation-file-name b)))
705 (x
706 (pk 'fail x #f)))))
707
d9085c23
LC
708(test-assert "build-expression->derivation without inputs"
709 (let* ((builder '(begin
710 (mkdir %output)
711 (call-with-output-file (string-append %output "/test")
712 (lambda (p)
713 (display '(hello guix) p)))))
dd1a5a15 714 (drv (build-expression->derivation %store "goo" builder))
59688fc4 715 (succeeded? (build-derivations %store (list drv))))
d9085c23 716 (and succeeded?
59688fc4 717 (let ((p (derivation->output-path drv)))
d9085c23
LC
718 (equal? '(hello guix)
719 (call-with-input-file (string-append p "/test") read))))))
720
969e678e
LC
721(test-assert "build-expression->derivation and max-silent-time"
722 (let* ((store (let ((s (open-connection)))
723 (set-build-options s #:max-silent-time 1)
724 s))
01e82af5 725 (builder '(begin (sleep 100) (mkdir %output) #t))
dd1a5a15 726 (drv (build-expression->derivation store "silent" builder))
59688fc4 727 (out-path (derivation->output-path drv)))
6c20d1d0
LC
728 (guard (c ((nix-protocol-error? c)
729 (and (string-contains (nix-protocol-error-message c)
730 "failed")
731 (not (valid-path? store out-path)))))
732 (build-derivations store (list drv))
733 #f)))
734
735(test-assert "build-expression->derivation and timeout"
736 (let* ((store (let ((s (open-connection)))
737 (set-build-options s #:timeout 1)
738 s))
739 (builder '(begin (sleep 100) (mkdir %output) #t))
740 (drv (build-expression->derivation store "slow" builder))
741 (out-path (derivation->output-path drv)))
969e678e
LC
742 (guard (c ((nix-protocol-error? c)
743 (and (string-contains (nix-protocol-error-message c)
744 "failed")
745 (not (valid-path? store out-path)))))
01e82af5
LC
746 (build-derivations store (list drv))
747 #f)))
969e678e 748
9a20830e 749(test-assert "build-expression->derivation and derivation-prerequisites-to-build"
dd1a5a15 750 (let ((drv (build-expression->derivation %store "fail" #f)))
9a20830e
LC
751 ;; The only direct dependency is (%guile-for-build) and it's already
752 ;; built.
753 (null? (derivation-prerequisites-to-build %store drv))))
754
784bb1f3 755(test-assert "derivation-prerequisites-to-build when outputs already present"
59688fc4 756 (let* ((builder '(begin (mkdir %output) #t))
dd1a5a15 757 (input-drv (build-expression->derivation %store "input" builder))
59688fc4
LC
758 (input-path (derivation-output-path
759 (assoc-ref (derivation-outputs input-drv)
760 "out")))
dd1a5a15
LC
761 (drv (build-expression->derivation %store "something" builder
762 #:inputs
59688fc4
LC
763 `(("i" ,input-drv))))
764 (output (derivation->output-path drv)))
784bb1f3
LC
765 ;; Make sure these things are not already built.
766 (when (valid-path? %store input-path)
767 (delete-paths %store (list input-path)))
768 (when (valid-path? %store output)
769 (delete-paths %store (list output)))
770
771 (and (equal? (map derivation-input-path
772 (derivation-prerequisites-to-build %store drv))
59688fc4 773 (list (derivation-file-name input-drv)))
784bb1f3
LC
774
775 ;; Build DRV and delete its input.
59688fc4 776 (build-derivations %store (list drv))
784bb1f3
LC
777 (delete-paths %store (list input-path))
778 (not (valid-path? %store input-path))
779
780 ;; Now INPUT-PATH is missing, yet it shouldn't be listed as a
781 ;; prerequisite to build because DRV itself is already built.
782 (null? (derivation-prerequisites-to-build %store drv)))))
783
dd36b51b 784(test-assert "derivation-prerequisites-to-build and substitutes"
59688fc4
LC
785 (let* ((store (open-connection))
786 (drv (build-expression->derivation store "prereq-subst"
dd1a5a15 787 (random 1000)))
e6740741 788 (output (derivation->output-path drv)))
dd36b51b 789
1950bf56 790 ;; Make sure substitutes are usable.
24f5aaaf
LC
791 (set-build-options store #:use-substitutes? #t
792 #:substitute-urls (%test-substitute-urls))
1950bf56 793
e6740741
LC
794 (with-derivation-narinfo drv
795 (let-values (((build download)
796 (derivation-prerequisites-to-build store drv))
797 ((build* download*)
798 (derivation-prerequisites-to-build store drv
e9651e39
LC
799 #:substitutable?
800 (const #f))))
e6740741
LC
801 (and (null? build)
802 (equal? download (list output))
803 (null? download*)
804 (null? build*))))))
dd36b51b 805
4a6aeb67 806(test-assert "derivation-prerequisites-to-build and substitutes, non-substitutable build"
d2d0514b 807 (let* ((store (open-connection))
4a6aeb67 808 (drv (build-expression->derivation store "prereq-no-subst"
d2d0514b 809 (random 1000)
4a6aeb67 810 #:substitutable? #f))
d2d0514b
LC
811 (output (derivation->output-path drv)))
812
813 ;; Make sure substitutes are usable.
24f5aaaf
LC
814 (set-build-options store #:use-substitutes? #t
815 #:substitute-urls (%test-substitute-urls))
d2d0514b
LC
816
817 (with-derivation-narinfo drv
818 (let-values (((build download)
819 (derivation-prerequisites-to-build store drv)))
820 ;; Despite being available as a substitute, DRV will be built locally
4a6aeb67 821 ;; due to #:substitutable? #f.
d2d0514b
LC
822 (and (null? download)
823 (match build
824 (((? derivation-input? input))
825 (string=? (derivation-input-path input)
826 (derivation-file-name drv)))))))))
827
4a6aeb67
LC
828(test-assert "derivation-prerequisites-to-build and substitutes, local build"
829 (with-store store
830 (let* ((drv (build-expression->derivation store "prereq-subst-local"
831 (random 1000)
832 #:local-build? #t))
833 (output (derivation->output-path drv)))
834
835 ;; Make sure substitutes are usable.
24f5aaaf
LC
836 (set-build-options store #:use-substitutes? #t
837 #:substitute-urls (%test-substitute-urls))
4a6aeb67
LC
838
839 (with-derivation-narinfo drv
840 (let-values (((build download)
841 (derivation-prerequisites-to-build store drv)))
cfc5d398 842 ;; #:local-build? is *not* synonymous with #:substitutable?, so we
4a6aeb67
LC
843 ;; must be able to substitute DRV's output.
844 ;; See <http://bugs.gnu.org/18747>.
845 (and (null? build)
846 (match download
847 (((? string? item))
848 (string=? item (derivation->output-path drv))))))))))
849
58c08df0
LC
850(test-assert "derivation-prerequisites-to-build in 'check' mode"
851 (with-store store
852 (let* ((dep (build-expression->derivation store "dep"
853 `(begin ,(random-text)
854 (mkdir %output))))
855 (drv (build-expression->derivation store "to-check"
856 '(mkdir %output)
857 #:inputs `(("dep" ,dep)))))
858 (build-derivations store (list drv))
859 (delete-paths store (list (derivation->output-path dep)))
860
861 ;; In 'check' mode, DEP must be rebuilt.
862 (and (null? (derivation-prerequisites-to-build store drv))
863 (match (derivation-prerequisites-to-build store drv
864 #:mode (build-mode
865 check))
866 ((input)
867 (string=? (derivation-input-path input)
868 (derivation-file-name dep))))))))
869
db393b33
LC
870(test-assert "build-expression->derivation with expression returning #f"
871 (let* ((builder '(begin
872 (mkdir %output)
873 #f)) ; fail!
dd1a5a15 874 (drv (build-expression->derivation %store "fail" builder))
59688fc4 875 (out-path (derivation->output-path drv)))
db393b33
LC
876 (guard (c ((nix-protocol-error? c)
877 ;; Note that the output path may exist at this point, but it
878 ;; is invalid.
31ef99a8
LC
879 (and (string-match "build .* failed"
880 (nix-protocol-error-message c))
881 (not (valid-path? %store out-path)))))
59688fc4 882 (build-derivations %store (list drv))
db393b33
LC
883 #f)))
884
9bc07f4d
LC
885(test-assert "build-expression->derivation with two outputs"
886 (let* ((builder '(begin
887 (call-with-output-file (assoc-ref %outputs "out")
888 (lambda (p)
889 (display '(hello) p)))
890 (call-with-output-file (assoc-ref %outputs "second")
891 (lambda (p)
892 (display '(world) p)))))
dd1a5a15 893 (drv (build-expression->derivation %store "double" builder
9bc07f4d
LC
894 #:outputs '("out"
895 "second")))
59688fc4 896 (succeeded? (build-derivations %store (list drv))))
9bc07f4d 897 (and succeeded?
59688fc4
LC
898 (let ((one (derivation->output-path drv))
899 (two (derivation->output-path drv "second")))
9bc07f4d
LC
900 (and (equal? '(hello) (call-with-input-file one read))
901 (equal? '(world) (call-with-input-file two read)))))))
902
ad1ebab3 903(test-skip (if %coreutils 0 1))
d9085c23
LC
904(test-assert "build-expression->derivation with one input"
905 (let* ((builder '(call-with-output-file %output
906 (lambda (p)
907 (let ((cu (assoc-ref %build-inputs "cu")))
908 (close 1)
909 (dup2 (port->fdes p) 1)
910 (execl (string-append cu "/bin/uname")
911 "uname" "-a")))))
dd1a5a15
LC
912 (drv (build-expression->derivation %store "uname" builder
913 #:inputs
2acb2cb6 914 `(("cu" ,%coreutils))))
59688fc4 915 (succeeded? (build-derivations %store (list drv))))
d9085c23 916 (and succeeded?
59688fc4 917 (let ((p (derivation->output-path drv)))
d9085c23
LC
918 (string-contains (call-with-input-file p read-line) "GNU")))))
919
d9024884
LC
920(test-assert "build-expression->derivation with modules"
921 (let* ((builder `(begin
922 (use-modules (guix build utils))
923 (let ((out (assoc-ref %outputs "out")))
924 (mkdir-p (string-append out "/guile/guix/nix"))
925 #t)))
59688fc4 926 (drv (build-expression->derivation %store "test-with-modules"
dd1a5a15 927 builder
d9024884
LC
928 #:modules
929 '((guix build utils)))))
59688fc4
LC
930 (and (build-derivations %store (list drv))
931 (let* ((p (derivation->output-path drv))
d9024884
LC
932 (s (stat (string-append p "/guile/guix/nix"))))
933 (eq? (stat:type s) 'directory)))))
934
813986ac
LC
935(test-assert "build-expression->derivation: same fixed-output path"
936 (let* ((builder1 '(call-with-output-file %output
937 (lambda (p)
938 (write "hello" p))))
939 (builder2 '(call-with-output-file (pk 'difference-here! %output)
940 (lambda (p)
941 (write "hello" p))))
942 (hash (sha256 (string->utf8 "hello")))
dd1a5a15 943 (input1 (build-expression->derivation %store "fixed" builder1
813986ac
LC
944 #:hash hash
945 #:hash-algo 'sha256))
dd1a5a15 946 (input2 (build-expression->derivation %store "fixed" builder2
813986ac
LC
947 #:hash hash
948 #:hash-algo 'sha256))
949 (succeeded? (build-derivations %store (list input1 input2))))
950 (and succeeded?
59688fc4
LC
951 (not (string=? (derivation-file-name input1)
952 (derivation-file-name input2)))
953 (string=? (derivation->output-path input1)
954 (derivation->output-path input2)))))
813986ac 955
7bdd1f0e
LC
956(test-assert "build-expression->derivation with a fixed-output input"
957 (let* ((builder1 '(call-with-output-file %output
958 (lambda (p)
959 (write "hello" p))))
960 (builder2 '(call-with-output-file (pk 'difference-here! %output)
961 (lambda (p)
962 (write "hello" p))))
963 (hash (sha256 (string->utf8 "hello")))
dd1a5a15 964 (input1 (build-expression->derivation %store "fixed" builder1
7bdd1f0e
LC
965 #:hash hash
966 #:hash-algo 'sha256))
dd1a5a15 967 (input2 (build-expression->derivation %store "fixed" builder2
7bdd1f0e
LC
968 #:hash hash
969 #:hash-algo 'sha256))
970 (builder3 '(let ((input (assoc-ref %build-inputs "input")))
971 (call-with-output-file %output
972 (lambda (out)
973 (format #f "My input is ~a.~%" input)))))
dd1a5a15
LC
974 (final1 (build-expression->derivation %store "final" builder3
975 #:inputs
7bdd1f0e 976 `(("input" ,input1))))
dd1a5a15
LC
977 (final2 (build-expression->derivation %store "final" builder3
978 #:inputs
7bdd1f0e 979 `(("input" ,input2)))))
59688fc4
LC
980 (and (string=? (derivation->output-path final1)
981 (derivation->output-path final2))
982 (string=? (derivation->output-path final1)
983 (derivation-path->output-path
984 (derivation-file-name final1)))
7bdd1f0e
LC
985 (build-derivations %store (list final1 final2)))))
986
36bbbbd1
LC
987(test-assert "build-expression->derivation produces recursive fixed-output"
988 (let* ((builder '(begin
989 (use-modules (srfi srfi-26))
990 (mkdir %output)
991 (chdir %output)
992 (call-with-output-file "exe"
993 (cut display "executable" <>))
994 (chmod "exe" #o777)
995 (symlink "exe" "symlink")
996 (mkdir "subdir")))
997 (drv (build-expression->derivation %store "fixed-rec" builder
998 #:hash-algo 'sha256
999 #:hash (base32
1000 "10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p")
1001 #:recursive? #t)))
1002 (and (build-derivations %store (list drv))
1003 (let* ((dir (derivation->output-path drv))
1004 (exe (string-append dir "/exe"))
1005 (link (string-append dir "/symlink"))
1006 (subdir (string-append dir "/subdir")))
1007 (and (executable-file? exe)
1008 (string=? "executable"
1009 (call-with-input-file exe get-string-all))
1010 (string=? "exe" (readlink link))
1011 (file-is-directory? subdir))))))
1012
1013(test-assert "build-expression->derivation uses recursive fixed-output"
1014 (let* ((builder '(call-with-output-file %output
1015 (lambda (port)
1016 (display "hello" port))))
1017 (fixed (build-expression->derivation %store "small-fixed-rec"
1018 builder
1019 #:hash-algo 'sha256
1020 #:hash (base32
1021 "0sg9f58l1jj88w6pdrfdpj5x9b1zrwszk84j81zvby36q9whhhqa")
1022 #:recursive? #t))
1023 (in (derivation->output-path fixed))
1024 (builder `(begin
1025 (mkdir %output)
1026 (chdir %output)
1027 (symlink ,in "symlink")))
1028 (drv (build-expression->derivation %store "fixed-rec-user"
1029 builder
1030 #:inputs `(("fixed" ,fixed)))))
1031 (and (build-derivations %store (list drv))
1032 (let ((out (derivation->output-path drv)))
1033 (string=? (readlink (string-append out "/symlink")) in)))))
1034
858e9282 1035(test-assert "build-expression->derivation with #:references-graphs"
9c629a27
LC
1036 (let* ((input (add-text-to-store %store "foo" "hello"
1037 (list %bash %mkdir)))
1038 (builder '(copy-file "input" %output))
858e9282 1039 (drv (build-expression->derivation %store "references-graphs"
dd1a5a15 1040 builder
858e9282 1041 #:references-graphs
9c629a27 1042 `(("input" . ,input))))
59688fc4 1043 (out (derivation->output-path drv)))
9c629a27
LC
1044 (define (deps path . deps)
1045 (let ((count (length deps)))
1046 (string-append path "\n\n" (number->string count) "\n"
1047 (string-join (sort deps string<?) "\n")
1048 (if (zero? count) "" "\n"))))
1049
1050 (and (build-derivations %store (list drv))
1051 (equal? (call-with-input-file out get-string-all)
1052 (string-concatenate
1053 (map cdr
1054 (sort (map (lambda (p d)
1055 (cons p (apply deps p d)))
1056 (list input %bash %mkdir)
1057 (list (list %bash %mkdir)
1058 '() '()))
1059 (lambda (x y)
1060 (match x
1061 ((p1 . _)
1062 (match y
1063 ((p2 . _)
1064 (string<? p1 p2)))))))))))))
1065
e387ab7c
LC
1066(test-equal "map-derivation"
1067 "hello"
1068 (let* ((joke (package-derivation %store guile-1.8))
1069 (good (package-derivation %store %bootstrap-guile))
1070 (drv1 (build-expression->derivation %store "original-drv1"
e387ab7c 1071 #f ; systematically fail
e387ab7c
LC
1072 #:guile-for-build joke))
1073 (drv2 (build-expression->derivation %store "original-drv2"
e387ab7c
LC
1074 '(call-with-output-file %output
1075 (lambda (p)
dd1a5a15 1076 (display "hello" p)))))
e387ab7c 1077 (drv3 (build-expression->derivation %store "drv-to-remap"
e387ab7c
LC
1078 '(let ((in (assoc-ref
1079 %build-inputs "in")))
1080 (copy-file in %output))
dd1a5a15 1081 #:inputs `(("in" ,drv1))
e387ab7c
LC
1082 #:guile-for-build joke))
1083 (drv4 (map-derivation %store drv3 `((,drv1 . ,drv2)
1084 (,joke . ,good))))
1085 (out (derivation->output-path drv4)))
1086 (and (build-derivations %store (list (pk 'remapped drv4)))
1087 (call-with-input-file out get-string-all))))
1088
a716e36d
LC
1089(test-equal "map-derivation, sources"
1090 "hello"
1091 (let* ((script1 (add-text-to-store %store "fail.sh" "exit 1"))
1092 (script2 (add-text-to-store %store "hi.sh" "echo -n hello > $out"))
1093 (bash-full (package-derivation %store (@ (gnu packages bash) bash)))
1094 (drv1 (derivation %store "drv-to-remap"
1095
1096 ;; XXX: This wouldn't work in practice, but if
1097 ;; we append "/bin/bash" then we can't replace
1098 ;; it with the bootstrap bash, which is a
1099 ;; single file.
1100 (derivation->output-path bash-full)
1101
1102 `("-e" ,script1)
1103 #:inputs `((,bash-full) (,script1))))
1104 (drv2 (map-derivation %store drv1
1105 `((,bash-full . ,%bash)
1106 (,script1 . ,script2))))
1107 (out (derivation->output-path drv2)))
1108 (and (build-derivations %store (list (pk 'remapped* drv2)))
1109 (call-with-input-file out get-string-all))))
1110
341c6fdd 1111(test-end)