gnu: linux-libre 5.10: Update to 5.10.34.
[jackhill/guix/guix.git] / tests / profiles.scm
CommitLineData
a2078770 1;;; GNU Guix --- Functional package management for GNU
b41e2148 2;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
343745c8 3;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
a2078770
LC
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)
c1bc358f 21 #:use-module (guix tests)
a2078770 22 #:use-module (guix profiles)
2225d56a 23 #:use-module (guix gexp)
462f5cca
LC
24 #:use-module (guix store)
25 #:use-module (guix monads)
ef8de985 26 #:use-module (guix grafts)
462f5cca
LC
27 #:use-module (guix packages)
28 #:use-module (guix derivations)
a0dac7a0 29 #:use-module (guix build-system trivial)
462f5cca 30 #:use-module (gnu packages bootstrap)
e39d1461 31 #:use-module ((gnu packages base) #:prefix packages:)
dedb17ad 32 #:use-module ((gnu packages guile) #:prefix packages:)
a2078770 33 #:use-module (ice-9 match)
ef8993e2 34 #:use-module (ice-9 regex)
d664f1b4
LC
35 #:use-module (ice-9 popen)
36 #:use-module (rnrs io ports)
ccda8f7d 37 #:use-module (srfi srfi-1)
79601521 38 #:use-module (srfi srfi-11)
a654dc4b 39 #:use-module (srfi srfi-34)
a2078770
LC
40 #:use-module (srfi srfi-64))
41
343745c8 42;; Test the (guix profiles) module.
a2078770 43
462f5cca 44(define %store
c1bc358f 45 (open-connection-for-tests))
a2078770 46
ef8de985
LC
47;; Globally disable grafts because they can trigger early builds.
48(%graft? #f)
49
a2078770
LC
50;; Example manifest entries.
51
f7554030
AK
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
a2078770
LC
59(define guile-2.0.9
60 (manifest-entry
61 (name "guile")
62 (version "2.0.9")
a54c94a4 63 (item "/gnu/store/...")
a2078770
LC
64 (output "out")))
65
66(define guile-2.0.9:debug
67 (manifest-entry (inherit guile-2.0.9)
68 (output "debug")))
69
79601521
LC
70(define glibc
71 (manifest-entry
72 (name "glibc")
73 (version "2.19")
74 (item "/gnu/store/...")
75 (output "out")))
76
a2078770
LC
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)))
487cbb01 96 (and (equal? e
a2078770
LC
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
487cbb01
LC
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
ce30a0eb
LC
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
a2078770
LC
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
f7554030
AK
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
435603a1
LC
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
b41e2148
LC
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
343745c8
AK
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
79601521
LC
204(test-assert "manifest-transaction-effects"
205 (let* ((m0 (manifest (list guile-1.8.8)))
206 (t (manifest-transaction
487cbb01 207 (install (list guile-2.0.9 glibc)))))
46b23e1a 208 (let-values (((remove install upgrade downgrade)
79601521 209 (manifest-transaction-effects m0 t)))
46b23e1a 210 (and (null? remove) (null? downgrade)
79601521 211 (equal? (list glibc) install)
ef8993e2
LC
212 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
213
f5d952c5
LP
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
46b23e1a
LC
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
f5d952c5
LP
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
3bea13bb
LC
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
c8c25704
LC
248(test-assert "manifest-transaction-null?"
249 (manifest-transaction-null? (manifest-transaction)))
250
6d382339
LC
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
f5d952c5
LP
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
ebf5ad46
LC
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))
a6562c7e
LC
273 #:hooks '()
274 #:locales? #f))
ebf5ad46
LC
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))))))
462f5cca 281
ef674a24
LC
282(test-assertm "<profile>"
283 (mlet* %store-monad
284 ((entry -> (package->manifest-entry %bootstrap-guile))
285 (profile -> (profile (hooks '()) (locales? #f)
286 (content (manifest (list entry)))))
287 (drv (lower-object profile))
288 (profile -> (derivation->output-path drv))
289 (bindir -> (string-append profile "/bin"))
290 (_ (built-derivations (list drv))))
291 (return (file-exists? (string-append bindir "/guile")))))
292
e00ade3f
LC
293(test-assertm "profile-derivation relative symlinks, one entry"
294 (mlet* %store-monad
295 ((entry -> (package->manifest-entry %bootstrap-guile))
296 (guile (package->derivation %bootstrap-guile))
297 (drv (profile-derivation (manifest (list entry))
298 #:relative-symlinks? #t
299 #:hooks '()
300 #:locales? #f))
301 (profile -> (derivation->output-path drv))
302 (bindir -> (string-append profile "/bin"))
303 (_ (built-derivations (list drv))))
304 (return (and (file-exists? (string-append bindir "/guile"))
305 (string=? (readlink bindir)
306 (string-append "../"
307 (basename
308 (derivation->output-path guile))
309 "/bin"))))))
310
311(unless (network-reachable?) (test-skip 1))
312(test-assertm "profile-derivation relative symlinks, two entries"
313 (mlet* %store-monad
03d76577
LC
314 ((manifest -> (packages->manifest
315 (list %bootstrap-guile gnu-make-for-tests)))
e00ade3f 316 (guile (package->derivation %bootstrap-guile))
03d76577 317 (make (package->derivation gnu-make-for-tests))
e00ade3f
LC
318 (drv (profile-derivation manifest
319 #:relative-symlinks? #t
320 #:hooks '()
321 #:locales? #f))
322 (profile -> (derivation->output-path drv))
323 (bindir -> (string-append profile "/bin"))
324 (_ (built-derivations (list drv))))
325 (return (and (file-exists? (string-append bindir "/guile"))
326 (file-exists? (string-append bindir "/make"))
327 (string=? (readlink (string-append bindir "/guile"))
328 (string-append "../../"
329 (basename
330 (derivation->output-path guile))
331 "/bin/guile"))
332 (string=? (readlink (string-append bindir "/make"))
333 (string-append "../../"
334 (basename
335 (derivation->output-path make))
336 "/bin/make"))))))
337
e39d1461
LC
338(test-assertm "profile-derivation, inputs"
339 (mlet* %store-monad
340 ((entry -> (package->manifest-entry packages:glibc "debug"))
341 (drv (profile-derivation (manifest (list entry))
a6562c7e
LC
342 #:hooks '()
343 #:locales? #f)))
e39d1461
LC
344 (return (derivation-inputs drv))))
345
176febe3
LC
346(test-assertm "profile-derivation, cross-compilation"
347 (mlet* %store-monad
348 ((manifest -> (packages->manifest (list packages:sed packages:grep)))
349 (target -> "arm-linux-gnueabihf")
350 (grep (package->cross-derivation packages:grep target))
351 (sed (package->cross-derivation packages:sed target))
352 (locales (package->derivation packages:glibc-utf8-locales))
353 (drv (profile-derivation manifest
354 #:hooks '()
355 #:locales? #t
356 #:target target)))
ede121de
CM
357 (define (find-input package)
358 (let ((name (string-append (package-full-name package "-") ".drv")))
176febe3
LC
359 (any (lambda (input)
360 (let ((input (derivation-input-path input)))
361 (and (string-suffix? name input) input)))
362 (derivation-inputs drv))))
363
364 ;; The inputs for grep and sed should be cross-build derivations, but that
365 ;; for the glibc-utf8-locales should be a native build.
366 (return (and (string=? (derivation-system drv) (%current-system))
ede121de 367 (string=? (find-input packages:grep)
176febe3 368 (derivation-file-name grep))
ede121de 369 (string=? (find-input packages:sed)
176febe3 370 (derivation-file-name sed))
ede121de 371 (string=? (find-input packages:glibc-utf8-locales)
176febe3
LC
372 (derivation-file-name locales))))))
373
9e90fc77
LC
374(test-assert "package->manifest-entry defaults to \"out\""
375 (let ((outputs (package-outputs packages:glibc)))
376 (equal? (manifest-entry-output
377 (package->manifest-entry (package
378 (inherit packages:glibc)
379 (outputs (reverse outputs)))))
380 (manifest-entry-output
381 (package->manifest-entry packages:glibc))
382 "out")))
383
dedb17ad
LC
384(test-assertm "profile-manifest, search-paths"
385 (mlet* %store-monad
386 ((guile -> (package
387 (inherit %bootstrap-guile)
388 (native-search-paths
389 (package-native-search-paths packages:guile-2.0))))
390 (entry -> (package->manifest-entry guile))
391 (drv (profile-derivation (manifest (list entry))
a6562c7e
LC
392 #:hooks '()
393 #:locales? #f))
dedb17ad
LC
394 (profile -> (derivation->output-path drv)))
395 (mbegin %store-monad
396 (built-derivations (list drv))
397
398 ;; Read the manifest back and make sure search paths are preserved.
399 (let ((manifest (profile-manifest profile)))
400 (match (manifest-entries manifest)
401 ((result)
402 (return (equal? (manifest-entry-search-paths result)
403 (manifest-entry-search-paths entry)
404 (package-native-search-paths
405 packages:guile-2.0)))))))))
d664f1b4 406
ccda8f7d
LC
407(test-assert "package->manifest-entry, search paths"
408 ;; See <http://bugs.gnu.org/22073>.
2d17a904 409 (let ((mpl (@ (gnu packages python-xyz) python2-matplotlib)))
ccda8f7d
LC
410 (lset= eq?
411 (package-transitive-native-search-paths mpl)
412 (manifest-entry-search-paths
413 (package->manifest-entry mpl)))))
414
07340cbe
LP
415(test-assert "packages->manifest, no duplicates"
416 (let ((expected
417 (manifest
418 (list
419 (package->manifest-entry packages:guile-2.2))))
420 (manifest (packages->manifest
421 (list packages:guile-2.2 packages:guile-2.2))))
422 (every manifest-entry=? (manifest-entries expected)
423 (manifest-entries manifest))))
424
55b4715f
LC
425(test-equal "packages->manifest, propagated inputs"
426 (map (match-lambda
427 ((label package)
428 (list (package-name package) (package-version package)
429 package)))
430 (package-propagated-inputs packages:guile-2.2))
431 (map (lambda (entry)
432 (list (manifest-entry-name entry)
433 (manifest-entry-version entry)
434 (manifest-entry-item entry)))
435 (manifest-entry-dependencies
436 (package->manifest-entry packages:guile-2.2))))
437
b3a00885
LC
438(test-assert "manifest-entry-parent"
439 (let ((entry (package->manifest-entry packages:guile-2.2)))
440 (match (manifest-entry-dependencies entry)
441 ((dependencies ..1)
442 (and (every (lambda (parent)
443 (eq? entry (force parent)))
444 (map manifest-entry-parent dependencies))
445 (not (force (manifest-entry-parent entry))))))))
446
55b4715f
LC
447(test-assertm "read-manifest"
448 (mlet* %store-monad ((manifest -> (packages->manifest
449 (list (package
450 (inherit %bootstrap-guile)
451 (native-search-paths
452 (package-native-search-paths
453 packages:guile-2.0))))))
454 (drv (profile-derivation manifest
455 #:hooks '()
456 #:locales? #f))
457 (out -> (derivation->output-path drv)))
458 (define (entry->sexp entry)
459 (list (manifest-entry-name entry)
460 (manifest-entry-version entry)
461 (manifest-entry-search-paths entry)
b3a00885
LC
462 (manifest-entry-dependencies entry)
463 (force (manifest-entry-parent entry))))
55b4715f
LC
464
465 (mbegin %store-monad
466 (built-derivations (list drv))
467 (let ((manifest2 (profile-manifest out)))
468 (return (equal? (map entry->sexp (manifest-entries manifest))
469 (map entry->sexp (manifest-entries manifest2))))))))
470
a654dc4b
LC
471(test-equal "collision"
472 '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
473 (guard (c ((profile-collision-error? c)
474 (let ((entry1 (profile-collision-error-entry c))
475 (entry2 (profile-collision-error-conflict c)))
476 (list (list (manifest-entry-name entry1)
477 (manifest-entry-version entry1))
478 (list (manifest-entry-name entry2)
479 (manifest-entry-version entry2))))))
480 (run-with-store %store
481 (mlet* %store-monad ((p0 -> (package
482 (inherit %bootstrap-guile)
483 (version "42")))
484 (p1 -> (dummy-package "p1"
485 (propagated-inputs `(("p0" ,p0)))))
486 (manifest -> (packages->manifest
487 (list %bootstrap-guile p1)))
488 (drv (profile-derivation manifest
489 #:hooks '()
490 #:locales? #f)))
491 (return #f)))))
492
493(test-equal "collision of propagated inputs"
494 '(("guile-bootstrap" "2.0") ("guile-bootstrap" "42"))
495 (guard (c ((profile-collision-error? c)
496 (let ((entry1 (profile-collision-error-entry c))
497 (entry2 (profile-collision-error-conflict c)))
498 (list (list (manifest-entry-name entry1)
499 (manifest-entry-version entry1))
500 (list (manifest-entry-name entry2)
501 (manifest-entry-version entry2))))))
502 (run-with-store %store
503 (mlet* %store-monad ((p0 -> (package
504 (inherit %bootstrap-guile)
505 (version "42")))
506 (p1 -> (dummy-package "p1"
507 (propagated-inputs
508 `(("guile" ,%bootstrap-guile)))))
509 (p2 -> (dummy-package "p2"
510 (propagated-inputs
511 `(("guile" ,p0)))))
512 (manifest -> (packages->manifest (list p1 p2)))
513 (drv (profile-derivation manifest
514 #:hooks '()
515 #:locales? #f)))
516 (return #f)))))
517
518(test-assertm "no collision"
519 ;; Here we have an entry that is "lowered" (its 'item' field is a store file
520 ;; name) and another entry (its 'item' field is a package) that is
521 ;; equivalent.
522 (mlet* %store-monad ((p -> (dummy-package "p"
523 (propagated-inputs
524 `(("guile" ,%bootstrap-guile)))))
525 (guile (package->derivation %bootstrap-guile))
526 (entry -> (manifest-entry
527 (inherit (package->manifest-entry
528 %bootstrap-guile))
529 (item (derivation->output-path guile))))
530 (manifest -> (manifest
531 (list entry
532 (package->manifest-entry p))))
533 (drv (profile-derivation manifest)))
534 (return (->bool drv))))
535
d664f1b4
LC
536(test-assertm "etc/profile"
537 ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
538 (mlet* %store-monad
539 ((guile -> (package
540 (inherit %bootstrap-guile)
541 (native-search-paths
542 (package-native-search-paths packages:guile-2.0))))
543 (entry -> (package->manifest-entry guile))
544 (drv (profile-derivation (manifest (list entry))
a6562c7e
LC
545 #:hooks '()
546 #:locales? #f))
d664f1b4
LC
547 (profile -> (derivation->output-path drv)))
548 (mbegin %store-monad
549 (built-derivations (list drv))
550 (let* ((pipe (open-input-pipe
9e006fb3
TUBK
551 (string-append "unset GUIX_PROFILE; "
552 ;; 'source' is a Bashism; use '.' (dot).
553 ". " profile "/etc/profile; "
554 ;; Don't try to parse set(1) output because
555 ;; it differs among shells; just use echo.
556 "echo $PATH")))
557 (path (get-string-all pipe)))
d664f1b4
LC
558 (return
559 (and (zero? (close-pipe pipe))
9e006fb3 560 (string-contains path (string-append profile "/bin"))))))))
d664f1b4 561
a0dac7a0
LC
562(test-assertm "etc/profile when etc/ already exists"
563 ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
564 ;; etc/ directory, which makes it read-only. Make sure the profile build
565 ;; handles that.
566 (mlet* %store-monad
567 ((thing -> (dummy-package "dummy"
568 (build-system trivial-build-system)
569 (arguments
570 `(#:guile ,%bootstrap-guile
571 #:builder
572 (let ((out (assoc-ref %outputs "out")))
573 (mkdir out)
574 (mkdir (string-append out "/etc"))
575 (call-with-output-file (string-append out "/etc/foo")
576 (lambda (port)
1e868858
MW
577 (display "foo!" port)))
578 #t)))))
a0dac7a0
LC
579 (entry -> (package->manifest-entry thing))
580 (drv (profile-derivation (manifest (list entry))
a6562c7e
LC
581 #:hooks '()
582 #:locales? #f))
a0dac7a0
LC
583 (profile -> (derivation->output-path drv)))
584 (mbegin %store-monad
585 (built-derivations (list drv))
586 (return (and (file-exists? (string-append profile "/etc/profile"))
587 (string=? (call-with-input-file
588 (string-append profile "/etc/foo")
589 get-string-all)
590 "foo!"))))))
591
113c17a0
LC
592(test-assertm "etc/profile when etc/ is a symlink"
593 ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
594 ;; gracelessly because 'scandir' would return #f.
595 (mlet* %store-monad
596 ((thing -> (dummy-package "dummy"
597 (build-system trivial-build-system)
598 (arguments
599 `(#:guile ,%bootstrap-guile
600 #:builder
601 (let ((out (assoc-ref %outputs "out")))
602 (mkdir out)
603 (mkdir (string-append out "/foo"))
604 (symlink "foo" (string-append out "/etc"))
605 (call-with-output-file (string-append out "/etc/bar")
606 (lambda (port)
1e868858
MW
607 (display "foo!" port)))
608 #t)))))
113c17a0
LC
609 (entry -> (package->manifest-entry thing))
610 (drv (profile-derivation (manifest (list entry))
a6562c7e
LC
611 #:hooks '()
612 #:locales? #f))
113c17a0
LC
613 (profile -> (derivation->output-path drv)))
614 (mbegin %store-monad
615 (built-derivations (list drv))
616 (return (and (file-exists? (string-append profile "/etc/profile"))
617 (string=? (call-with-input-file
618 (string-append profile "/etc/bar")
619 get-string-all)
620 "foo!"))))))
621
2225d56a
LC
622(test-assertm "profile-derivation when etc/ is a relative symlink"
623 ;; See <https://bugs.gnu.org/32686>.
624 (mlet* %store-monad
625 ((etc (gexp->derivation
626 "etc"
627 #~(begin
628 (mkdir #$output)
629 (call-with-output-file (string-append #$output "/foo")
630 (lambda (port)
631 (display "Heya!" port))))))
632 (thing -> (dummy-package "dummy"
633 (build-system trivial-build-system)
634 (inputs
635 `(("etc" ,etc)))
636 (arguments
637 `(#:guile ,%bootstrap-guile
638 #:builder
639 (let ((out (assoc-ref %outputs "out"))
640 (etc (assoc-ref %build-inputs "etc")))
641 (mkdir out)
642 (symlink etc (string-append out "/etc"))
643 #t)))))
644 (entry -> (package->manifest-entry thing))
645 (drv (profile-derivation (manifest (list entry))
646 #:relative-symlinks? #t
647 #:hooks '()
648 #:locales? #f))
649 (profile -> (derivation->output-path drv)))
650 (mbegin %store-monad
651 (built-derivations (list drv))
652 (return (string=? (call-with-input-file
653 (string-append profile "/etc/foo")
654 get-string-all)
655 "Heya!")))))
656
22ef06b8
LC
657(test-equalm "union vs. dangling symlink" ;<https://bugs.gnu.org/26949>
658 "does-not-exist"
659 (mlet* %store-monad
660 ((thing1 -> (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 (symlink "does-not-exist"
668 (string-append out "/dangling"))
669 #t)))))
670 (thing2 -> (package (inherit thing1) (name "dummy2")))
671 (drv (profile-derivation (packages->manifest
672 (list thing1 thing2))
673 #:hooks '()
674 #:locales? #f))
675 (profile -> (derivation->output-path drv)))
676 (mbegin %store-monad
677 (built-derivations (list drv))
678 (return (readlink (readlink (string-append profile "/dangling")))))))
679
38b77f34
LC
680(test-equalm "profile in profile"
681 '("foo" "0")
682
683 ;; Make sure we can build a profile that has another profile has one of its
684 ;; entries. The new profile's /manifest and /etc/profile must override the
685 ;; other's.
686 (mlet* %store-monad
687 ((prof0 (profile-derivation
688 (manifest
689 (list (package->manifest-entry %bootstrap-guile)))
690 #:hooks '()
691 #:locales? #f))
692 (prof1 (profile-derivation
693 (manifest (list (manifest-entry
694 (name "foo")
695 (version "0")
696 (item prof0))))
697 #:hooks '()
698 #:locales? #f)))
699 (mbegin %store-monad
700 (built-derivations (list prof1))
701 (let ((out (derivation->output-path prof1)))
702 (return (and (file-exists?
703 (string-append out "/bin/guile"))
704 (let ((manifest (profile-manifest out)))
705 (match (manifest-entries manifest)
706 ((entry)
707 (list (manifest-entry-name entry)
708 (manifest-entry-version entry)))))))))))
709
a2078770
LC
710(test-end "profiles")
711
a2078770
LC
712;;; Local Variables:
713;;; eval: (put 'dummy-package 'scheme-indent-function 1)
714;;; End: