diff --git a/tests/Makefile.am b/tests/Makefile.am
index bfb8508a02b5a7fc43dcb50c3a02389e1b8484cf..31ad159b06b21cb6586e7fcb693961546364de6b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,14 +2,11 @@ TESTS_ENVIRONMENT = $(SHELL) -e
 
 extra1 = $(shell pwd)/test-tmp/shared
 
-simple.sh: simple.nix
+simple.sh substitutes.sh substitutes2.sh fallback.sh: simple.nix
 dependencies.sh gc.sh nix-push.sh nix-pull.in logging.sh nix-build.sh install-package.sh check-refs.sh: dependencies.nix
 locking.sh: locking.nix
 parallel.sh: parallel.nix
 build-hook.sh: build-hook.nix
-substitutes.sh: substitutes.nix
-substitutes2.sh: substitutes2.nix
-fallback.sh: fallback.nix
 gc-concurrent.sh: gc-concurrent.nix gc-concurrent2.nix
 user-envs.sh: user-envs.nix
 fixed.sh: fixed.nix
@@ -36,11 +33,9 @@ EXTRA_DIST = $(TESTS) \
   locking.nix.in locking.builder.sh \
   parallel.nix.in parallel.builder.sh \
   build-hook.nix.in build-hook.hook.sh \
-  substitutes.nix.in substituter.sh \
-  substitutes2.nix.in substituter2.sh \
+  substituter.sh substituter2.sh \
   gc-concurrent.nix.in gc-concurrent.builder.sh \
   gc-concurrent2.nix.in gc-concurrent2.builder.sh \
-  fallback.nix.in \
   user-envs.nix.in user-envs.builder.sh \
   fixed.nix.in fixed.builder1.sh fixed.builder2.sh \
   gc-runtime.nix.in \
