gnu: Add bsnes.
[jackhill/guix/guix.git] / tests / guix-pack-relocatable.sh
CommitLineData
b07014f5 1# GNU Guix --- Functional package management for GNU
2520059b 2# Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
b07014f5
LC
3#
4# This file is part of GNU Guix.
5#
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.
10#
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.
15#
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/>.
18
19#
20# Test the 'guix pack --relocatable' using the external store, if any.
21#
22
23guix pack --version
24
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.
29
baab87ac 30storedir="`guile -c '(use-modules (guix config))(display %storedir)'`"
b07014f5 31localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
baab87ac 32NIX_STORE_DIR="$storedir"
b07014f5
LC
33GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
34export NIX_STORE_DIR GUIX_DAEMON_SOCKET
35
36if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
37then
38 exit 77
39fi
40
41STORE_PARENT="`dirname $NIX_STORE_DIR`"
42export STORE_PARENT
43if test "$STORE_PARENT" = "/"; then exit 77; fi
44
99aec37a 45if unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"'
b07014f5 46then
99aec37a
LC
47 # Test the wrapper that relies on user namespaces.
48 relocatable_option="-R"
49else
50 case "`uname -m`" in
51 x86_64|i?86)
52 # Test the wrapper that falls back to PRoot.
53 relocatable_option="-RR";;
54 *)
55 # XXX: Our 'proot' package currently fails tests on non-Intel
56 # architectures, so skip this by default.
57 exit 77;;
58 esac
b07014f5
LC
59fi
60
61test_directory="`mktemp -d`"
62export test_directory
63trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
64
99aec37a
LC
65export relocatable_option
66tarball="`guix pack $relocatable_option -S /Bin=bin sed`"
b07014f5
LC
67(cd "$test_directory"; tar xvf "$tarball")
68
8deb65c3
LC
69if unshare -r true # Are user namespaces supported?
70then
71 # Run that relocatable 'sed' in a user namespace where we "erase" the store by
72 # mounting an empty file system on top of it. That way, we exercise the
73 # wrapper code that creates the user namespace and bind-mounts the store.
74 unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"; echo "$STORE_PARENT"/*; "$test_directory/Bin/sed" --version > "$test_directory/output"'
2520059b
LC
75
76 # Check whether the exit code is preserved.
77 if unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"; echo "$STORE_PARENT"/*; "$test_directory/Bin/sed" --does-not-exist';
78 then false; else true; fi
8deb65c3
LC
79else
80 # Run the relocatable 'sed' in the current namespaces. This is a weak
81 # test because we're going to access store items from the host store.
82 "$test_directory/Bin/sed" --version > "$test_directory/output"
83fi
b07014f5 84grep 'GNU sed' "$test_directory/output"
b908fcd8
LC
85chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
86
fde2aec3
LC
87case "`uname -m`" in
88 x86_64|i?86)
89 # Try '-RR' and PRoot.
90 tarball="`guix pack -RR -S /Bin=bin sed`"
91 tar tvf "$tarball" | grep /bin/proot
92 (cd "$test_directory"; tar xvf "$tarball")
93 GUIX_EXECUTION_ENGINE="proot"
94 export GUIX_EXECUTION_ENGINE
95 "$test_directory/Bin/sed" --version > "$test_directory/output"
96 grep 'GNU sed' "$test_directory/output"
64562321
LC
97
98 # Now with fakechroot.
99 GUIX_EXECUTION_ENGINE="fakechroot"
100 "$test_directory/Bin/sed" --version > "$test_directory/output"
101 grep 'GNU sed' "$test_directory/output"
102
fde2aec3
LC
103 chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
104 ;;
105 *)
106 echo "skipping PRoot test" >&2
107 ;;
108esac
109
b908fcd8
LC
110# Ensure '-R' works with outputs other than "out".
111tarball="`guix pack -R -S /share=share groff:doc`"
112(cd "$test_directory"; tar xvf "$tarball")
113test -d "$test_directory/share/doc/groff/html"