1diff --git a/app/flatpak-builtins-build-export.c b/app/flatpak-builtins-build-export.c
2index 5de89d62..bf6bdb52 100644
3--- a/app/flatpak-builtins-build-export.c
4+++ b/app/flatpak-builtins-build-export.c
5@@ -458,7 +458,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 e64be49f..a9a53e12 100644
16--- a/tests/libtest.sh
17+++ b/tests/libtest.sh
18@@ -367,7 +367,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@@ -440,7 +440,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@@ -449,7 +449,7 @@ gdb_bt () {
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 || true
43 fusermount -u $XDG_RUNTIME_DIR/doc || :
44 kill $(jobs -p) &> /dev/null || true
45diff --git a/tests/make-test-app.sh b/tests/make-test-app.sh
46index e51e21a6..7d39efb5 100755
47--- a/tests/make-test-app.sh
48+++ b/tests/make-test-app.sh
49@@ -149,13 +149,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}
64 mkdir -p repos
65diff --git a/tests/make-test-runtime.sh b/tests/make-test-runtime.sh
66index 5d2c309b..cf61a3cf 100755
67--- a/tests/make-test-runtime.sh
68+++ b/tests/make-test-runtime.sh
69@@ -25,9 +25,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@@ -37,48 +38,24 @@ if test -f /sbin/ldconfig.real; then
82 else
83 cp `which ldconfig` ${DIR}/usr/bin
84 fi
85-LIBS=`mktemp`
86-BINS=`mktemp`
87-
88-add_bin() {
89- local f=$1
90- shift
91-
92- if grep -qFe "${f}" $BINS; then
93- # Already handled
94- return 0
95- fi
96-
97- echo $f >> $BINS
98-
99- # Add library dependencies
100- (ldd "${f}" | sed "s/.* => //" | awk '{ print $1}' | grep ^/ | sort -u -o $LIBS $LIBS -) || true
101-
102- local shebang=$(sed -n '1s/^#!\([^ ]*\).*/\1/p' "${f}")
103- if [ x$shebang != x ]; then
104- add_bin "$shebang"
105- fi
106-}
107-
108 for i in $@ bash ls cat echo readlink socat; do
109- I=`which $i`
110- add_bin $I
111-done
112-for i in `cat $BINS`; do
113- #echo Adding binary $i 1>&2
114- cp "$i" ${DIR}/usr/bin/
115-done
116-for i in `cat $LIBS`; do
117- #echo Adding library $i 1>&2
118- cp "$i" ${DIR}/usr/lib/
119+ I=$(readlink -f $(which $i))
120+ [ -e ${DIR}/usr/bin/$i ] && continue
121+ requisites=$(nix-store --query --requisites "$I")
122+ for r in $requisites; do
123+ # a single store item can be needed by multiple paths, no need to copy it again
124+ if [ ! -e ${DIR}/$r ]; then
125+ cp -r $r ${DIR}/$r
126+ fi
127+ done
128+ ln -s $I ${DIR}/usr/bin/$i
129 done
130 ln -s bash ${DIR}/usr/bin/sh
131
132-# We copy the C.UTF8 locale and call it en_US. Its a bit of a lie, but
133-# the real en_US locale is often not available, because its in the
134-# local archive.
135-mkdir -p ${DIR}/usr/lib/locale/
136-cp -r /usr/lib/locale/C.* ${DIR}/usr/lib/locale/en_US
137+mv ${DIR}/nix/store ${DIR}/usr/store # files outside /usr are not permitted, we will have to replace /nix/store with /usr/store
138+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
139+find ${DIR} -type f -print0 | xargs -0 sed -i 's~/nix/store/~/usr/store/~g' # replace hardcoded paths
140+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
141
142 if [ x$COLLECTION_ID != x ]; then
143 collection_args=--collection-id=${COLLECTION_ID}
144diff --git a/tests/testlibrary.c b/tests/testlibrary.c
145index 44ae28e3..76bf619f 100644
146--- a/tests/testlibrary.c
147+++ b/tests/testlibrary.c
148@@ -1343,7 +1343,7 @@ check_bwrap_support (void)
149 {
150 gint exit_code = 0;
151 char *argv[] = { (char *) bwrap, "--unshare-ipc", "--unshare-net",
152- "--unshare-pid", "--ro-bind", "/", "/", "/bin/true", NULL };
153+ "--unshare-pid", "--ro-bind", "/", "/", "@coreutils@/bin/true", NULL };
154 g_autofree char *argv_str = g_strjoinv (" ", argv);
155 g_test_message ("Spawning %s", argv_str);
156 g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &exit_code, &error);
157diff --git a/triggers/desktop-database.trigger b/triggers/desktop-database.trigger
158index 2188f535..d8283061 100755
159--- a/triggers/desktop-database.trigger
160+++ b/triggers/desktop-database.trigger
161@@ -1,5 +1,5 @@
162 #!/bin/sh
163
164-if test \( -x "$(which update-desktop-database 2>/dev/null)" \) -a \( -d $1/exports/share/applications \); then
165- exec update-desktop-database -q $1/exports/share/applications
166+if test \( -d $1/exports/share/applications \); then
167+ exec @dfu@/bin/update-desktop-database -q $1/exports/share/applications
168 fi
169diff --git a/triggers/gtk-icon-cache.trigger b/triggers/gtk-icon-cache.trigger
170index 711cfab2..07baa2ac 100755
171--- a/triggers/gtk-icon-cache.trigger
172+++ b/triggers/gtk-icon-cache.trigger
173@@ -1,10 +1,10 @@
174 #!/bin/sh
175
176-if test \( -x "$(which gtk-update-icon-cache 2>/dev/null)" \) -a \( -d $1/exports/share/icons/hicolor \); then
177- cp /usr/share/icons/hicolor/index.theme $1/exports/share/icons/hicolor/
178+if test \( -d $1/exports/share/icons/hicolor \); then
179+ cp @hicolorIconTheme@/share/icons/hicolor/index.theme $1/exports/share/icons/hicolor/
180 for dir in $1/exports/share/icons/*; do
181 if test -f $dir/index.theme; then
182- if ! gtk-update-icon-cache --quiet $dir; then
183+ if ! @gtk3@/bin/gtk-update-icon-cache --quiet $dir; then
184 echo "Failed to run gtk-update-icon-cache for $dir"
185 exit 1
186 fi
187diff --git a/triggers/mime-database.trigger b/triggers/mime-database.trigger
188index 2067d8ec..a49a8777 100755
189--- a/triggers/mime-database.trigger
190+++ b/triggers/mime-database.trigger
191@@ -1,5 +1,5 @@
192 #!/bin/sh
193
194-if test \( -x "$(which update-mime-database 2>/dev/null)" \) -a \( -d $1/exports/share/mime/packages \); then
195- exec update-mime-database $1/exports/share/mime
196+if test \( -d $1/exports/share/mime/packages \); then
197+ exec @smi@/bin/update-mime-database $1/exports/share/mime
198 fi