1--- a/tests/libtest.sh
2+++ b/tests/libtest.sh
3@@ -328,7 +328,7 @@
4 # running installed-tests: assume we know what we're doing
5 _flatpak_bwrap_works=true
6 elif ! "$FLATPAK_BWRAP" --unshare-ipc --unshare-net --unshare-pid \
7- --ro-bind / / /bin/true > bwrap-result 2>&1; then
8+ --ro-bind / / @coreutils@/bin/true > bwrap-result 2>&1; then
9 _flatpak_bwrap_works=false
10 else
11 _flatpak_bwrap_works=true
12@@ -309,12 +309,12 @@
13 export DBUS_SESSION_BUS_ADDRESS="$(cat dbus-session-bus-address)"
14 DBUS_SESSION_BUS_PID="$(cat dbus-session-bus-pid)"
15
16-if ! /bin/kill -0 "$DBUS_SESSION_BUS_PID"; then
17+if ! @coreutils@/bin/kill -0 "$DBUS_SESSION_BUS_PID"; then
18 assert_not_reached "Failed to start dbus-daemon"
19 fi
20
21 cleanup () {
22- /bin/kill -9 $DBUS_SESSION_BUS_PID ${FLATPAK_HTTP_PID:-}
23+ @coreutils@/bin/kill -9 $DBUS_SESSION_BUS_PID ${FLATPAK_HTTP_PID:-}
24 gpg-connect-agent --homedir "${FL_GPG_HOMEDIR}" killagent /bye || true
25 fusermount -u $XDG_RUNTIME_DIR/doc || :
26 if test -n "${TEST_SKIP_CLEANUP:-}"; then
27--- a/tests/make-test-app.sh
28+++ b/tests/make-test-app.sh
29@@ -114,13 +114,13 @@ msgid "Hello world"
30 msgstr "Hallo Welt"
31 EOF
32 mkdir -p ${DIR}/files/de/share/de/LC_MESSAGES
33-msgfmt --output-file ${DIR}/files/de/share/de/LC_MESSAGES/helloworld.mo de.po
34+@gettext@/bin/msgfmt --output-file ${DIR}/files/de/share/de/LC_MESSAGES/helloworld.mo de.po
35 cat > fr.po <<EOF
36 msgid "Hello world"
37 msgstr "Bonjour le monde"
38 EOF
39 mkdir -p ${DIR}/files/fr/share/fr/LC_MESSAGES
40-msgfmt --output-file ${DIR}/files/fr/share/fr/LC_MESSAGES/helloworld.mo fr.po
41+@gettext@/bin/msgfmt --output-file ${DIR}/files/fr/share/fr/LC_MESSAGES/helloworld.mo fr.po
42
43 flatpak build-finish ${DIR}
44 mkdir -p repos
45--- a/tests/make-test-runtime.sh
46+++ b/tests/make-test-runtime.sh
47@@ -26,6 +26,7 @@
48 PATH="$PATH:/usr/sbin:/sbin"
49
50 # Add bash and dependencies
51+mkdir -p ${DIR}/nix/store
52 mkdir -p ${DIR}/usr/bin
53 mkdir -p ${DIR}/usr/lib
54 ln -s ../lib ${DIR}/usr/lib64
55@@ -35,48 +36,27 @@
56 else
57 cp `which ldconfig` ${DIR}/usr/bin
58 fi
59-LIBS=`mktemp`
60-BINS=`mktemp`
61-
62-add_bin() {
63- local f=$1
64- shift
65-
66- if grep -qFe "${f}" $BINS; then
67- # Already handled
68- return 0
69- fi
70-
71- echo $f >> $BINS
72-
73- # Add library dependencies
74- (ldd "${f}" | sed "s/.* => //" | awk '{ print $1}' | grep ^/ | sort -u -o $LIBS $LIBS -) || true
75-
76- local shebang=$(sed -n '1s/^#!\([^ ]*\).*/\1/p' "${f}")
77- if [ x$shebang != x ]; then
78- add_bin "$shebang"
79- fi
80-}
81-
82 for i in $@ bash ls cat echo readlink; do
83- I=`which $i`
84- add_bin $I
85-done
86-for i in `cat $BINS`; do
87- echo Adding binary $i 1>&2
88- cp "$i" ${DIR}/usr/bin/
89-done
90-for i in `cat $LIBS`; do
91- echo Adding library $i 1>&2
92- cp "$i" ${DIR}/usr/lib/
93+ I=$(readlink -f $(which $i))
94+ requisites=$(nix-store --query --requisites "$I")
95+ for r in $requisites; do
96+ # a single store item can be needed by multiple paths, no need to copy it again
97+ if [ ! -e ${DIR}/$r ]; then
98+ cp -r $r ${DIR}/$r
99+ fi
100+ done
101+ ln -s $I ${DIR}/usr/bin/$i
102 done
103 ln -s bash ${DIR}/usr/bin/sh
104
105-# We copy the C.UTF8 locale and call it en_US. Its a bit of a lie, but
106-# the real en_US locale is often not available, because its in the
107-# local archive.
108+mv ${DIR}/nix/store ${DIR}/usr/store # files outside /usr are not permitted, we will have to replace /nix/store with /usr/store
109+chmod -R u+w ${DIR} # nix store has read-only directories which would cause problems during clean-up, files need to be writable for sed
110+find ${DIR} -type f -print0 | xargs -0 sed -i 's~/nix/store/~/usr/store/~g' # replace hardcoded paths
111+find ${DIR} -type l | xargs -I '{}' sh -c 'tg="$(readlink "$1")"; newtg="${tg#/nix/store/}"; if [ "$tg" != "$newtg" ]; then ln -fs "/usr/store/$newtg" "$1"; fi' -- '{}' # replace symlink targets
112+
113+# We copy the whole locale archive because we do not have C.UTF8 locale
114 mkdir -p ${DIR}/usr/lib/locale/
115-cp -r /usr/lib/locale/C.* ${DIR}/usr/lib/locale/en_US
116+cp @glibcLocales@/lib/locale/locale-archive ${DIR}/usr/lib/locale/locale-archive
117
118 if [ x$COLLECTION_ID != x ]; then
119 collection_args=--collection-id=${COLLECTION_ID}
120--- a/tests/testlibrary.c
121+++ b/tests/testlibrary.c
122@@ -584,7 +584,7 @@
123 {
124 gint exit_code = 0;
125 char *argv[] = { (char *) bwrap, "--unshare-ipc", "--unshare-net",
126- "--unshare-pid", "--ro-bind", "/", "/", "/bin/true", NULL };
127+ "--unshare-pid", "--ro-bind", "/", "/", "@coreutils@/bin/true", NULL };
128 g_autofree char *argv_str = g_strjoinv (" ", argv);
129 g_test_message ("Spawning %s", argv_str);
130 g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &exit_code, &error);
131--- a/triggers/gtk-icon-cache.trigger
132+++ b/triggers/gtk-icon-cache.trigger
133@@ -1,7 +1,7 @@
134 #!/bin/sh
135
136 if test \( -x "$(which gtk-update-icon-cache 2>/dev/null)" \) -a \( -d $1/exports/share/icons/hicolor \); then
137- cp /usr/share/icons/hicolor/index.theme $1/exports/share/icons/hicolor/
138+ cp @hicolorIconTheme@/share/icons/hicolor/index.theme $1/exports/share/icons/hicolor/
139 for dir in $1/exports/share/icons/*; do
140 if test -f $dir/index.theme; then
141 if ! gtk-update-icon-cache --quiet $dir; then