installer: Mount ESP once only.
[guix.git] / tests / guix-pack-relocatable.sh
blobc45a679bb14e008b78d3044ccea1ff99010afa42
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 # This file is part of GNU Guix.
6 # GNU Guix is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or (at
9 # your option) any later version.
11 # GNU Guix is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 # Test the 'guix pack --relocatable' using the external store, if any.
23 guix pack --version
25 # 'guix pack --relocatable' requires a C compiler and libc.a, which our
26 # bootstrap binaries don't provide. To make the test relatively inexpensive,
27 # run it on the user's global store if possible, on the grounds that binaries
28 # may already be there or can be built or downloaded inexpensively.
30 NIX_STORE_DIR="`guile -c '(use-modules (guix config))(display %storedir)'`"
31 localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
32 GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
33 export NIX_STORE_DIR GUIX_DAEMON_SOCKET
35 if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
36 then
37 exit 77
40 STORE_PARENT="`dirname $NIX_STORE_DIR`"
41 export STORE_PARENT
42 if test "$STORE_PARENT" = "/"; then exit 77; fi
44 if unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"'
45 then
46 # Test the wrapper that relies on user namespaces.
47 relocatable_option="-R"
48 else
49 case "`uname -m`" in
50 x86_64|i?86)
51 # Test the wrapper that falls back to PRoot.
52 relocatable_option="-RR";;
54 # XXX: Our 'proot' package currently fails tests on non-Intel
55 # architectures, so skip this by default.
56 exit 77;;
57 esac
60 test_directory="`mktemp -d`"
61 export test_directory
62 trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
64 export relocatable_option
65 tarball="`guix pack $relocatable_option -S /Bin=bin sed`"
66 (cd "$test_directory"; tar xvf "$tarball")
68 if unshare -r true # Are user namespaces supported?
69 then
70 # Run that relocatable 'sed' in a user namespace where we "erase" the store by
71 # mounting an empty file system on top of it. That way, we exercise the
72 # wrapper code that creates the user namespace and bind-mounts the store.
73 unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"; echo "$STORE_PARENT"/*; "$test_directory/Bin/sed" --version > "$test_directory/output"'
74 else
75 # Run the relocatable 'sed' in the current namespaces. This is a weak
76 # test because we're going to access store items from the host store.
77 "$test_directory/Bin/sed" --version > "$test_directory/output"
79 grep 'GNU sed' "$test_directory/output"