gnu: r-diversitree: Update to 0.9-14.
[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
c6c0d5a2
LC
41# Attempt to run the given command in a namespace where the store is
42# invisible. This makes sure the presence of the store does not hide
43# problems.
44run_without_store ()
45{
46 if unshare -r true # Are user namespaces supported?
47 then
48 # Run that relocatable executable in a user namespace where we "erase"
49 # the store by mounting an empty file system on top of it. That way,
50 # we exercise the wrapper code that creates the user namespace and
51 # bind-mounts the store.
52 unshare -mrf sh -c 'mount -t tmpfs -o ro none "$NIX_STORE_DIR"; '"$*"
53 else
54 # Run the relocatable program in the current namespaces. This is a
55 # weak test because we're going to access store items from the host
56 # store.
57 $*
58 fi
59}
b07014f5
LC
60
61test_directory="`mktemp -d`"
62export test_directory
63trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
64
c6c0d5a2 65if unshare -r true
8deb65c3 66then
c6c0d5a2
LC
67 # Test the 'userns' execution engine.
68 tarball="`guix pack -R -S /Bin=bin sed`"
69 (cd "$test_directory"; tar xvf "$tarball")
70
71 run_without_store "$test_directory/Bin/sed" --version > "$test_directory/output"
72 grep 'GNU sed' "$test_directory/output"
73
74 # Same with an explicit engine.
75 run_without_store GUIX_EXECUTION_ENGINE="userns" \
76 "$test_directory/Bin/sed" --version > "$test_directory/output"
77 grep 'GNU sed' "$test_directory/output"
2520059b
LC
78
79 # Check whether the exit code is preserved.
c6c0d5a2 80 if run_without_store "$test_directory/Bin/sed" --does-not-exist;
2520059b 81 then false; else true; fi
c6c0d5a2
LC
82
83 chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
8deb65c3 84else
c6c0d5a2 85 echo "'userns' execution tests skipped" >&2
8deb65c3 86fi
b908fcd8 87
fde2aec3
LC
88case "`uname -m`" in
89 x86_64|i?86)
90 # Try '-RR' and PRoot.
91 tarball="`guix pack -RR -S /Bin=bin sed`"
92 tar tvf "$tarball" | grep /bin/proot
c088aa29 93 (cd "$test_directory"; tar xf "$tarball")
c6c0d5a2 94 run_without_store GUIX_EXECUTION_ENGINE="proot" \
fde2aec3
LC
95 "$test_directory/Bin/sed" --version > "$test_directory/output"
96 grep 'GNU sed' "$test_directory/output"
64562321
LC
97
98 # Now with fakechroot.
c6c0d5a2 99 run_without_store GUIX_EXECUTION_ENGINE="fakechroot" \
64562321
LC
100 "$test_directory/Bin/sed" --version > "$test_directory/output"
101 grep 'GNU sed' "$test_directory/output"
102
fde2aec3 103 chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
c088aa29
LC
104
105 if unshare -r true
106 then
107 # Check whether the store contains everything it should. Check
108 # once when erasing $STORE_PARENT ("/gnu") and once when erasing
109 # $NIX_STORE_DIR ("/gnu/store").
110 tarball="`guix pack -RR -S /bin=bin bash-minimal`"
111 (cd "$test_directory"; tar xf "$tarball")
112
113 STORE_PARENT="`dirname $NIX_STORE_DIR`"
114 export STORE_PARENT
115
116 for engine in userns proot fakechroot
117 do
118 for i in $(guix gc -R $(guix build bash-minimal | grep -v -e '-doc$'))
119 do
120 unshare -mrf sh -c "mount -t tmpfs none \"$NIX_STORE_DIR\"; GUIX_EXECUTION_ENGINE=$engine $test_directory/bin/sh -c 'echo $NIX_STORE_DIR/*'" | grep $(basename $i)
121 unshare -mrf sh -c "mount -t tmpfs none \"$STORE_PARENT\"; GUIX_EXECUTION_ENGINE=$engine $test_directory/bin/sh -c 'echo $NIX_STORE_DIR/*'" | grep $(basename $i)
122 done
123 done
124
125 chmod -Rf +w "$test_directory"; rm -rf "$test_directory"/*
126 fi
fde2aec3
LC
127 ;;
128 *)
c6c0d5a2 129 echo "skipping PRoot and Fakechroot tests" >&2
fde2aec3
LC
130 ;;
131esac
132
b908fcd8
LC
133# Ensure '-R' works with outputs other than "out".
134tarball="`guix pack -R -S /share=share groff:doc`"
c088aa29 135(cd "$test_directory"; tar xf "$tarball")
b908fcd8 136test -d "$test_directory/share/doc/groff/html"
a5538922
LC
137
138# Ensure '-R' applies to propagated inputs. Failing to do that, it would fail
139# with a profile collision error in this case because 'python-scipy'
140# propagates 'python-numpy'. See <https://bugs.gnu.org/42510>.
141guix pack -RR python-numpy python-scipy --no-grafts -n