1diff --git a/app/flatpak-builtins-build-export.c b/app/flatpak-builtins-build-export.c
2index 3f5d8a1f..79493e61 100644
3--- a/app/flatpak-builtins-build-export.c
4+++ b/app/flatpak-builtins-build-export.c
5@@ -464,7 +464,7 @@ validate_desktop_file (GFile *desktop_file,
6 subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
7 G_SUBPROCESS_FLAGS_STDERR_PIPE |
8 G_SUBPROCESS_FLAGS_STDERR_MERGE,
9- &local_error, "desktop-file-validate", path, NULL);
10+ &local_error, "@dfu@/bin/desktop-file-validate", path, NULL);
11 if (!subprocess)
12 {
13 if (!g_error_matches (local_error, G_SPAWN_ERROR, G_SPAWN_ERROR_NOENT))
14diff --git a/tests/libtest.sh b/tests/libtest.sh
15index 36d39ac4..3ad2c7a6 100644
16--- a/tests/libtest.sh
17+++ b/tests/libtest.sh
18@@ -511,7 +511,7 @@ if [ -z "${FLATPAK_BWRAP:-}" ]; then
19 # running installed-tests: assume we know what we're doing
20 _flatpak_bwrap_works=true
21 elif ! "$FLATPAK_BWRAP" --unshare-ipc --unshare-net --unshare-pid \
22- --ro-bind / / /bin/true > bwrap-result 2>&1; then
23+ --ro-bind / / @coreutils@/bin/true > bwrap-result 2>&1; then
24 _flatpak_bwrap_works=false
25 else
26 _flatpak_bwrap_works=true
27@@ -591,7 +591,7 @@ dbus-daemon --fork --config-file=session.conf --print-address=3 --print-pid=4 \
28 export DBUS_SESSION_BUS_ADDRESS="$(cat dbus-session-bus-address)"
29 DBUS_SESSION_BUS_PID="$(cat dbus-session-bus-pid)"
30
31-if ! /bin/kill -0 "$DBUS_SESSION_BUS_PID"; then
32+if ! @coreutils@/bin/kill -0 "$DBUS_SESSION_BUS_PID"; then
33 assert_not_reached "Failed to start dbus-daemon"
34 fi
35
36@@ -606,7 +606,7 @@ commit_to_path () {
37 }
38
39 cleanup () {
40- /bin/kill -9 $DBUS_SESSION_BUS_PID
41+ @coreutils@/bin/kill -9 $DBUS_SESSION_BUS_PID
42 gpg-connect-agent --homedir "${FL_GPG_HOMEDIR}" killagent /bye >&2 || true
43 fusermount -u $XDG_RUNTIME_DIR/doc >&2 || :
44 kill $(jobs -p) &> /dev/null || true
45diff --git a/tests/make-test-app.sh b/tests/make-test-app.sh
46index afa11a6b..5b12055f 100755
47--- a/tests/make-test-app.sh
48+++ b/tests/make-test-app.sh
49@@ -190,13 +190,13 @@ msgid "Hello world"
50 msgstr "Hallo Welt"
51 EOF
52 mkdir -p ${DIR}/files/de/share/de/LC_MESSAGES
53-msgfmt --output-file ${DIR}/files/de/share/de/LC_MESSAGES/helloworld.mo de.po
54+@gettext@/bin/msgfmt --output-file ${DIR}/files/de/share/de/LC_MESSAGES/helloworld.mo de.po
55 cat > fr.po <<EOF
56 msgid "Hello world"
57 msgstr "Bonjour le monde"
58 EOF
59 mkdir -p ${DIR}/files/fr/share/fr/LC_MESSAGES
60-msgfmt --output-file ${DIR}/files/fr/share/fr/LC_MESSAGES/helloworld.mo fr.po
61+@gettext@/bin/msgfmt --output-file ${DIR}/files/fr/share/fr/LC_MESSAGES/helloworld.mo fr.po
62
63 flatpak build-finish ${DIR} >&2
64 mkdir -p repos
65diff --git a/tests/make-test-runtime.sh b/tests/make-test-runtime.sh
66index 6345ff58..fd50fab3 100755
67--- a/tests/make-test-runtime.sh
68+++ b/tests/make-test-runtime.sh
69@@ -28,9 +28,10 @@ EOF
70
71 # On Debian derivatives, /usr/sbin and /sbin aren't in ordinary users'
72 # PATHs, but ldconfig is kept in /sbin
73-PATH="$PATH:/usr/sbin:/sbin"
74+PATH="$PATH:@socat@/bin:/usr/sbin:/sbin"
75
76 # Add bash and dependencies
77+mkdir -p ${DIR}/nix/store
78 mkdir -p ${DIR}/usr/bin
79 mkdir -p ${DIR}/usr/lib
80 ln -s ../lib ${DIR}/usr/lib64
81@@ -40,46 +41,17 @@ if test -f /sbin/ldconfig.real; then
82 else
83 cp "$(type -P ldconfig)" "${DIR}/usr/bin"
84 fi
85-LIBS=`mktemp`
86-BINS=`mktemp`
87-
88-add_bin() {
89- local f=$1
90- shift
91-
92- # Check if the program is installed
93- if ! command -v "${f}" &> /dev/null; then
94- echo "${f} not found"
95- exit 1
96- fi
97-
98- if grep -qFe "${f}" $BINS; then
99- # Already handled
100- return 0
101- fi
102-
103- echo $f >> $BINS
104-
105- # Add library dependencies
106- (ldd "${f}" | sed "s/.* => //" | awk '{ print $1}' | grep ^/ | sort -u -o $LIBS $LIBS -) || true
107-
108- local shebang=$(sed -n '1s/^#!\([^ ]*\).*/\1/p' "${f}")
109- if [ x$shebang != x ]; then
110- add_bin "$shebang"
111- fi
112-}
113-
114 for i in $@ bash ls cat echo readlink socat; do
115- I=$(type -P "$i")
116- add_bin "$I"
117-done
118-for i in `cat $BINS`; do
119- #echo Adding binary $i 1>&2
120- cp "$i" ${DIR}/usr/bin/
121-done
122-for i in `cat $LIBS`; do
123- #echo Adding library $i 1>&2
124- cp "$i" ${DIR}/usr/lib/
125+ I=$(readlink -f "$(type -P "$i")")
126+ [ -e "${DIR}/usr/bin/$i" ] && continue
127+ requisites=$(nix-store --query --requisites "$I")
128+ for r in $requisites; do
129+ # a single store item can be needed by multiple paths, no need to copy it again
130+ if [ ! -e "${DIR}/$r" ]; then
131+ cp -r "$r" "${DIR}/$r"
132+ fi
133+ done
134+ ln -s "$I" "${DIR}/usr/bin/$i"
135 done
136 ln -s bash ${DIR}/usr/bin/sh
137
138@@ -90,11 +62,13 @@ echo "Hello world, from a runtime$EXTRA"
139 EOF
140 chmod a+x ${DIR}/usr/bin/runtime_hello.sh
141
142-# We copy the C.UTF8 locale and call it en_US. Its a bit of a lie, but
143-# the real en_US locale is often not available, because its in the
144-# local archive.
145-mkdir -p ${DIR}/usr/lib/locale/
146-cp -r /usr/lib/locale/C.* ${DIR}/usr/lib/locale/en_US
147+# We do not copy C.UTF8 locale because it is in locale archive and
148+# that is already copied with glibc.
149+
150+mv "${DIR}/nix/store" "${DIR}/usr/store" # files outside /usr are not permitted, we will have to replace /nix/store with /usr/store
151+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
152+find "${DIR}" -type f -print0 | xargs -0 sed -i 's~/nix/store/~/usr/store/~g' # replace hardcoded paths
153+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
154
155 if [ x$COLLECTION_ID != x ]; then
156 collection_args=--collection-id=${COLLECTION_ID}
157diff --git a/tests/testlibrary.c b/tests/testlibrary.c
158index 831d85c1..ae4f03d0 100644
159--- a/tests/testlibrary.c
160+++ b/tests/testlibrary.c
161@@ -1601,7 +1601,7 @@ check_bwrap_support (void)
162 {
163 gint exit_code = 0;
164 char *argv[] = { (char *) bwrap, "--unshare-ipc", "--unshare-net",
165- "--unshare-pid", "--ro-bind", "/", "/", "/bin/true", NULL };
166+ "--unshare-pid", "--ro-bind", "/", "/", "@coreutils@/bin/true", NULL };
167 g_autofree char *argv_str = g_strjoinv (" ", argv);
168 g_test_message ("Spawning %s", argv_str);
169 g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &exit_code, &error);
170diff --git a/triggers/desktop-database.trigger b/triggers/desktop-database.trigger
171index 1037466d..c4c7ed6d 100755
172--- a/triggers/desktop-database.trigger
173+++ b/triggers/desktop-database.trigger
174@@ -1,5 +1,5 @@
175 #!/bin/sh
176
177-if command -v update-desktop-database >/dev/null && test -d "$1/exports/share/applications"; then
178- exec update-desktop-database -q "$1/exports/share/applications"
179+if test -d "$1/exports/share/applications"; then
180+ exec @dfu@/bin/update-desktop-database -q "$1/exports/share/applications"
181 fi
182diff --git a/triggers/gtk-icon-cache.trigger b/triggers/gtk-icon-cache.trigger
183index d9fc8251..d8ddb96e 100755
184--- a/triggers/gtk-icon-cache.trigger
185+++ b/triggers/gtk-icon-cache.trigger
186@@ -1,10 +1,10 @@
187 #!/bin/sh
188
189-if command -v gtk-update-icon-cache >/dev/null && test -d "$1/exports/share/icons/hicolor"; then
190- cp /usr/share/icons/hicolor/index.theme "$1/exports/share/icons/hicolor/"
191+if test -d "$1/exports/share/icons/hicolor"; then
192+ @coreutils@/bin/cp -f @hicolorIconTheme@/share/icons/hicolor/index.theme "$1/exports/share/icons/hicolor/"
193 for dir in "$1"/exports/share/icons/*; do
194 if test -f "$dir/index.theme"; then
195- if ! gtk-update-icon-cache --quiet "$dir"; then
196- echo "Failed to run gtk-update-icon-cache for $dir"
197+ if ! @gtk3@/bin/gtk-update-icon-cache --quiet "$dir"; then
198+ @coreutils@/bin/echo "Failed to run gtk-update-icon-cache for $dir"
199 exit 1
200 fi
201diff --git a/triggers/mime-database.trigger b/triggers/mime-database.trigger
202index 10ddbbb3..c270998a 100755
203--- a/triggers/mime-database.trigger
204+++ b/triggers/mime-database.trigger
205@@ -1,5 +1,5 @@
206 #!/bin/sh
207
208-if command -v update-mime-database >/dev/null && test -d "$1/exports/share/mime/packages"; then
209- exec update-mime-database "$1/exports/share/mime"
210+if test -d "$1/exports/share/mime/packages"; then
211+ exec @smi@/bin/update-mime-database "$1/exports/share/mime"
212 fi