pack: Import (guix store database) only when '--localstatedir' is passed.
[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 monads)
26 #:use-module (guix grafts)
27 #:use-module (guix tests)
28 #:use-module (guix gexp)
29 #:use-module (gnu packages bootstrap)
30 #:use-module (srfi srfi-64))
31
32 (define %store
33 (open-connection-for-tests))
34
35 ;; Globally disable grafts because they can trigger early builds.
36 (%graft? #f)
37
38 (define-syntax-rule (test-assertm name store exp)
39 (test-assert name
40 (run-with-store store exp
41 #:guile-for-build (%guile-for-build))))
42
43 (define %gzip-compressor
44 ;; Compressor that uses the bootstrap 'gzip'.
45 ((@ (guix scripts pack) compressor) "gzip"
46 "gz"
47 #~(#+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n")))
48
49 (define %tar-bootstrap %bootstrap-coreutils&co)
50
51 \f
52 (test-begin "pack")
53
54 (unless (network-reachable?) (test-skip 1))
55 (test-assertm "self-contained-tarball" %store
56 (mlet* %store-monad
57 ((profile (profile-derivation (packages->manifest
58 (list %bootstrap-guile))
59 #:hooks '()
60 #:locales? #f))
61 (tarball (self-contained-tarball "pack" profile
62 #:symlinks '(("/bin/Guile"
63 -> "bin/guile"))
64 #:compressor %gzip-compressor
65 #:archiver %tar-bootstrap))
66 (check (gexp->derivation
67 "check-tarball"
68 #~(let ((bin (string-append "." #$profile "/bin")))
69 (setenv "PATH"
70 (string-append #$%tar-bootstrap "/bin"))
71 (system* "tar" "xvf" #$tarball)
72 (mkdir #$output)
73 (exit
74 (and (file-exists? (string-append bin "/guile"))
75 (string=? (string-append #$%bootstrap-guile "/bin")
76 (readlink bin))
77 (string=? (string-append ".." #$profile
78 "/bin/guile")
79 (readlink "bin/Guile"))))))))
80 (built-derivations (list check))))
81
82 (test-end)
83
84 ;; Local Variables:
85 ;; eval: (put 'test-assertm 'scheme-indent-function 2)
86 ;; End: