profiles: Build union of inputs in the right order.
[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, 2021 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-equal "manifest->code, simple"
158 '(begin
159 (specifications->manifest (list "guile" "guile:debug" "glibc")))
160 (manifest->code (manifest (list guile-2.0.9 guile-2.0.9:debug glibc))))
161
162 (test-equal "manifest->code, simple, versions"
163 '(begin
164 (specifications->manifest (list "guile@2.0.9" "guile@2.0.9:debug"
165 "glibc@2.19")))
166 (manifest->code (manifest (list guile-2.0.9 guile-2.0.9:debug glibc))
167 #:entry-package-version manifest-entry-version))
168
169 (test-equal "manifest->code, transformations"
170 '(begin
171 (use-modules (guix transformations))
172
173 (define transform1
174 (options->transformation '((foo . "bar"))))
175
176 (packages->manifest
177 (list (transform1 (specification->package "guile"))
178 (specification->package "glibc"))))
179 (manifest->code (manifest (list (manifest-entry
180 (inherit guile-2.0.9)
181 (properties `((transformations
182 . ((foo . "bar"))))))
183 glibc))))
184
185 (test-assert "manifest-perform-transaction"
186 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
187 (t1 (manifest-transaction
188 (install (list guile-1.8.8))
189 (remove (list (manifest-pattern (name "guile")
190 (output "debug"))))))
191 (t2 (manifest-transaction
192 (remove (list (manifest-pattern (name "guile")
193 (version "2.0.9")
194 (output #f))))))
195 (m1 (manifest-perform-transaction m0 t1))
196 (m2 (manifest-perform-transaction m1 t2))
197 (m3 (manifest-perform-transaction m0 t2)))
198 (and (match (manifest-entries m1)
199 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
200 (_ #f))
201 (equal? m1 m2)
202 (null? (manifest-entries m3)))))
203
204 (test-assert "manifest-transaction-effects"
205 (let* ((m0 (manifest (list guile-1.8.8)))
206 (t (manifest-transaction
207 (install (list guile-2.0.9 glibc)))))
208 (let-values (((remove install upgrade downgrade)
209 (manifest-transaction-effects m0 t)))
210 (and (null? remove) (null? downgrade)
211 (equal? (list glibc) install)
212 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
213
214 (test-assert "manifest-transaction-effects no double install or upgrades"
215 (let* ((m0 (manifest (list guile-1.8.8)))
216 (t (manifest-transaction
217 (install (list guile-2.0.9 glibc glibc)))))
218 (let-values (((remove install upgrade downgrade)
219 (manifest-transaction-effects m0 t)))
220 (and (null? remove) (null? downgrade)
221 (equal? (list glibc) install)
222 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
223
224 (test-assert "manifest-transaction-effects and downgrades"
225 (let* ((m0 (manifest (list guile-2.0.9)))
226 (t (manifest-transaction (install (list guile-1.8.8)))))
227 (let-values (((remove install upgrade downgrade)
228 (manifest-transaction-effects m0 t)))
229 (and (null? remove) (null? install) (null? upgrade)
230 (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
231
232 (test-assert "manifest-transaction-effects no double downgrade"
233 (let* ((m0 (manifest (list guile-2.0.9)))
234 (t (manifest-transaction (install (list guile-1.8.8 guile-1.8.8)))))
235 (let-values (((remove install upgrade downgrade)
236 (manifest-transaction-effects m0 t)))
237 (and (null? remove) (null? install) (null? upgrade)
238 (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
239
240 (test-assert "manifest-transaction-effects and pseudo-upgrades"
241 (let* ((m0 (manifest (list guile-2.0.9)))
242 (t (manifest-transaction (install (list guile-2.0.9)))))
243 (let-values (((remove install upgrade downgrade)
244 (manifest-transaction-effects m0 t)))
245 (and (null? remove) (null? install) (null? downgrade)
246 (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade)))))
247
248 (test-assert "manifest-transaction-null?"
249 (manifest-transaction-null? (manifest-transaction)))
250
251 (test-assert "manifest-transaction-removal-candidate?"
252 (let ((m (manifest (list guile-2.0.9)))
253 (t (manifest-transaction
254 (remove (list (manifest-pattern (name "guile")))))))
255 (and (manifest-transaction-removal-candidate? guile-2.0.9 t)
256 (not (manifest-transaction-removal-candidate? glibc t)))))
257
258 (test-assert "manifest-transaction-effects no double removal"
259 (let* ((m0 (manifest (list guile-2.0.9)))
260 (t (manifest-transaction
261 (remove (list (manifest-pattern (name "guile")))))))
262 (let-values (((remove install upgrade downgrade)
263 (manifest-transaction-effects m0 t)))
264 (and (= 1 (length remove))
265 (manifest-transaction-removal-candidate? guile-2.0.9 t)
266 (null? install) (null? downgrade) (null? upgrade)))))
267
268 (test-assertm "profile-derivation"
269 (mlet* %store-monad
270 ((entry -> (package->manifest-entry %bootstrap-guile))
271 (guile (package->derivation %bootstrap-guile))
272 (drv (profile-derivation (manifest (list entry))
273 #:hooks '()
274 #:locales? #f))
275 (profile -> (derivation->output-path drv))
276 (bindir -> (string-append profile "/bin"))
277 (_ (built-derivations (list drv))))
278 (return (and (file-exists? (string-append bindir "/guile"))
279 (string=? (dirname (readlink bindir))
280 (derivation->output-path guile))))))
281
282 (test-assertm "profile-derivation, ordering & collisions"
283 ;; ENTRY1 and ENTRY2 both provide 'bin/guile'--a collision. Make sure
284 ;; ENTRY1 "wins" over ENTRY2. See <https://bugs.gnu.org/49102>.
285 (mlet* %store-monad
286 ((entry1 -> (package->manifest-entry %bootstrap-guile))
287 (entry2 -> (manifest-entry
288 (name "fake-guile")
289 (version "0")
290 (item (computed-file
291 "fake-guile"
292 #~(begin
293 (mkdir #$output)
294 (mkdir (string-append #$output "/bin"))
295 (call-with-output-file
296 (string-append #$output "/bin/guile")
297 (lambda (port)
298 (display "Fake!\n" port))))))))
299 (guile (package->derivation %bootstrap-guile))
300 (drv (profile-derivation (manifest (list entry1 entry2))
301 #:hooks '()
302 #:locales? #f))
303 (profile -> (derivation->output-path drv))
304 (bindir -> (string-append profile "/bin"))
305 (file -> (string-append bindir "/guile"))
306 (_ (built-derivations (list drv))))
307 (return (string=? (readlink file)
308 (string-append
309 (derivation->output-path guile)
310 "/bin/guile")))))
311
312 (test-assertm "load-profile"
313 (mlet* %store-monad
314 ((entry -> (package->manifest-entry %bootstrap-guile))
315 (guile (package->derivation %bootstrap-guile))
316 (drv (profile-derivation (manifest (list entry))
317 #:hooks '()
318 #:locales? #f))
319 (profile -> (derivation->output-path drv))
320 (bindir -> (string-append profile "/bin"))
321 (_ (built-derivations (list drv))))
322 (define-syntax-rule (with-environment-excursion exp ...)
323 (let ((env (environ)))
324 (dynamic-wind
325 (const #t)
326 (lambda () exp ...)
327 (lambda () (environ env)))))
328
329 (return (and (with-environment-excursion
330 (load-profile profile)
331 (and (string-prefix? (string-append bindir ":")
332 (getenv "PATH"))
333 (getenv "GUILE_LOAD_PATH")))
334 (with-environment-excursion
335 (load-profile profile #:pure? #t #:white-list '())
336 (equal? (list (string-append "PATH=" bindir))
337 (environ)))))))
338
339 (test-assertm "<profile>"
340 (mlet* %store-monad
341 ((entry -> (package->manifest-entry %bootstrap-guile))
342 (profile -> (profile (hooks '()) (locales? #f)
343 (content (manifest (list entry)))))
344 (drv (lower-object profile))
345 (profile -> (derivation->output-path drv))
346 (bindir -> (string-append profile "/bin"))
347 (_ (built-derivations (list drv))))
348 (return (file-exists? (string-append bindir "/guile")))))
349
350 (test-assertm "profile-derivation relative symlinks, one entry"
351 (mlet* %store-monad
352 ((entry -> (package->manifest-entry %bootstrap-guile))
353 (guile (package->derivation %bootstrap-guile))
354 (drv (profile-derivation (manifest (list entry))
355 #:relative-symlinks? #t
356 #:hooks '()
357 #:locales? #f))
358 (profile -> (derivation->output-path drv))
359 (bindir -> (string-append profile "/bin"))
360 (_ (built-derivations (list drv))))
361 (return (and (file-exists? (string-append bindir "/guile"))
362 (string=? (readlink bindir)
363 (string-append "../"
364 (basename
365 (derivation->output-path guile))
366 "/bin"))))))
367
368 (unless (network-reachable?) (test-skip 1))
369 (test-assertm "profile-derivation relative symlinks, two entries"
370 (mlet* %store-monad
371 ((manifest -> (packages->manifest
372 (list %bootstrap-guile gnu-make-for-tests)))
373 (guile (package->derivation %bootstrap-guile))
374 (make (package->derivation gnu-make-for-tests))
375 (drv (profile-derivation manifest
376 #:relative-symlinks? #t
377 #:hooks '()
378 #:locales? #f))
379 (profile -> (derivation->output-path drv))
380 (bindir -> (string-append profile "/bin"))
381 (_ (built-derivations (list drv))))
382 (return (and (file-exists? (string-append bindir "/guile"))
383 (file-exists? (string-append bindir "/make"))
384 (string=? (readlink (string-append bindir "/guile"))
385 (string-append "../../"
386 (basename
387 (derivation->output-path guile))
388 "/bin/guile"))
389 (string=? (readlink (string-append bindir "/make"))
390 (string-append "../../"
391 (basename
392 (derivation->output-path make))
393 "/bin/make"))))))
394
395 (test-assertm "profile-derivation, inputs"
396 (mlet* %store-monad
397 ((entry -> (package->manifest-entry packages:glibc "debug"))
398 (drv (profile-derivation (manifest (list entry))
399 #:hooks '()
400 #:locales? #f)))
401 (return (derivation-inputs drv))))
402
403 (test-assertm "profile-derivation, cross-compilation"
404 (mlet* %store-monad
405 ((manifest -> (packages->manifest (list packages:sed packages:grep)))
406 (target -> "arm-linux-gnueabihf")
407 (grep (package->cross-derivation packages:grep target))
408 (sed (package->cross-derivation packages:sed target))
409 (locales (package->derivation packages:glibc-utf8-locales))
410 (drv (profile-derivation manifest
411 #:hooks '()
412 #:locales? #t
413 #:target target)))
414 (define (find-input package)
415 (let ((name (string-append (package-full-name package "-") ".drv")))
416 (any (lambda (input)
417 (let ((input (derivation-input-path input)))
418 (and (string-suffix? name input) input)))
419 (derivation-inputs drv))))
420
421 ;; The inputs for grep and sed should be cross-build derivations, but that
422 ;; for the glibc-utf8-locales should be a native build.
423 (return (and (string=? (derivation-system drv) (%current-system))
424 (string=? (find-input packages:grep)
425 (derivation-file-name grep))
426 (string=? (find-input packages:sed)
427 (derivation-file-name sed))
428 (string=? (find-input packages:glibc-utf8-locales)
429 (derivation-file-name locales))))))
430
431 (test-assert "package->manifest-entry defaults to \"out\""
432 (let ((outputs (package-outputs packages:glibc)))
433 (equal? (manifest-entry-output
434 (package->manifest-entry (package
435 (inherit packages:glibc)
436 (outputs (reverse outputs)))))
437 (manifest-entry-output
438 (package->manifest-entry packages:glibc))
439 "out")))
440
441 (test-assertm "profile-manifest, search-paths"
442 (mlet* %store-monad
443 ((guile -> (package
444 (inherit %bootstrap-guile)
445 (native-search-paths
446 (package-native-search-paths packages:guile-2.0))))
447 (entry -> (package->manifest-entry guile))
448 (drv (profile-derivation (manifest (list entry))
449 #:hooks '()
450 #:locales? #f))
451 (profile -> (derivation->output-path drv)))
452 (mbegin %store-monad
453 (built-derivations (list drv))
454
455 ;; Read the manifest back and make sure search paths are preserved.
456 (let ((manifest (profile-manifest profile)))
457 (match (manifest-entries manifest)
458 ((result)
459 (return (equal? (manifest-entry-search-paths result)
460 (manifest-entry-search-paths entry)
461 (package-native-search-paths
462 packages:guile-2.0)))))))))
463
464 (test-assert "package->manifest-entry, search paths"
465 ;; See <http://bugs.gnu.org/22073>.
466 (let ((mpl (@ (gnu packages python-xyz) python2-matplotlib)))
467 (lset= eq?
468 (package-transitive-native-search-paths mpl)
469 (manifest-entry-search-paths
470 (package->manifest-entry mpl)))))
471
472 (test-assert "packages->manifest, no duplicates"
473 (let ((expected
474 (manifest
475 (list
476 (package->manifest-entry packages:guile-2.2))))
477 (manifest (packages->manifest
478 (list packages:guile-2.2 packages:guile-2.2))))
479 (every manifest-entry=? (manifest-entries expected)
480 (manifest-entries manifest))))
481
482 (test-equal "packages->manifest, propagated inputs"
483 (map (match-lambda
484 ((label package)
485 (list (package-name package) (package-version package)
486 package)))
487 (package-propagated-inputs packages:guile-2.2))
488 (map (lambda (entry)
489 (list (manifest-entry-name entry)
490 (manifest-entry-version entry)
491 (manifest-entry-item entry)))
492 (manifest-entry-dependencies
493 (package->manifest-entry packages:guile-2.2))))
494
495 (test-assert "manifest-entry-parent"
496 (let ((entry (package->manifest-entry packages:guile-2.2)))
497 (match (manifest-entry-dependencies entry)
498 ((dependencies ..1)
499 (and (every (lambda (parent)
500 (eq? entry (force parent)))
501 (map manifest-entry-parent dependencies))
502 (not (force (manifest-entry-parent entry))))))))
503
504 (test-assertm "read-manifest"
505 (mlet* %store-monad ((manifest -> (packages->manifest
506 (list (package
507 (inherit %bootstrap-guile)
508 (native-search-paths
509 (package-native-search-paths
510 packages:guile-2.0))))))
511 (drv (profile-derivation manifest
512 #:hooks '()
513 #:locales? #f))
514 (out -> (derivation->output-path drv)))
515 (define (entry->sexp entry)
516 (list (manifest-entry-name entry)
517 (manifest-entry-version entry)
518 (manifest-entry-search-paths entry)
519 (manifest-entry-dependencies entry)
520 (force (manifest-entry-parent entry))))
521
522 (mbegin %store-monad
523 (built-derivations (list drv))
524 (let ((manifest2 (profile-manifest out)))
525 (return (equal? (map entry->sexp (manifest-entries manifest))
526 (map entry->sexp (manifest-entries manifest2))))))))
527
528 (test-equal "collision"
529 '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
530 (guard (c ((profile-collision-error? c)
531 (let ((entry1 (profile-collision-error-entry c))
532 (entry2 (profile-collision-error-conflict c)))
533 (list (list (manifest-entry-name entry1)
534 (manifest-entry-version entry1))
535 (list (manifest-entry-name entry2)
536 (manifest-entry-version entry2))))))
537 (run-with-store %store
538 (mlet* %store-monad ((p0 -> (package
539 (inherit %bootstrap-guile)
540 (version "42")))
541 (p1 -> (dummy-package "p1"
542 (propagated-inputs `(("p0" ,p0)))))
543 (manifest -> (packages->manifest
544 (list %bootstrap-guile p1)))
545 (drv (profile-derivation manifest
546 #:hooks '()
547 #:locales? #f)))
548 (return #f)))))
549
550 (test-equal "collision of propagated inputs"
551 '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
552 (guard (c ((profile-collision-error? c)
553 (let ((entry1 (profile-collision-error-entry c))
554 (entry2 (profile-collision-error-conflict c)))
555 (list (list (manifest-entry-name entry1)
556 (manifest-entry-version entry1))
557 (list (manifest-entry-name entry2)
558 (manifest-entry-version entry2))))))
559 (run-with-store %store
560 (mlet* %store-monad ((p0 -> (package
561 (inherit %bootstrap-guile)
562 (version "42")))
563 (p1 -> (dummy-package "p1"
564 (propagated-inputs
565 `(("guile" ,%bootstrap-guile)))))
566 (p2 -> (dummy-package "p2"
567 (propagated-inputs
568 `(("guile" ,p0)))))
569 (manifest -> (packages->manifest (list p1 p2)))
570 (drv (profile-derivation manifest
571 #:hooks '()
572 #:locales? #f)))
573 (return #f)))))
574
575 (test-assertm "no collision"
576 ;; Here we have an entry that is "lowered" (its 'item' field is a store file
577 ;; name) and another entry (its 'item' field is a package) that is
578 ;; equivalent.
579 (mlet* %store-monad ((p -> (dummy-package "p"
580 (propagated-inputs
581 `(("guile" ,%bootstrap-guile)))))
582 (guile (package->derivation %bootstrap-guile))
583 (entry -> (manifest-entry
584 (inherit (package->manifest-entry
585 %bootstrap-guile))
586 (item (derivation->output-path guile))))
587 (manifest -> (manifest
588 (list entry
589 (package->manifest-entry p))))
590 (drv (profile-derivation manifest)))
591 (return (->bool drv))))
592
593 (test-assertm "etc/profile"
594 ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
595 (mlet* %store-monad
596 ((guile -> (package
597 (inherit %bootstrap-guile)
598 (native-search-paths
599 (package-native-search-paths packages:guile-2.0))))
600 (entry -> (package->manifest-entry guile))
601 (drv (profile-derivation (manifest (list entry))
602 #:hooks '()
603 #:locales? #f))
604 (profile -> (derivation->output-path drv)))
605 (mbegin %store-monad
606 (built-derivations (list drv))
607 (let* ((pipe (open-input-pipe
608 (string-append "unset GUIX_PROFILE; "
609 ;; 'source' is a Bashism; use '.' (dot).
610 ". " profile "/etc/profile; "
611 ;; Don't try to parse set(1) output because
612 ;; it differs among shells; just use echo.
613 "echo $PATH")))
614 (path (get-string-all pipe)))
615 (return
616 (and (zero? (close-pipe pipe))
617 (string-contains path (string-append profile "/bin"))))))))
618
619 (test-assertm "etc/profile when etc/ already exists"
620 ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
621 ;; etc/ directory, which makes it read-only. Make sure the profile build
622 ;; handles that.
623 (mlet* %store-monad
624 ((thing -> (dummy-package "dummy"
625 (build-system trivial-build-system)
626 (arguments
627 `(#:guile ,%bootstrap-guile
628 #:builder
629 (let ((out (assoc-ref %outputs "out")))
630 (mkdir out)
631 (mkdir (string-append out "/etc"))
632 (call-with-output-file (string-append out "/etc/foo")
633 (lambda (port)
634 (display "foo!" port)))
635 #t)))))
636 (entry -> (package->manifest-entry thing))
637 (drv (profile-derivation (manifest (list entry))
638 #:hooks '()
639 #:locales? #f))
640 (profile -> (derivation->output-path drv)))
641 (mbegin %store-monad
642 (built-derivations (list drv))
643 (return (and (file-exists? (string-append profile "/etc/profile"))
644 (string=? (call-with-input-file
645 (string-append profile "/etc/foo")
646 get-string-all)
647 "foo!"))))))
648
649 (test-assertm "etc/profile when etc/ is a symlink"
650 ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
651 ;; gracelessly because 'scandir' would return #f.
652 (mlet* %store-monad
653 ((thing -> (dummy-package "dummy"
654 (build-system trivial-build-system)
655 (arguments
656 `(#:guile ,%bootstrap-guile
657 #:builder
658 (let ((out (assoc-ref %outputs "out")))
659 (mkdir out)
660 (mkdir (string-append out "/foo"))
661 (symlink "foo" (string-append out "/etc"))
662 (call-with-output-file (string-append out "/etc/bar")
663 (lambda (port)
664 (display "foo!" port)))
665 #t)))))
666 (entry -> (package->manifest-entry thing))
667 (drv (profile-derivation (manifest (list entry))
668 #:hooks '()
669 #:locales? #f))
670 (profile -> (derivation->output-path drv)))
671 (mbegin %store-monad
672 (built-derivations (list drv))
673 (return (and (file-exists? (string-append profile "/etc/profile"))
674 (string=? (call-with-input-file
675 (string-append profile "/etc/bar")
676 get-string-all)
677 "foo!"))))))
678
679 (test-assertm "profile-derivation when etc/ is a relative symlink"
680 ;; See <https://bugs.gnu.org/32686>.
681 (mlet* %store-monad
682 ((etc (gexp->derivation
683 "etc"
684 #~(begin
685 (mkdir #$output)
686 (call-with-output-file (string-append #$output "/foo")
687 (lambda (port)
688 (display "Heya!" port))))))
689 (thing -> (dummy-package "dummy"
690 (build-system trivial-build-system)
691 (inputs
692 `(("etc" ,etc)))
693 (arguments
694 `(#:guile ,%bootstrap-guile
695 #:builder
696 (let ((out (assoc-ref %outputs "out"))
697 (etc (assoc-ref %build-inputs "etc")))
698 (mkdir out)
699 (symlink etc (string-append out "/etc"))
700 #t)))))
701 (entry -> (package->manifest-entry thing))
702 (drv (profile-derivation (manifest (list entry))
703 #:relative-symlinks? #t
704 #:hooks '()
705 #:locales? #f))
706 (profile -> (derivation->output-path drv)))
707 (mbegin %store-monad
708 (built-derivations (list drv))
709 (return (string=? (call-with-input-file
710 (string-append profile "/etc/foo")
711 get-string-all)
712 "Heya!")))))
713
714 (test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949>
715 "does-not-exist"
716 (mlet* %store-monad
717 ((thing1 -> (dummy-package "dummy"
718 (build-system trivial-build-system)
719 (arguments
720 `(#:guile ,%bootstrap-guile
721 #:builder
722 (let ((out (assoc-ref %outputs "out")))
723 (mkdir out)
724 (symlink "does-not-exist"
725 (string-append out "/dangling"))
726 #t)))))
727 (thing2 -> (package (inherit thing1) (name "dummy2")))
728 (drv (profile-derivation (packages->manifest
729 (list thing1 thing2))
730 #:hooks '()
731 #:locales? #f))
732 (profile -> (derivation->output-path drv)))
733 (mbegin %store-monad
734 (built-derivations (list drv))
735 (return (readlink (readlink (string-append profile "/dangling")))))))
736
737 (test-equalm "profile in profile"
738 '("foo" "0")
739
740 ;; Make sure we can build a profile that has another profile has one of its
741 ;; entries. The new profile's /manifest and /etc/profile must override the
742 ;; other's.
743 (mlet* %store-monad
744 ((prof0 (profile-derivation
745 (manifest
746 (list (package->manifest-entry %bootstrap-guile)))
747 #:hooks '()
748 #:locales? #f))
749 (prof1 (profile-derivation
750 (manifest (list (manifest-entry
751 (name "foo")
752 (version "0")
753 (item prof0))))
754 #:hooks '()
755 #:locales? #f)))
756 (mbegin %store-monad
757 (built-derivations (list prof1))
758 (let ((out (derivation->output-path prof1)))
759 (return (and (file-exists?
760 (string-append out "/bin/guile"))
761 (let ((manifest (profile-manifest out)))
762 (match (manifest-entries manifest)
763 ((entry)
764 (list (manifest-entry-name entry)
765 (manifest-entry-version entry)))))))))))
766
767 (test-end "profiles")
768
769 ;;; Local Variables:
770 ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
771 ;;; End: