diff --git a/tests/Makefile.am b/tests/Makefile.am
index 540665ea9ef0cb1512950d63ae8ca934f5c4b453..225f780b8ec5eeb6721cb531ef3a057455e62f80 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,7 +3,7 @@ TESTS_ENVIRONMENT = $(SHELL) -e
 extra1 = $(shell pwd)/test-tmp/shared
 
 simple.sh: simple.nix
-dependencies.sh gc.sh nix-push.sh nix-pull.in logging.sh: dependencies.nix
+dependencies.sh gc.sh nix-push.sh nix-pull.in logging.sh nix-build.sh: dependencies.nix
 locking.sh: locking.nix
 parallel.sh: parallel.nix
 build-hook.sh: build-hook.nix
@@ -16,7 +16,7 @@ user-envs.sh: user-envs.nix
 TESTS = init.sh hash.sh lang.sh simple.sh dependencies.sh locking.sh parallel.sh \
   build-hook.sh substitutes.sh substitutes2.sh fallback.sh nix-push.sh gc.sh \
   gc-concurrent.sh verify.sh nix-pull.sh referrers.sh user-envs.sh \
-  logging.sh misc.sh
+  logging.sh nix-build.sh misc.sh
 
 XFAIL_TESTS =
 
diff --git a/tests/init.sh b/tests/init.sh
index a11d63f7592484adea6bc9aa92d55c8340afdbae..11e0632a484239195b1b9e903e9d973951da8668 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -23,6 +23,7 @@ ln -s $nixinstantiate $NIX_BIN_DIR/
 ln -s $nixhash $NIX_BIN_DIR/
 ln -s $TOP/scripts/nix-prefetch-url $NIX_BIN_DIR/
 ln -s $TOP/scripts/nix-collect-garbage $NIX_BIN_DIR/
+ln -s $TOP/scripts/nix-build $NIX_BIN_DIR/
 mkdir $NIX_BIN_DIR/nix
 ln -s $TOP/scripts/download-using-manifests.pl $NIX_BIN_DIR/nix/
 ln -s $TOP/scripts/readmanifest.pm $NIX_BIN_DIR/nix/
@@ -48,6 +49,7 @@ for i in \
     $NIX_BIN_DIR/nix/download-using-manifests.pl \
     $NIX_BIN_DIR/nix-prefetch-url \
     $NIX_BIN_DIR/nix-collect-garbage \
+    $NIX_BIN_DIR/nix-build \
     ; do
     echo "$REAL_BIN_DIR"
     sed < $i > $i.tmp \
diff --git a/tests/logging.sh b/tests/logging.sh
index 50808d264b919fa387c54598a19c81296e3b9aac..80d186a754bc8ca5f7e877cf55018f914827695f 100644
--- a/tests/logging.sh
+++ b/tests/logging.sh
@@ -1,7 +1,6 @@
 source common.sh
 
 $nixstore --gc
-$nixstore --clear-substitutes
 
 # Produce an escaped log file.
 $nixstore --log-type escapes -r -vv $($nixinstantiate dependencies.nix) 2> $TEST_ROOT/log.esc
diff --git a/tests/nix-build.sh b/tests/nix-build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..23f8ce99875f147efa4c306d1b32799396f69439
--- /dev/null
+++ b/tests/nix-build.sh
@@ -0,0 +1,17 @@
+source common.sh
+
+$nixstore --gc
+
+(cd $TEST_ROOT && $NIX_BIN_DIR/nix-build ../dependencies.nix)
+test "$(cat $TEST_ROOT/result/foobar)" = FOOBAR
+
+# The result should be retained by a GC.
+target=$(ls -l $TEST_ROOT/result | sed 's/.*->\ //')
+echo target is $target
+$nixstore --gc
+test -e $target/foobar
+
+# But now it should be gone.
+rm $TEST_ROOT/result
+$nixstore --gc
+if test -e $target/foobar; then false; fi
diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh
index 146227b71aacf521c91328aee9e5cdef9be009fc..03dcdb21d506d9504c7624ee3f827d35316f70f5 100644
--- a/tests/nix-pull.sh
+++ b/tests/nix-pull.sh
@@ -36,4 +36,6 @@ cat $outPath/input-2/bar
 
 # Check that the derivers are set properly.
 test $($nixstore -q --deriver "$outPath") = "$drvPath"
-$nixstore -q --deriver $(/bin/ls -l $outPath/input-2 | sed 's/.*->\ //') | grep -q -- "-input-2.drv" 
+$nixstore -q --deriver $(ls -l $outPath/input-2 | sed 's/.*->\ //') | grep -q -- "-input-2.drv" 
+
+$nixstore --clear-substitutes