1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019 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 (gnu packages bootstrap)
31 #:use-module ((gnu packages compression) #:select (squashfs-tools-next))
32 #:use-module (srfi srfi-64))
35 (open-connection-for-tests))
37 ;; Globally disable grafts because they can trigger early builds.
40 (define-syntax-rule (test-assertm name store exp)
42 (let ((guile (package-derivation store %bootstrap-guile)))
43 (run-with-store store exp
44 #:guile-for-build guile))))
46 (define %gzip-compressor
47 ;; Compressor that uses the bootstrap 'gzip'.
48 ((@ (guix scripts pack) compressor) "gzip"
50 #~(#+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n")))
52 (define %tar-bootstrap %bootstrap-coreutils&co)
57 (unless (network-reachable?) (test-skip 1))
58 (test-assertm "self-contained-tarball" %store
60 ((profile (profile-derivation (packages->manifest
61 (list %bootstrap-guile))
64 (tarball (self-contained-tarball "pack" profile
65 #:symlinks '(("/bin/Guile"
67 #:compressor %gzip-compressor
68 #:archiver %tar-bootstrap))
69 (check (gexp->derivation
71 (with-imported-modules '((guix build utils))
73 (use-modules (guix build utils)
77 ;; The unpacked store.
78 (string-append "." (%store-directory) "/"))
80 (define (canonical? file)
81 ;; Return #t if FILE is read-only and its mtime is 1.
82 (let ((st (lstat file)))
83 (or (not (string-prefix? store file))
84 (eq? 'symlink (stat:type st))
85 (and (= 1 (stat:mtime st))
90 (string-append "." #$profile "/bin"))
93 (string-append #$%tar-bootstrap "/bin"))
94 (system* "tar" "xvf" #$tarball)
97 (and (file-exists? (string-append bin "/guile"))
100 (find-files "." (const #t)
102 (string=? (string-append #$%bootstrap-guile "/bin")
104 (string=? (string-append ".." #$profile
106 (readlink "bin/Guile")))))))))
107 (built-derivations (list check))))
109 ;; The following test needs guile-sqlite3, libgcrypt, etc. as a consequence of
110 ;; commit c45477d2a1a651485feede20fe0f3d15aec48b39 and related changes. Thus,
111 ;; run it on the user's store, if it's available, on the grounds that these
112 ;; dependencies may be already there, or we can get substitutes or build them
113 ;; quite inexpensively; see <https://bugs.gnu.org/32184>.
115 (with-external-store store
116 (unless store (test-skip 1))
117 (test-assertm "self-contained-tarball + localstatedir" store
119 ((guile (set-guile-for-build (default-guile)))
120 (profile (profile-derivation (packages->manifest
121 (list %bootstrap-guile))
124 (tarball (self-contained-tarball "tar-pack" profile
125 #:localstatedir? #t))
126 (check (gexp->derivation
128 #~(let ((bin (string-append "." #$profile "/bin")))
130 (string-append #$%tar-bootstrap "/bin"))
131 (system* "tar" "xvf" #$tarball)
134 (and (file-exists? "var/guix/db/db.sqlite")
135 (string=? (string-append #$%bootstrap-guile "/bin")
136 (readlink bin))))))))
137 (built-derivations (list check))))
139 (unless store (test-skip 1))
140 (test-assertm "docker-image + localstatedir" store
142 ((guile (set-guile-for-build (default-guile)))
143 (profile (profile-derivation (packages->manifest
144 (list %bootstrap-guile))
147 (tarball (docker-image "docker-pack" profile
148 #:symlinks '(("/bin/Guile" -> "bin/guile"))
149 #:localstatedir? #t))
150 (check (gexp->derivation
152 (with-imported-modules '((guix build utils))
154 (use-modules (guix build utils)
158 (string-append "." #$profile "/bin"))
160 (setenv "PATH" (string-append #$%tar-bootstrap "/bin"))
162 (with-directory-excursion "base"
163 (invoke "tar" "xvf" #$tarball))
165 (match (find-files "base" "layer.tar")
167 (invoke "tar" "xvf" layer)))
170 (and (file-exists? (string-append bin "/guile"))
171 (file-exists? "var/guix/db/db.sqlite")
172 (string=? (string-append #$%bootstrap-guile "/bin")
173 (pk 'binlink (readlink bin)))
174 (string=? (string-append #$profile "/bin/guile")
175 (pk 'guilelink (readlink "bin/Guile"))))
176 (mkdir #$output)))))))
177 (built-derivations (list check))))
179 (unless store (test-skip 1))
180 (test-assertm "squashfs-image + localstatedir" store
182 ((guile (set-guile-for-build (default-guile)))
183 (profile (profile-derivation (packages->manifest
184 (list %bootstrap-guile))
187 (image (squashfs-image "squashfs-pack" profile
188 #:symlinks '(("/bin" -> "bin"))
189 #:localstatedir? #t))
190 (check (gexp->derivation
192 (with-imported-modules '((guix build utils))
194 (use-modules (guix build utils)
198 (string-append "." #$profile "/bin"))
201 (string-append #$squashfs-tools-next "/bin"))
202 (invoke "unsquashfs" #$image)
203 (with-directory-excursion "squashfs-root"
204 (when (and (file-exists? (string-append bin
206 (file-exists? "var/guix/db/db.sqlite")
207 (string=? (string-append #$%bootstrap-guile "/bin")
208 (pk 'binlink (readlink bin)))
210 ;; This is a relative symlink target.
211 (string=? (string-drop
212 (string-append #$profile "/bin")
214 (pk 'guilelink (readlink "bin"))))
215 (mkdir #$output))))))))
216 (built-derivations (list check)))))
221 ;; eval: (put 'test-assertm 'scheme-indent-function 2)