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