1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 (guix modules)
31 #:use-module (gnu packages)
32 #:use-module ((gnu packages base) #:select (glibc-utf8-locales))
33 #:use-module (gnu packages bootstrap)
34 #:use-module ((gnu packages compression) #:select (squashfs-tools))
35 #:use-module ((gnu packages guile) #:select (guile-sqlite3))
36 #:use-module ((gnu packages gnupg) #:select (guile-gcrypt))
37 #:use-module (srfi srfi-64))
40 (open-connection-for-tests))
42 ;; Globally disable grafts because they can trigger early builds.
45 (define-syntax-rule (test-assertm name store exp)
47 (let ((guile (package-derivation store %bootstrap-guile)))
48 (run-with-store store exp
49 #:guile-for-build guile))))
51 (define %gzip-compressor
52 ;; Compressor that uses the bootstrap 'gzip'.
53 ((@ (guix scripts pack) compressor) "gzip"
55 #~(#+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n")))
57 (define %tar-bootstrap %bootstrap-coreutils&co)
62 (unless (network-reachable?) (test-skip 1))
63 (test-assertm "self-contained-tarball" %store
66 (content (packages->manifest (list %bootstrap-guile)))
69 (tarball (self-contained-tarball "pack" profile
70 #:symlinks '(("/bin/Guile"
72 #:compressor %gzip-compressor
73 #:archiver %tar-bootstrap))
74 (check (gexp->derivation
76 (with-imported-modules '((guix build utils))
78 (use-modules (guix build utils)
82 ;; The unpacked store.
83 (string-append "." (%store-directory) "/"))
85 (define (canonical? file)
86 ;; Return #t if FILE is read-only and its mtime is 1.
87 (let ((st (lstat file)))
88 (or (not (string-prefix? store file))
89 (eq? 'symlink (stat:type st))
90 (and (= 1 (stat:mtime st))
95 (string-append "." #$profile "/bin"))
98 (string-append #$%tar-bootstrap "/bin"))
99 (system* "tar" "xvf" #$tarball)
102 (and (file-exists? (string-append bin "/guile"))
105 (find-files "." (const #t)
107 (string=? (string-append #$%bootstrap-guile "/bin")
109 (string=? (string-append ".." #$profile
111 (readlink "bin/Guile")))))))))
112 (built-derivations (list check))))
114 ;; The following test needs guile-sqlite3, libgcrypt, etc. as a consequence of
115 ;; commit c45477d2a1a651485feede20fe0f3d15aec48b39 and related changes. Thus,
116 ;; run it on the user's store, if it's available, on the grounds that these
117 ;; dependencies may be already there, or we can get substitutes or build them
118 ;; quite inexpensively; see <https://bugs.gnu.org/32184>.
120 (with-external-store store
121 (unless store (test-skip 1))
122 (test-assertm "self-contained-tarball + localstatedir" store
124 ((guile (set-guile-for-build (default-guile)))
125 (profile (profile-derivation (packages->manifest
126 (list %bootstrap-guile))
129 (tarball (self-contained-tarball "tar-pack" profile
130 #:localstatedir? #t))
131 (check (gexp->derivation
133 #~(let ((bin (string-append "." #$profile "/bin")))
135 (string-append #$%tar-bootstrap "/bin"))
136 (system* "tar" "xvf" #$tarball)
139 (and (file-exists? "var/guix/db/db.sqlite")
140 (string=? (string-append #$%bootstrap-guile "/bin")
141 (readlink bin))))))))
142 (built-derivations (list check))))
144 (unless store (test-skip 1))
145 (test-assertm "self-contained-tarball + localstatedir, UTF-8 file names" store
147 ((guile (set-guile-for-build (default-guile)))
148 (tree (interned-file-tree
149 `("directory-with-utf8-file-names" directory
150 ("α" regular (data "alpha"))
151 ("λ" regular (data "lambda")))))
152 (tarball (self-contained-tarball "tar-pack" tree
153 #:localstatedir? #t))
154 (check (gexp->derivation
156 (with-extensions (list guile-sqlite3 guile-gcrypt)
157 (with-imported-modules (source-module-closure
158 '((guix store database)))
160 (use-modules (guix store database)
164 (define (valid-file? basename data)
166 (string-append "./" #$tree "/" basename))
168 (string=? (call-with-input-file (pk 'file file)
173 (string-append #$%tar-bootstrap "/bin"))
174 (system* "tar" "xvf" #$tarball)
177 #$(local-file (search-path %load-path
178 "guix/store/schema.sql")))
179 (with-database "var/guix/db/db.sqlite" db
180 ;; Make sure non-ASCII file names are properly
182 (setenv "GUIX_LOCPATH"
183 #+(file-append glibc-utf8-locales
185 (setlocale LC_ALL "en_US.utf8")
189 (and (every valid-file?
192 (integer? (path-id db #$tree)))))))))))
193 (built-derivations (list check))))
195 (unless store (test-skip 1))
196 (test-assertm "docker-image + localstatedir" store
198 ((guile (set-guile-for-build (default-guile)))
199 (profile (profile-derivation (packages->manifest
200 (list %bootstrap-guile))
203 (tarball (docker-image "docker-pack" profile
204 #:symlinks '(("/bin/Guile" -> "bin/guile"))
205 #:localstatedir? #t))
206 (check (gexp->derivation
208 (with-imported-modules '((guix build utils))
210 (use-modules (guix build utils)
214 (string-append "." #$profile "/bin"))
216 (setenv "PATH" (string-append #$%tar-bootstrap "/bin"))
218 (with-directory-excursion "base"
219 (invoke "tar" "xvf" #$tarball))
221 (match (find-files "base" "layer.tar")
223 (invoke "tar" "xvf" layer)))
226 (and (file-exists? (string-append bin "/guile"))
227 (file-exists? "var/guix/db/db.sqlite")
228 (file-is-directory? "tmp")
229 (string=? (string-append #$%bootstrap-guile "/bin")
230 (pk 'binlink (readlink bin)))
231 (string=? (string-append #$profile "/bin/guile")
232 (pk 'guilelink (readlink "bin/Guile"))))
233 (mkdir #$output)))))))
234 (built-derivations (list check))))
236 (unless store (test-skip 1))
237 (test-assertm "squashfs-image + localstatedir" store
239 ((guile (set-guile-for-build (default-guile)))
240 (profile (profile-derivation (packages->manifest
241 (list %bootstrap-guile))
244 (image (squashfs-image "squashfs-pack" profile
245 #:symlinks '(("/bin" -> "bin"))
246 #:localstatedir? #t))
247 (check (gexp->derivation
249 (with-imported-modules '((guix build utils))
251 (use-modules (guix build utils)
255 (string-append "." #$profile "/bin"))
258 (string-append #$squashfs-tools "/bin"))
259 (invoke "unsquashfs" #$image)
260 (with-directory-excursion "squashfs-root"
261 (when (and (file-exists? (string-append bin
263 (file-exists? "var/guix/db/db.sqlite")
264 (string=? (string-append #$%bootstrap-guile "/bin")
265 (pk 'binlink (readlink bin)))
267 ;; This is a relative symlink target.
268 (string=? (string-drop
269 (string-append #$profile "/bin")
271 (pk 'guilelink (readlink "bin"))))
272 (mkdir #$output))))))))
273 (built-derivations (list check)))))
278 ;; eval: (put 'test-assertm 'scheme-indent-function 2)