diff --git a/tests/common.sh.in b/tests/common.sh.in
index 32759bab01d2a2536379eb7bec26bd2e24062cd1..1b8bb3e7df428a160cc8c921304272bf97a2e74c 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -65,3 +65,7 @@ clearProfiles() {
     profiles="$NIX_STATE_DIR"/profiles
     rm -f $profiles/*
 }
+
+clearManifests() {
+    rm -f $NIX_STATE_DIR/manifests/*
+}
diff --git a/tests/fallback.nix.in b/tests/fallback.nix.in
deleted file mode 100644
index e47b59823bd088b516f7c63fd82c3931da44585c..0000000000000000000000000000000000000000
--- a/tests/fallback.nix.in
+++ /dev/null
@@ -1,7 +0,0 @@
-derivation {
-  name = "fall-back";
-  system = "@system@";
-  builder = "@shell@";
-  args = ["-e" "-x" ./simple.builder.sh];
-  goodPath = "@testPath@";
-}
diff --git a/tests/fallback.sh b/tests/fallback.sh
index 482e4ce5b72ccafa5c4410bc2ddc626e2b8b42e0..24889a452881dc686a577039e3b58cc914ab08c4 100644
--- a/tests/fallback.sh
+++ b/tests/fallback.sh
@@ -1,15 +1,19 @@
 source common.sh
 
-drvPath=$($nixinstantiate fallback.nix)
+clearStore
+
+drvPath=$($nixinstantiate simple.nix)
 echo "derivation is $drvPath"
 
 outPath=$($nixstore -q --fallback "$drvPath")
 echo "output path is $outPath"
 
-# Register a non-existant substitute
-(echo $outPath && echo "" && echo $TOP/no-such-program && echo 0 && echo 0) | $nixstore --register-substitutes
+# Build with a substitute that fails.  This should fail.
+export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh
+if $nixstore -r "$drvPath"; then echo unexpected fallback; exit 1; fi
 
-# Build the derivation
+# Build with a substitute that fails.  This should fall back to a source build.
+export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh
 $nixstore -r --fallback "$drvPath"
 
 text=$(cat "$outPath"/hello)
diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh
index a847510cebfeb13a91d6eba75b8412c8347be6bb..5ef3e55cae51d135119e564aa1f1ffc3b5fc4be0 100644
--- a/tests/nix-pull.sh
+++ b/tests/nix-pull.sh
@@ -6,6 +6,7 @@ pullCache () {
 }
 
 clearStore
+clearManifests
 pullCache
 
 drvPath=$($nixinstantiate dependencies.nix)
@@ -17,6 +18,7 @@ $nixstore -r $outPath
 cat $outPath/input-2/bar
 
 clearStore
+clearManifests
 pullCache
 
 echo "building $drvPath using substitutes..."
@@ -28,4 +30,4 @@ cat $outPath/input-2/bar
 test $($nixstore -q --deriver "$outPath") = "$drvPath"
 $nixstore -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" 
 
-$nixstore --clear-substitutes
+clearManifests
diff --git a/tests/simple.builder.sh b/tests/simple.builder.sh
index 536faec1491507e70afccc93b0417cf5033fc585..569e8ca88c1e479d9c1cfefb5582fd93de2e5966 100644
--- a/tests/simple.builder.sh
+++ b/tests/simple.builder.sh
@@ -1,7 +1,7 @@
 echo "PATH=$PATH"
 
 # Verify that the PATH is empty.
-if mkdir foo; then exit 1; fi
+if mkdir foo 2> /dev/null; then exit 1; fi
 
 # Set a PATH (!!! impure).
 export PATH=$goodPath
diff --git a/tests/substituter.sh b/tests/substituter.sh
index 005e97605c915098c6da505f5f5e86c4331b708e..96fb95b91f6bede2b249d2c672a6aa8698b9b290 100755
--- a/tests/substituter.sh
+++ b/tests/substituter.sh
@@ -1,10 +1,19 @@
-#! /bin/sh -ex
-echo $*
-
-case $* in
-    *)
-        mkdir $1
-        echo $3 $4 > $1/hello
-        ;;
-esac        
+#! /bin/sh -e
+echo substituter args: $* >&2
 
+if test $1 = "--query-paths"; then
+    cat $TEST_ROOT/sub-paths
+elif test $1 = "--query-info"; then
+    shift
+    for i in in $@; do
+        echo $i
+        echo "" # deriver
+        echo 0 # nr of refs
+    done
+elif test $1 = "--substitute"; then
+    mkdir $2
+    echo "Hallo Wereld" > $2/hello
+else
+    echo "unknown substituter operation"
+    exit 1
+fi
diff --git a/tests/substituter2.sh b/tests/substituter2.sh
index c4e1bfec7b395cdaf1b9c6cf59c0d020a741a185..1bcf65a54d0ed305f550d274a59696a2e57cfa7e 100755
--- a/tests/substituter2.sh
+++ b/tests/substituter2.sh
@@ -1,3 +1,18 @@
-#! /bin/sh -ex
-echo $*
-exit 1
+#! /bin/sh -e
+echo substituter2 args: $* >&2
+
+if test $1 = "--query-paths"; then
+    cat $TEST_ROOT/sub-paths
+elif test $1 = "--query-info"; then
+    shift
+    for i in in $@; do
+        echo $i
+        echo "" # deriver
+        echo 0 # nr of refs
+    done
+elif test $1 = "--substitute"; then
+    exit 1
+else
+    echo "unknown substituter operation"
+    exit 1
+fi
diff --git a/tests/substitutes.nix.in b/tests/substitutes.nix.in
deleted file mode 100644
index e3473621608de56b89b6d5026f23aeaf92a88cad..0000000000000000000000000000000000000000
--- a/tests/substitutes.nix.in
+++ /dev/null
@@ -1,6 +0,0 @@
-derivation {
-  name = "substitutes";
-  system = "@system@";
-  builder = "@shell@";
-  args = ["-e" "-x" ./simple.builder.sh];
-}
\ No newline at end of file
diff --git a/tests/substitutes.sh b/tests/substitutes.sh
index c44f012f5924696973f751733e8d86107ad5db6d..042827314bd9f7bc3459e060f94916702e903ffc 100644
--- a/tests/substitutes.sh
+++ b/tests/substitutes.sh
@@ -1,22 +1,20 @@
 source common.sh
 
+clearStore
+
 # Instantiate.
-drvPath=$($nixinstantiate substitutes.nix)
+drvPath=$($nixinstantiate simple.nix)
 echo "derivation is $drvPath"
 
 # Find the output path.
 outPath=$($nixstore -qvv "$drvPath")
 echo "output path is $outPath"
 
-regSub() {
-    (echo $1 && echo "" && echo $2 && echo 3 && echo $outPath && echo Hallo && echo Wereld && echo 0) | $nixstore --register-substitutes
-}
-
-# Register a substitute for the output path.
-regSub $outPath $(pwd)/substituter.sh
+echo $outPath > $TEST_ROOT/sub-paths
 
+export NIX_SUBSTITUTERS=$(pwd)/substituter.sh
 
 $nixstore -rvv "$drvPath"
 
 text=$(cat "$outPath"/hello)
-if test "$text" != "Hallo Wereld"; then exit 1; fi
+if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi
diff --git a/tests/substitutes2.nix.in b/tests/substitutes2.nix.in
deleted file mode 100644
index 8ade1ba11674a0b855d55655e18b62aee7c2fb39..0000000000000000000000000000000000000000
--- a/tests/substitutes2.nix.in
+++ /dev/null
@@ -1,6 +0,0 @@
-derivation {
-  name = "substitutes-2";
-  system = "@system@";
-  builder = "@shell@";
-  args = ["-e" "-x" ./simple.builder.sh];
-}
\ No newline at end of file
diff --git a/tests/substitutes2.sh b/tests/substitutes2.sh
index 416e815360c20c0065fac0f5b6b56507a362916f..0bbc13913dac6c39d56814a57b08c060203eb4a8 100644
--- a/tests/substitutes2.sh
+++ b/tests/substitutes2.sh
@@ -1,25 +1,21 @@
 source common.sh
 
+clearStore
+
 # Instantiate.
-drvPath=$($nixinstantiate substitutes2.nix)
+drvPath=$($nixinstantiate simple.nix)
 echo "derivation is $drvPath"
 
 # Find the output path.
 outPath=$($nixstore -qvvvvv "$drvPath")
 echo "output path is $outPath"
 
-regSub() {
-    (echo $1 && echo "" && echo $2 && echo 3 && echo $outPath && echo Hallo && echo Wereld && echo 0) | $nixstore --register-substitutes
-}
-
-# Register a substitute for the output path.
-regSub $outPath $(pwd)/substituter.sh
+echo $outPath > $TEST_ROOT/sub-paths
 
-# Register another substitute for the output path.  This one takes
-# precedence over the previous one.  It will fail.
-regSub $outPath $(pwd)/substituter2.sh
+# First try a substituter that fails, then one that succeeds
+export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh:$(pwd)/substituter.sh
 
 $nixstore -rvv "$drvPath"
 
 text=$(cat "$outPath"/hello)
-if test "$text" != "Hallo Wereld"; then exit 1; fi
+if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi