pack: Add test for 'self-contained-tarball' with localstatedir.
[jackhill/guix/guix.git] / tests / pack.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
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-pack)
21 #:use-module (guix scripts pack)
22 #:use-module (guix store)
23 #:use-module (guix derivations)
24 #:use-module (guix profiles)
25 #:use-module (guix packages)
26 #:use-module (guix monads)
27 #:use-module (guix grafts)
28 #:use-module (guix tests)
29 #:use-module (guix gexp)
30 #:use-module (gnu packages bootstrap)
31 #:use-module ((gnu packages compression) #:select (squashfs-tools-next))
32 #:use-module (srfi srfi-64))
33
34 (define %store
35 (open-connection-for-tests))
36
37 ;; Globally disable grafts because they can trigger early builds.
38 (%graft? #f)
39
40 (define-syntax-rule (test-assertm name store exp)
41 (test-assert name
42 (let ((guile (package-derivation store %bootstrap-guile)))
43 (run-with-store store exp
44 #:guile-for-build guile))))
45
46 (define %gzip-compressor
47 ;; Compressor that uses the bootstrap 'gzip'.
48 ((@ (guix scripts pack) compressor) "gzip"
49 "gz"
50 #~(#+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n")))
51
52 (define %tar-bootstrap %bootstrap-coreutils&co)
53
54 \f
55 (test-begin "pack")
56
57 (unless (network-reachable?) (test-skip 1))
58 (test-assertm "self-contained-tarball" %store
59 (mlet* %store-monad
60 ((profile (profile-derivation (packages->manifest
61 (list %bootstrap-guile))
62 #:hooks '()
63 #:locales? #f))
64 (tarball (self-contained-tarball "pack" profile
65 #:symlinks '(("/bin/Guile"
66 -> "bin/guile"))
67 #:compressor %gzip-compressor
68 #:archiver %tar-bootstrap))
69 (check (gexp->derivation
70 "check-tarball"
71 #~(let ((bin (string-append "." #$profile "/bin")))
72 (setenv "PATH"
73 (string-append #$%tar-bootstrap "/bin"))
74 (system* "tar" "xvf" #$tarball)
75 (mkdir #$output)
76 (exit
77 (and (file-exists? (string-append bin "/guile"))
78 (string=? (string-append #$%bootstrap-guile "/bin")
79 (readlink bin))
80 (string=? (string-append ".." #$profile
81 "/bin/guile")
82 (readlink "bin/Guile"))))))))
83 (built-derivations (list check))))
84
85 ;; The following test needs guile-sqlite3, libgcrypt, etc. as a consequence of
86 ;; commit c45477d2a1a651485feede20fe0f3d15aec48b39 and related changes. Thus,
87 ;; run it on the user's store, if it's available, on the grounds that these
88 ;; dependencies may be already there, or we can get substitutes or build them
89 ;; quite inexpensively; see <https://bugs.gnu.org/32184>.
90
91 (with-external-store store
92 (unless store (test-skip 1))
93 (test-assertm "self-contained-tarball + localstatedir" store
94 (mlet* %store-monad
95 ((guile (set-guile-for-build (default-guile)))
96 (profile (profile-derivation (packages->manifest
97 (list %bootstrap-guile))
98 #:hooks '()
99 #:locales? #f))
100 (tarball (self-contained-tarball "tar-pack" profile
101 #:localstatedir? #t))
102 (check (gexp->derivation
103 "check-tarball"
104 #~(let ((bin (string-append "." #$profile "/bin")))
105 (setenv "PATH"
106 (string-append #$%tar-bootstrap "/bin"))
107 (system* "tar" "xvf" #$tarball)
108 (mkdir #$output)
109 (exit
110 (and (file-exists? "var/guix/db/db.sqlite")
111 (string=? (string-append #$%bootstrap-guile "/bin")
112 (readlink bin))))))))
113 (built-derivations (list check))))
114
115 (unless store (test-skip 1))
116 (test-assertm "docker-image + localstatedir" store
117 (mlet* %store-monad
118 ((guile (set-guile-for-build (default-guile)))
119 (profile (profile-derivation (packages->manifest
120 (list %bootstrap-guile))
121 #:hooks '()
122 #:locales? #f))
123 (tarball (docker-image "docker-pack" profile
124 #:symlinks '(("/bin/Guile" -> "bin/guile"))
125 #:localstatedir? #t))
126 (check (gexp->derivation
127 "check-tarball"
128 (with-imported-modules '((guix build utils))
129 #~(begin
130 (use-modules (guix build utils)
131 (ice-9 match))
132
133 (define bin
134 (string-append "." #$profile "/bin"))
135
136 (setenv "PATH" (string-append #$%tar-bootstrap "/bin"))
137 (mkdir "base")
138 (with-directory-excursion "base"
139 (invoke "tar" "xvf" #$tarball))
140
141 (match (find-files "base" "layer.tar")
142 ((layer)
143 (invoke "tar" "xvf" layer)))
144
145 (when
146 (and (file-exists? (string-append bin "/guile"))
147 (file-exists? "var/guix/db/db.sqlite")
148 (string=? (string-append #$%bootstrap-guile "/bin")
149 (pk 'binlink (readlink bin)))
150 (string=? (string-append #$profile "/bin/guile")
151 (pk 'guilelink (readlink "bin/Guile"))))
152 (mkdir #$output)))))))
153 (built-derivations (list check))))
154
155 (unless store (test-skip 1))
156 (test-assertm "squashfs-image + localstatedir" store
157 (mlet* %store-monad
158 ((guile (set-guile-for-build (default-guile)))
159 (profile (profile-derivation (packages->manifest
160 (list %bootstrap-guile))
161 #:hooks '()
162 #:locales? #f))
163 (image (squashfs-image "squashfs-pack" profile
164 #:symlinks '(("/bin" -> "bin"))
165 #:localstatedir? #t))
166 (check (gexp->derivation
167 "check-tarball"
168 (with-imported-modules '((guix build utils))
169 #~(begin
170 (use-modules (guix build utils)
171 (ice-9 match))
172
173 (define bin
174 (string-append "." #$profile "/bin"))
175
176 (setenv "PATH"
177 (string-append #$squashfs-tools-next "/bin"))
178 (invoke "unsquashfs" #$image)
179 (with-directory-excursion "squashfs-root"
180 (when (and (file-exists? (string-append bin
181 "/guile"))
182 (file-exists? "var/guix/db/db.sqlite")
183 (string=? (string-append #$%bootstrap-guile "/bin")
184 (pk 'binlink (readlink bin)))
185 (string=? (string-append #$profile "/bin")
186 (pk 'guilelink (readlink "bin"))))
187 (mkdir #$output))))))))
188 (built-derivations (list check)))))
189
190 (test-end)
191
192 ;; Local Variables:
193 ;; eval: (put 'test-assertm 'scheme-indent-function 2)
194 ;; End: