profiles: Remove duplicates in manifest transactions.
[jackhill/guix/guix.git] / tests / profiles.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
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.
11 ;;;
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.
16 ;;;
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/>.
19
20 (define-module (test-profiles)
21 #:use-module (guix tests)
22 #:use-module (guix profiles)
23 #:use-module (guix gexp)
24 #:use-module (guix store)
25 #:use-module (guix monads)
26 #:use-module (guix grafts)
27 #:use-module (guix packages)
28 #:use-module (guix derivations)
29 #:use-module (guix build-system trivial)
30 #:use-module (gnu packages bootstrap)
31 #:use-module ((gnu packages base) #:prefix packages:)
32 #:use-module ((gnu packages guile) #:prefix packages:)
33 #:use-module (ice-9 match)
34 #:use-module (ice-9 regex)
35 #:use-module (ice-9 popen)
36 #:use-module (rnrs io ports)
37 #:use-module (srfi srfi-1)
38 #:use-module (srfi srfi-11)
39 #:use-module (srfi srfi-34)
40 #:use-module (srfi srfi-64))
41
42 ;; Test the (guix profiles) module.
43
44 (define %store
45 (open-connection-for-tests))
46
47 ;; Globally disable grafts because they can trigger early builds.
48 (%graft? #f)
49
50 ;; Example manifest entries.
51
52 (define guile-1.8.8
53 (manifest-entry
54 (name "guile")
55 (version "1.8.8")
56 (item "/gnu/store/...")
57 (output "out")))
58
59 (define guile-2.0.9
60 (manifest-entry
61 (name "guile")
62 (version "2.0.9")
63 (item "/gnu/store/...")
64 (output "out")))
65
66 (define guile-2.0.9:debug
67 (manifest-entry (inherit guile-2.0.9)
68 (output "debug")))
69
70 (define glibc
71 (manifest-entry
72 (name "glibc")
73 (version "2.19")
74 (item "/gnu/store/...")
75 (output "out")))
76
77 \f
78 (test-begin "profiles")
79
80 (test-assert "manifest-installed?"
81 (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug))))
82 (and (manifest-installed? m (manifest-pattern (name "guile")))
83 (manifest-installed? m (manifest-pattern
84 (name "guile") (output "debug")))
85 (manifest-installed? m (manifest-pattern
86 (name "guile") (output "out")
87 (version "2.0.9")))
88 (not (manifest-installed?
89 m (manifest-pattern (name "guile") (version "1.8.8"))))
90 (not (manifest-installed?
91 m (manifest-pattern (name "guile") (output "foobar")))))))
92
93 (test-assert "manifest-matching-entries"
94 (let* ((e (list guile-2.0.9 guile-2.0.9:debug))
95 (m (manifest e)))
96 (and (equal? e
97 (manifest-matching-entries m
98 (list (manifest-pattern
99 (name "guile")
100 (output #f)))))
101 (equal? (list guile-2.0.9)
102 (manifest-matching-entries m
103 (list (manifest-pattern
104 (name "guile")
105 (version "2.0.9"))))))))
106
107 (test-assert "manifest-matching-entries, no match"
108 (let ((m (manifest (list guile-2.0.9)))
109 (p (manifest-pattern (name "python"))))
110 (guard (c ((unmatched-pattern-error? c)
111 (and (eq? p (unmatched-pattern-error-pattern c))
112 (eq? m (unmatched-pattern-error-manifest c)))))
113 (manifest-matching-entries m (list p))
114 #f)))
115
116 (test-equal "concatenate-manifests"
117 (manifest (list guile-2.0.9 glibc))
118 (concatenate-manifests (list (manifest (list guile-2.0.9))
119 (manifest (list glibc)))))
120
121 (test-assert "manifest-remove"
122 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
123 (m1 (manifest-remove m0
124 (list (manifest-pattern (name "guile")))))
125 (m2 (manifest-remove m1
126 (list (manifest-pattern (name "guile"))))) ; same
127 (m3 (manifest-remove m2
128 (list (manifest-pattern
129 (name "guile") (output "debug")))))
130 (m4 (manifest-remove m3
131 (list (manifest-pattern (name "guile"))))))
132 (match (manifest-entries m2)
133 ((($ <manifest-entry> "guile" "2.0.9" "debug"))
134 (and (equal? m1 m2)
135 (null? (manifest-entries m3))
136 (null? (manifest-entries m4)))))))
137
138 (test-assert "manifest-add"
139 (let* ((m0 (manifest '()))
140 (m1 (manifest-add m0 (list guile-1.8.8)))
141 (m2 (manifest-add m1 (list guile-2.0.9)))
142 (m3 (manifest-add m2 (list guile-2.0.9:debug)))
143 (m4 (manifest-add m3 (list guile-2.0.9:debug))))
144 (and (match (manifest-entries m1)
145 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
146 (_ #f))
147 (match (manifest-entries m2)
148 ((($ <manifest-entry> "guile" "2.0.9" "out")) #t)
149 (_ #f))
150 (equal? m3 m4))))
151
152 (test-equal "manifest-add removes duplicates" ;<https://bugs.gnu.org/30569>
153 (list guile-2.0.9)
154 (manifest-entries (manifest-add (manifest '())
155 (list guile-2.0.9 guile-2.0.9))))
156
157 (test-assert "manifest-perform-transaction"
158 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
159 (t1 (manifest-transaction
160 (install (list guile-1.8.8))
161 (remove (list (manifest-pattern (name "guile")
162 (output "debug"))))))
163 (t2 (manifest-transaction
164 (remove (list (manifest-pattern (name "guile")
165 (version "2.0.9")
166 (output #f))))))
167 (m1 (manifest-perform-transaction m0 t1))
168 (m2 (manifest-perform-transaction m1 t2))
169 (m3 (manifest-perform-transaction m0 t2)))
170 (and (match (manifest-entries m1)
171 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
172 (_ #f))
173 (equal? m1 m2)
174 (null? (manifest-entries m3)))))
175
176 (test-assert "manifest-transaction-effects"
177 (let* ((m0 (manifest (list guile-1.8.8)))
178 (t (manifest-transaction
179 (install (list guile-2.0.9 glibc)))))
180 (let-values (((remove install upgrade downgrade)
181 (manifest-transaction-effects m0 t)))
182 (and (null? remove) (null? downgrade)
183 (equal? (list glibc) install)
184 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
185
186 (test-assert "manifest-transaction-effects no double install or upgrades"
187 (let* ((m0 (manifest (list guile-1.8.8)))
188 (t (manifest-transaction
189 (install (list guile-2.0.9 glibc glibc)))))
190 (let-values (((remove install upgrade downgrade)
191 (manifest-transaction-effects m0 t)))
192 (and (null? remove) (null? downgrade)
193 (equal? (list glibc) install)
194 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
195
196 (test-assert "manifest-transaction-effects and downgrades"
197 (let* ((m0 (manifest (list guile-2.0.9)))
198 (t (manifest-transaction (install (list guile-1.8.8)))))
199 (let-values (((remove install upgrade downgrade)
200 (manifest-transaction-effects m0 t)))
201 (and (null? remove) (null? install) (null? upgrade)
202 (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
203
204 (test-assert "manifest-transaction-effects no double downgrade"
205 (let* ((m0 (manifest (list guile-2.0.9)))
206 (t (manifest-transaction (install (list guile-1.8.8 guile-1.8.8)))))
207 (let-values (((remove install upgrade downgrade)
208 (manifest-transaction-effects m0 t)))
209 (and (null? remove) (null? install) (null? upgrade)
210 (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
211
212 (test-assert "manifest-transaction-effects and pseudo-upgrades"
213 (let* ((m0 (manifest (list guile-2.0.9)))
214 (t (manifest-transaction (install (list guile-2.0.9)))))
215 (let-values (((remove install upgrade downgrade)
216 (manifest-transaction-effects m0 t)))
217 (and (null? remove) (null? install) (null? downgrade)
218 (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade)))))
219
220 (test-assert "manifest-transaction-null?"
221 (manifest-transaction-null? (manifest-transaction)))
222
223 (test-assert "manifest-transaction-removal-candidate?"
224 (let ((m (manifest (list guile-2.0.9)))
225 (t (manifest-transaction
226 (remove (list (manifest-pattern (name "guile")))))))
227 (and (manifest-transaction-removal-candidate? guile-2.0.9 t)
228 (not (manifest-transaction-removal-candidate? glibc t)))))
229
230 (test-assert "manifest-transaction-effects no double removal"
231 (let* ((m0 (manifest (list guile-2.0.9)))
232 (t (manifest-transaction
233 (remove (list (manifest-pattern (name "guile")))))))
234 (let-values (((remove install upgrade downgrade)
235 (manifest-transaction-effects m0 t)))
236 (and (= 1 (length remove))
237 (manifest-transaction-removal-candidate? guile-2.0.9 t)
238 (null? install) (null? downgrade) (null? upgrade)))))
239
240 (test-assertm "profile-derivation"
241 (mlet* %store-monad
242 ((entry -> (package->manifest-entry %bootstrap-guile))
243 (guile (package->derivation %bootstrap-guile))
244 (drv (profile-derivation (manifest (list entry))
245 #:hooks '()
246 #:locales? #f))
247 (profile -> (derivation->output-path drv))
248 (bindir -> (string-append profile "/bin"))
249 (_ (built-derivations (list drv))))
250 (return (and (file-exists? (string-append bindir "/guile"))
251 (string=? (dirname (readlink bindir))
252 (derivation->output-path guile))))))
253
254 (test-assertm "<profile>"
255 (mlet* %store-monad
256 ((entry -> (package->manifest-entry %bootstrap-guile))
257 (profile -> (profile (hooks '()) (locales? #f)
258 (content (manifest (list entry)))))
259 (drv (lower-object profile))
260 (profile -> (derivation->output-path drv))
261 (bindir -> (string-append profile "/bin"))
262 (_ (built-derivations (list drv))))
263 (return (file-exists? (string-append bindir "/guile")))))
264
265 (test-assertm "profile-derivation relative symlinks, one entry"
266 (mlet* %store-monad
267 ((entry -> (package->manifest-entry %bootstrap-guile))
268 (guile (package->derivation %bootstrap-guile))
269 (drv (profile-derivation (manifest (list entry))
270 #:relative-symlinks? #t
271 #:hooks '()
272 #:locales? #f))
273 (profile -> (derivation->output-path drv))
274 (bindir -> (string-append profile "/bin"))
275 (_ (built-derivations (list drv))))
276 (return (and (file-exists? (string-append bindir "/guile"))
277 (string=? (readlink bindir)
278 (string-append "../"
279 (basename
280 (derivation->output-path guile))
281 "/bin"))))))
282
283 (unless (network-reachable?) (test-skip 1))
284 (test-assertm "profile-derivation relative symlinks, two entries"
285 (mlet* %store-monad
286 ((manifest -> (packages->manifest
287 (list %bootstrap-guile gnu-make-for-tests)))
288 (guile (package->derivation %bootstrap-guile))
289 (make (package->derivation gnu-make-for-tests))
290 (drv (profile-derivation manifest
291 #:relative-symlinks? #t
292 #:hooks '()
293 #:locales? #f))
294 (profile -> (derivation->output-path drv))
295 (bindir -> (string-append profile "/bin"))
296 (_ (built-derivations (list drv))))
297 (return (and (file-exists? (string-append bindir "/guile"))
298 (file-exists? (string-append bindir "/make"))
299 (string=? (readlink (string-append bindir "/guile"))
300 (string-append "../../"
301 (basename
302 (derivation->output-path guile))
303 "/bin/guile"))
304 (string=? (readlink (string-append bindir "/make"))
305 (string-append "../../"
306 (basename
307 (derivation->output-path make))
308 "/bin/make"))))))
309
310 (test-assertm "profile-derivation, inputs"
311 (mlet* %store-monad
312 ((entry -> (package->manifest-entry packages:glibc "debug"))
313 (drv (profile-derivation (manifest (list entry))
314 #:hooks '()
315 #:locales? #f)))
316 (return (derivation-inputs drv))))
317
318 (test-assertm "profile-derivation, cross-compilation"
319 (mlet* %store-monad
320 ((manifest -> (packages->manifest (list packages:sed packages:grep)))
321 (target -> "arm-linux-gnueabihf")
322 (grep (package->cross-derivation packages:grep target))
323 (sed (package->cross-derivation packages:sed target))
324 (locales (package->derivation packages:glibc-utf8-locales))
325 (drv (profile-derivation manifest
326 #:hooks '()
327 #:locales? #t
328 #:target target)))
329 (define (find-input package)
330 (let ((name (string-append (package-full-name package "-") ".drv")))
331 (any (lambda (input)
332 (let ((input (derivation-input-path input)))
333 (and (string-suffix? name input) input)))
334 (derivation-inputs drv))))
335
336 ;; The inputs for grep and sed should be cross-build derivations, but that
337 ;; for the glibc-utf8-locales should be a native build.
338 (return (and (string=? (derivation-system drv) (%current-system))
339 (string=? (find-input packages:grep)
340 (derivation-file-name grep))
341 (string=? (find-input packages:sed)
342 (derivation-file-name sed))
343 (string=? (find-input packages:glibc-utf8-locales)
344 (derivation-file-name locales))))))
345
346 (test-assert "package->manifest-entry defaults to \"out\""
347 (let ((outputs (package-outputs packages:glibc)))
348 (equal? (manifest-entry-output
349 (package->manifest-entry (package
350 (inherit packages:glibc)
351 (outputs (reverse outputs)))))
352 (manifest-entry-output
353 (package->manifest-entry packages:glibc))
354 "out")))
355
356 (test-assertm "profile-manifest, search-paths"
357 (mlet* %store-monad
358 ((guile -> (package
359 (inherit %bootstrap-guile)
360 (native-search-paths
361 (package-native-search-paths packages:guile-2.0))))
362 (entry -> (package->manifest-entry guile))
363 (drv (profile-derivation (manifest (list entry))
364 #:hooks '()
365 #:locales? #f))
366 (profile -> (derivation->output-path drv)))
367 (mbegin %store-monad
368 (built-derivations (list drv))
369
370 ;; Read the manifest back and make sure search paths are preserved.
371 (let ((manifest (profile-manifest profile)))
372 (match (manifest-entries manifest)
373 ((result)
374 (return (equal? (manifest-entry-search-paths result)
375 (manifest-entry-search-paths entry)
376 (package-native-search-paths
377 packages:guile-2.0)))))))))
378
379 (test-assert "package->manifest-entry, search paths"
380 ;; See <http://bugs.gnu.org/22073>.
381 (let ((mpl (@ (gnu packages python-xyz) python2-matplotlib)))
382 (lset= eq?
383 (package-transitive-native-search-paths mpl)
384 (manifest-entry-search-paths
385 (package->manifest-entry mpl)))))
386
387 (test-equal "packages->manifest, propagated inputs"
388 (map (match-lambda
389 ((label package)
390 (list (package-name package) (package-version package)
391 package)))
392 (package-propagated-inputs packages:guile-2.2))
393 (map (lambda (entry)
394 (list (manifest-entry-name entry)
395 (manifest-entry-version entry)
396 (manifest-entry-item entry)))
397 (manifest-entry-dependencies
398 (package->manifest-entry packages:guile-2.2))))
399
400 (test-assert "manifest-entry-parent"
401 (let ((entry (package->manifest-entry packages:guile-2.2)))
402 (match (manifest-entry-dependencies entry)
403 ((dependencies ..1)
404 (and (every (lambda (parent)
405 (eq? entry (force parent)))
406 (map manifest-entry-parent dependencies))
407 (not (force (manifest-entry-parent entry))))))))
408
409 (test-assertm "read-manifest"
410 (mlet* %store-monad ((manifest -> (packages->manifest
411 (list (package
412 (inherit %bootstrap-guile)
413 (native-search-paths
414 (package-native-search-paths
415 packages:guile-2.0))))))
416 (drv (profile-derivation manifest
417 #:hooks '()
418 #:locales? #f))
419 (out -> (derivation->output-path drv)))
420 (define (entry->sexp entry)
421 (list (manifest-entry-name entry)
422 (manifest-entry-version entry)
423 (manifest-entry-search-paths entry)
424 (manifest-entry-dependencies entry)
425 (force (manifest-entry-parent entry))))
426
427 (mbegin %store-monad
428 (built-derivations (list drv))
429 (let ((manifest2 (profile-manifest out)))
430 (return (equal? (map entry->sexp (manifest-entries manifest))
431 (map entry->sexp (manifest-entries manifest2))))))))
432
433 (test-equal "collision"
434 '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
435 (guard (c ((profile-collision-error? c)
436 (let ((entry1 (profile-collision-error-entry c))
437 (entry2 (profile-collision-error-conflict c)))
438 (list (list (manifest-entry-name entry1)
439 (manifest-entry-version entry1))
440 (list (manifest-entry-name entry2)
441 (manifest-entry-version entry2))))))
442 (run-with-store %store
443 (mlet* %store-monad ((p0 -> (package
444 (inherit %bootstrap-guile)
445 (version "42")))
446 (p1 -> (dummy-package "p1"
447 (propagated-inputs `(("p0" ,p0)))))
448 (manifest -> (packages->manifest
449 (list %bootstrap-guile p1)))
450 (drv (profile-derivation manifest
451 #:hooks '()
452 #:locales? #f)))
453 (return #f)))))
454
455 (test-equal "collision of propagated inputs"
456 '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
457 (guard (c ((profile-collision-error? c)
458 (let ((entry1 (profile-collision-error-entry c))
459 (entry2 (profile-collision-error-conflict c)))
460 (list (list (manifest-entry-name entry1)
461 (manifest-entry-version entry1))
462 (list (manifest-entry-name entry2)
463 (manifest-entry-version entry2))))))
464 (run-with-store %store
465 (mlet* %store-monad ((p0 -> (package
466 (inherit %bootstrap-guile)
467 (version "42")))
468 (p1 -> (dummy-package "p1"
469 (propagated-inputs
470 `(("guile" ,%bootstrap-guile)))))
471 (p2 -> (dummy-package "p2"
472 (propagated-inputs
473 `(("guile" ,p0)))))
474 (manifest -> (packages->manifest (list p1 p2)))
475 (drv (profile-derivation manifest
476 #:hooks '()
477 #:locales? #f)))
478 (return #f)))))
479
480 (test-assertm "no collision"
481 ;; Here we have an entry that is "lowered" (its 'item' field is a store file
482 ;; name) and another entry (its 'item' field is a package) that is
483 ;; equivalent.
484 (mlet* %store-monad ((p -> (dummy-package "p"
485 (propagated-inputs
486 `(("guile" ,%bootstrap-guile)))))
487 (guile (package->derivation %bootstrap-guile))
488 (entry -> (manifest-entry
489 (inherit (package->manifest-entry
490 %bootstrap-guile))
491 (item (derivation->output-path guile))))
492 (manifest -> (manifest
493 (list entry
494 (package->manifest-entry p))))
495 (drv (profile-derivation manifest)))
496 (return (->bool drv))))
497
498 (test-assertm "etc/profile"
499 ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
500 (mlet* %store-monad
501 ((guile -> (package
502 (inherit %bootstrap-guile)
503 (native-search-paths
504 (package-native-search-paths packages:guile-2.0))))
505 (entry -> (package->manifest-entry guile))
506 (drv (profile-derivation (manifest (list entry))
507 #:hooks '()
508 #:locales? #f))
509 (profile -> (derivation->output-path drv)))
510 (mbegin %store-monad
511 (built-derivations (list drv))
512 (let* ((pipe (open-input-pipe
513 (string-append "unset GUIX_PROFILE; "
514 ;; 'source' is a Bashism; use '.' (dot).
515 ". " profile "/etc/profile; "
516 ;; Don't try to parse set(1) output because
517 ;; it differs among shells; just use echo.
518 "echo $PATH")))
519 (path (get-string-all pipe)))
520 (return
521 (and (zero? (close-pipe pipe))
522 (string-contains path (string-append profile "/bin"))))))))
523
524 (test-assertm "etc/profile when etc/ already exists"
525 ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
526 ;; etc/ directory, which makes it read-only. Make sure the profile build
527 ;; handles that.
528 (mlet* %store-monad
529 ((thing -> (dummy-package "dummy"
530 (build-system trivial-build-system)
531 (arguments
532 `(#:guile ,%bootstrap-guile
533 #:builder
534 (let ((out (assoc-ref %outputs "out")))
535 (mkdir out)
536 (mkdir (string-append out "/etc"))
537 (call-with-output-file (string-append out "/etc/foo")
538 (lambda (port)
539 (display "foo!" port)))
540 #t)))))
541 (entry -> (package->manifest-entry thing))
542 (drv (profile-derivation (manifest (list entry))
543 #:hooks '()
544 #:locales? #f))
545 (profile -> (derivation->output-path drv)))
546 (mbegin %store-monad
547 (built-derivations (list drv))
548 (return (and (file-exists? (string-append profile "/etc/profile"))
549 (string=? (call-with-input-file
550 (string-append profile "/etc/foo")
551 get-string-all)
552 "foo!"))))))
553
554 (test-assertm "etc/profile when etc/ is a symlink"
555 ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
556 ;; gracelessly because 'scandir' would return #f.
557 (mlet* %store-monad
558 ((thing -> (dummy-package "dummy"
559 (build-system trivial-build-system)
560 (arguments
561 `(#:guile ,%bootstrap-guile
562 #:builder
563 (let ((out (assoc-ref %outputs "out")))
564 (mkdir out)
565 (mkdir (string-append out "/foo"))
566 (symlink "foo" (string-append out "/etc"))
567 (call-with-output-file (string-append out "/etc/bar")
568 (lambda (port)
569 (display "foo!" port)))
570 #t)))))
571 (entry -> (package->manifest-entry thing))
572 (drv (profile-derivation (manifest (list entry))
573 #:hooks '()
574 #:locales? #f))
575 (profile -> (derivation->output-path drv)))
576 (mbegin %store-monad
577 (built-derivations (list drv))
578 (return (and (file-exists? (string-append profile "/etc/profile"))
579 (string=? (call-with-input-file
580 (string-append profile "/etc/bar")
581 get-string-all)
582 "foo!"))))))
583
584 (test-assertm "profile-derivation when etc/ is a relative symlink"
585 ;; See <https://bugs.gnu.org/32686>.
586 (mlet* %store-monad
587 ((etc (gexp->derivation
588 "etc"
589 #~(begin
590 (mkdir #$output)
591 (call-with-output-file (string-append #$output "/foo")
592 (lambda (port)
593 (display "Heya!" port))))))
594 (thing -> (dummy-package "dummy"
595 (build-system trivial-build-system)
596 (inputs
597 `(("etc" ,etc)))
598 (arguments
599 `(#:guile ,%bootstrap-guile
600 #:builder
601 (let ((out (assoc-ref %outputs "out"))
602 (etc (assoc-ref %build-inputs "etc")))
603 (mkdir out)
604 (symlink etc (string-append out "/etc"))
605 #t)))))
606 (entry -> (package->manifest-entry thing))
607 (drv (profile-derivation (manifest (list entry))
608 #:relative-symlinks? #t
609 #:hooks '()
610 #:locales? #f))
611 (profile -> (derivation->output-path drv)))
612 (mbegin %store-monad
613 (built-derivations (list drv))
614 (return (string=? (call-with-input-file
615 (string-append profile "/etc/foo")
616 get-string-all)
617 "Heya!")))))
618
619 (test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949>
620 "does-not-exist"
621 (mlet* %store-monad
622 ((thing1 -> (dummy-package "dummy"
623 (build-system trivial-build-system)
624 (arguments
625 `(#:guile ,%bootstrap-guile
626 #:builder
627 (let ((out (assoc-ref %outputs "out")))
628 (mkdir out)
629 (symlink "does-not-exist"
630 (string-append out "/dangling"))
631 #t)))))
632 (thing2 -> (package (inherit thing1) (name "dummy2")))
633 (drv (profile-derivation (packages->manifest
634 (list thing1 thing2))
635 #:hooks '()
636 #:locales? #f))
637 (profile -> (derivation->output-path drv)))
638 (mbegin %store-monad
639 (built-derivations (list drv))
640 (return (readlink (readlink (string-append profile "/dangling")))))))
641
642 (test-equalm "profile in profile"
643 '("foo" "0")
644
645 ;; Make sure we can build a profile that has another profile has one of its
646 ;; entries. The new profile's /manifest and /etc/profile must override the
647 ;; other's.
648 (mlet* %store-monad
649 ((prof0 (profile-derivation
650 (manifest
651 (list (package->manifest-entry %bootstrap-guile)))
652 #:hooks '()
653 #:locales? #f))
654 (prof1 (profile-derivation
655 (manifest (list (manifest-entry
656 (name "foo")
657 (version "0")
658 (item prof0))))
659 #:hooks '()
660 #:locales? #f)))
661 (mbegin %store-monad
662 (built-derivations (list prof1))
663 (let ((out (derivation->output-path prof1)))
664 (return (and (file-exists?
665 (string-append out "/bin/guile"))
666 (let ((manifest (profile-manifest out)))
667 (match (manifest-entries manifest)
668 ((entry)
669 (list (manifest-entry-name entry)
670 (manifest-entry-version entry)))))))))))
671
672 (test-end "profiles")
673
674 ;;; Local Variables:
675 ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
676 ;;; End: