about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/add.sh12
-rw-r--r--tests/binary-patching.sh32
-rw-r--r--tests/build-hook.sh2
-rw-r--r--tests/check-refs.sh28
-rw-r--r--tests/common.sh.in31
-rw-r--r--tests/dependencies.sh20
-rw-r--r--tests/export-graph.sh10
-rw-r--r--tests/export.sh14
-rw-r--r--tests/fallback.sh8
-rw-r--r--tests/filter-source.sh2
-rw-r--r--tests/fixed.sh20
-rw-r--r--tests/gc-concurrent.sh20
-rw-r--r--tests/gc-runtime.sh10
-rw-r--r--tests/gc.sh22
-rw-r--r--tests/hash.sh12
-rw-r--r--tests/init.sh48
-rw-r--r--tests/install-package.sh12
-rw-r--r--tests/lang.sh10
-rw-r--r--tests/logging.sh2
-rw-r--r--tests/misc.sh14
-rw-r--r--tests/negative-caching.sh6
-rw-r--r--tests/nix-build.sh6
-rw-r--r--tests/nix-copy-closure.nix54
-rw-r--r--tests/nix-pull.sh14
-rw-r--r--tests/nix-push.sh7
-rw-r--r--tests/parallel.sh6
-rw-r--r--tests/referrers.sh6
-rw-r--r--tests/remote-builds.nix97
-rw-r--r--tests/secure-drv-outputs.sh12
-rw-r--r--tests/simple.sh10
-rw-r--r--tests/substitutes.sh8
-rw-r--r--tests/substitutes2.sh6
-rw-r--r--tests/timeout.sh6
-rw-r--r--tests/user-envs.sh92
-rw-r--r--tests/verify.sh2
35 files changed, 396 insertions, 265 deletions
diff --git a/tests/add.sh b/tests/add.sh
index 7ea4cb6d6a99..e26e05843d7f 100644
--- a/tests/add.sh
+++ b/tests/add.sh
@@ -1,9 +1,9 @@
 source common.sh
 
-path1=$($nixstore --add ./dummy)
+path1=$(nix-store --add ./dummy)
 echo $path1
 
-path2=$($nixstore --add-fixed sha256 --recursive ./dummy)
+path2=$(nix-store --add-fixed sha256 --recursive ./dummy)
 echo $path2
 
 if test "$path1" != "$path2"; then
@@ -11,18 +11,18 @@ if test "$path1" != "$path2"; then
     exit 1
 fi    
 
-path3=$($nixstore --add-fixed sha256 ./dummy)
+path3=$(nix-store --add-fixed sha256 ./dummy)
 echo $path3
 test "$path1" != "$path3" || exit 1
 
-path4=$($nixstore --add-fixed sha1 --recursive ./dummy)
+path4=$(nix-store --add-fixed sha1 --recursive ./dummy)
 echo $path4
 test "$path1" != "$path4" || exit 1
 
-hash1=$($nixstore -q --hash $path1)
+hash1=$(nix-store -q --hash $path1)
 echo $hash1
 
-hash2=$($nixhash --type sha256 --base32 ./dummy)
+hash2=$(nix-hash --type sha256 --base32 ./dummy)
 echo $hash2
 
 test "$hash1" = "sha256:$hash2"
diff --git a/tests/binary-patching.sh b/tests/binary-patching.sh
index 60e57b4b00dc..8c52c2f1421b 100644
--- a/tests/binary-patching.sh
+++ b/tests/binary-patching.sh
@@ -7,52 +7,52 @@ mkdir -p $TEST_ROOT/cache2 $TEST_ROOT/patches
 RESULT=$TEST_ROOT/result
 
 # Build version 1 and 2 of the "foo" package.
-$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \
-    $($nixbuild -o $RESULT binary-patching.nix --arg version 1)
+nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \
+    $(nix-build -o $RESULT binary-patching.nix --arg version 1)
 
-out2=$($nixbuild -o $RESULT binary-patching.nix --arg version 2)
-$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2
+out2=$(nix-build -o $RESULT binary-patching.nix --arg version 2)
+nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2
     
-out3=$($nixbuild -o $RESULT binary-patching.nix --arg version 3)
-$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest3 $out3
+out3=$(nix-build -o $RESULT binary-patching.nix --arg version 3)
+nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest3 $out3
 
 rm $RESULT
 
 # Generate binary patches.
-$NIX_BIN_DIR/nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
+nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
     file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest2
 
-$NIX_BIN_DIR/nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
+nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
     file://$TEST_ROOT/patches $TEST_ROOT/manifest2 $TEST_ROOT/manifest3
 
 grep -q "patch {" $TEST_ROOT/manifest3
 
 # Get rid of versions 2 and 3.
-$nixstore --delete $out2 $out3
+nix-store --delete $out2 $out3
 
 # Pull the manifest containing the patches.
 clearManifests
-$NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest3
+nix-pull file://$TEST_ROOT/manifest3
 
 # Make sure that the download size prediction uses the patches rather
 # than the full download.
-$nixbuild -o $RESULT binary-patching.nix --arg version 3 --dry-run 2>&1 | grep -q "0.01 MiB"
+nix-build -o $RESULT binary-patching.nix --arg version 3 --dry-run 2>&1 | grep -q "0.01 MiB"
 
 # Now rebuild it.  This should use the two patches generated above.
 rm -f $TEST_ROOT/var/log/nix/downloads
-$nixbuild -o $RESULT binary-patching.nix --arg version 3
+nix-build -o $RESULT binary-patching.nix --arg version 3
 rm $RESULT
 [ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 2 ]
 
 # Add a patch from version 1 directly to version 3.
-$NIX_BIN_DIR/nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
+nix-generate-patches $TEST_ROOT/cache2 $TEST_ROOT/patches \
     file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest3
 
 # Rebuild version 3.  This should use the direct patch rather than the
 # sequence of two patches.
-$nixstore --delete $out2 $out3
+nix-store --delete $out2 $out3
 clearManifests
 rm $TEST_ROOT/var/log/nix/downloads
-$NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest3
-$nixbuild -o $RESULT binary-patching.nix --arg version 3
+nix-pull file://$TEST_ROOT/manifest3
+nix-build -o $RESULT binary-patching.nix --arg version 3
 [ "$(grep ' patch ' $TEST_ROOT/var/log/nix/downloads | wc -l)" -eq 1 ]
diff --git a/tests/build-hook.sh b/tests/build-hook.sh
index b9de00993654..c733b2680408 100644
--- a/tests/build-hook.sh
+++ b/tests/build-hook.sh
@@ -2,7 +2,7 @@ source common.sh
 
 export NIX_BUILD_HOOK="build-hook.hook.sh"
 
-outPath=$($nixbuild build-hook.nix)
+outPath=$(nix-build build-hook.nix)
 
 echo "output path is $outPath"
 
diff --git a/tests/check-refs.sh b/tests/check-refs.sh
index 0e80b1541ff7..08fe01ec18b4 100644
--- a/tests/check-refs.sh
+++ b/tests/check-refs.sh
@@ -4,33 +4,33 @@ set -x
 
 RESULT=$TEST_ROOT/result
 
-dep=$($nixbuild -o $RESULT check-refs.nix -A dep)
+dep=$(nix-build -o $RESULT check-refs.nix -A dep)
 
 # test1 references dep, not itself.
-test1=$($nixbuild -o $RESULT check-refs.nix -A test1)
-! $nixstore -q --references $test1 | grep -q $test1
-$nixstore -q --references $test1 | grep -q $dep
+test1=$(nix-build -o $RESULT check-refs.nix -A test1)
+! nix-store -q --references $test1 | grep -q $test1
+nix-store -q --references $test1 | grep -q $dep
 
 # test2 references src, not itself nor dep.
-test2=$($nixbuild -o $RESULT check-refs.nix -A test2)
-! $nixstore -q --references $test2 | grep -q $test2
-! $nixstore -q --references $test2 | grep -q $dep
-$nixstore -q --references $test2 | grep -q aux-ref
+test2=$(nix-build -o $RESULT check-refs.nix -A test2)
+! nix-store -q --references $test2 | grep -q $test2
+! nix-store -q --references $test2 | grep -q $dep
+nix-store -q --references $test2 | grep -q aux-ref
 
 # test3 should fail (unallowed ref).
-! $nixbuild -o $RESULT check-refs.nix -A test3
+! nix-build -o $RESULT check-refs.nix -A test3
 
 # test4 should succeed.
-$nixbuild -o $RESULT check-refs.nix -A test4
+nix-build -o $RESULT check-refs.nix -A test4
 
 # test5 should succeed.
-$nixbuild -o $RESULT check-refs.nix -A test5
+nix-build -o $RESULT check-refs.nix -A test5
 
 # test6 should fail (unallowed self-ref).
-! $nixbuild -o $RESULT check-refs.nix -A test6
+! nix-build -o $RESULT check-refs.nix -A test6
 
 # test7 should succeed (allowed self-ref).
-$nixbuild -o $RESULT check-refs.nix -A test7
+nix-build -o $RESULT check-refs.nix -A test7
 
 # test8 should fail (toFile depending on derivation output).
-! $nixbuild -o $RESULT check-refs.nix -A test8
+! nix-build -o $RESULT check-refs.nix -A test8
diff --git a/tests/common.sh.in b/tests/common.sh.in
index b03cd49ec70d..62ac669df665 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -1,5 +1,7 @@
 set -e
 
+export TOP=$(pwd)/..
+
 export TEST_ROOT=$(pwd)/test-tmp
 export NIX_STORE_DIR
 if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
@@ -15,9 +17,12 @@ export NIX_DB_DIR=$TEST_ROOT/db
 export NIX_CONF_DIR=$TEST_ROOT/etc
 export NIX_BIN_DIR=$TEST_ROOT/bin
 export NIX_LIBEXEC_DIR=$TEST_ROOT/bin
+export NIX_MANIFESTS_DIR=$TEST_ROOT/var/nix/manifests
 export NIX_ROOT_FINDER=
 export SHARED=$TEST_ROOT/shared
 
+export PATH=$NIX_BIN_DIR:$TOP/scripts:$PATH
+
 export NIX_REMOTE=
 
 export REAL_BIN_DIR=@bindir@
@@ -27,10 +32,10 @@ export REAL_DATA_DIR=@datadir@
 export REAL_STORE_DIR=@storedir@
 export NIX_BUILD_HOOK=
 export PERL=perl
-export TOP=$(pwd)/..
-export bzip2_bin_test="@bzip2_bin_test@"
-if test "${bzip2_bin_test:0:1}" != "/"; then
-    bzip2_bin_test=`pwd`/${bzip2_bin_test}
+export PERL5LIB=$TOP/perl/lib:$PERL5LIB
+export NIX_BZIP2="@bzip2_bin_test@/bzip2"
+if test "${NIX_BZIP2:0:1}" != "/"; then
+    NIX_BZIP2=`pwd`/${NIX_BZIP2}
 fi
 export dot=@dot@
 export xmllint="@xmllint@"
@@ -42,13 +47,6 @@ export SHELL="@shell@"
 export version=@version@
 export system=@system@
 
-export nixinstantiate=$TOP/src/nix-instantiate/nix-instantiate
-export nixstore=$TOP/src/nix-store/nix-store
-export nixenv=$TOP/src/nix-env/nix-env
-export nixhash=$TOP/src/nix-hash/nix-hash
-export nixworker=$TOP/src/nix-worker/nix-worker
-export nixbuild=$NIX_BIN_DIR/nix-build
-
 readLink() {
     ls -l "$1" | sed 's/.*->\ //'
 }
@@ -65,7 +63,7 @@ clearStore() {
     mkdir "$NIX_STORE_DIR"
     rm -rf "$NIX_DB_DIR"
     mkdir "$NIX_DB_DIR"
-    $nixstore --init
+    nix-store --init
     clearProfiles
     rm -f "$NIX_STATE_DIR"/gcroots/auto/*
     rm -f "$NIX_STATE_DIR"/gcroots/ref
@@ -76,7 +74,14 @@ clearManifests() {
 }
 
 startDaemon() {
-    $nixworker --daemon &
+    # Start the daemon, wait for the socket to appear.  !!!
+    # ‘nix-worker’ should have an option to fork into the background.
+    rm -f $NIX_STATE_DIR/daemon-socket/socket
+    nix-worker --daemon &
+    for ((i = 0; i < 30; i++)); do
+        if [ -e $NIX_STATE_DIR/daemon-socket/socket ]; then break; fi
+        sleep 1
+    done
     pidDaemon=$!
     trap "kill -9 $pidDaemon" EXIT
     export NIX_REMOTE=daemon
diff --git a/tests/dependencies.sh b/tests/dependencies.sh
index 46f60c9bd334..df204d185ddc 100644
--- a/tests/dependencies.sh
+++ b/tests/dependencies.sh
@@ -2,36 +2,36 @@ source common.sh
 
 clearStore
 
-drvPath=$($nixinstantiate dependencies.nix)
+drvPath=$(nix-instantiate dependencies.nix)
 
 echo "derivation is $drvPath"
 
-$nixstore -q --tree "$drvPath" | grep '   +---.*builder1.sh'
+nix-store -q --tree "$drvPath" | grep '   +---.*builder1.sh'
 
 # Test Graphviz graph generation.
-$nixstore -q --graph "$drvPath" > $TEST_ROOT/graph
+nix-store -q --graph "$drvPath" > $TEST_ROOT/graph
 if test -n "$dot"; then
     # Does it parse?
     $dot < $TEST_ROOT/graph
 fi
 
-outPath=$($nixstore -rvv "$drvPath") || fail "build failed"
+outPath=$(nix-store -rvv "$drvPath") || fail "build failed"
 
 # Test Graphviz graph generation.
-$nixstore -q --graph "$outPath" > $TEST_ROOT/graph
+nix-store -q --graph "$outPath" > $TEST_ROOT/graph
 if test -n "$dot"; then
     # Does it parse?
     $dot < $TEST_ROOT/graph
 fi    
 
-$nixstore -q --tree "$outPath" | grep '+---.*dependencies-input-2'
+nix-store -q --tree "$outPath" | grep '+---.*dependencies-input-2'
 
 echo "output path is $outPath"
 
 text=$(cat "$outPath"/foobar)
 if test "$text" != "FOOBAR"; then exit 1; fi
 
-deps=$($nixstore -quR "$drvPath")
+deps=$(nix-store -quR "$drvPath")
 
 echo "output closure contains $deps"
 
@@ -45,8 +45,8 @@ if echo "$deps" | grep -q "dependencies-input-1"; then exit 1; fi
 input2OutPath=$(echo "$deps" | grep "dependencies-input-2")
 
 # The referrers closure of input-2 should include outPath.
-$nixstore -q --referrers-closure "$input2OutPath" | grep "$outPath"
+nix-store -q --referrers-closure "$input2OutPath" | grep "$outPath"
 
 # Check that the derivers are set properly.
-test $($nixstore -q --deriver "$outPath") = "$drvPath"
-$nixstore -q --deriver "$input2OutPath" | grep -q -- "-input-2.drv" 
+test $(nix-store -q --deriver "$outPath") = "$drvPath"
+nix-store -q --deriver "$input2OutPath" | grep -q -- "-input-2.drv" 
diff --git a/tests/export-graph.sh b/tests/export-graph.sh
index 607849a7c8d3..7adbefd120ce 100644
--- a/tests/export-graph.sh
+++ b/tests/export-graph.sh
@@ -4,23 +4,23 @@ clearStore
 clearProfiles
 
 checkRef() {
-    $nixstore -q --references ./result | grep -q "$1" || fail "missing reference $1"
+    nix-store -q --references ./result | grep -q "$1" || fail "missing reference $1"
 }
 
 # Test the export of the runtime dependency graph.
 
-outPath=$($nixbuild ./export-graph.nix -A runtimeGraph)
+outPath=$(nix-build ./export-graph.nix -A runtimeGraph)
 
-test $($nixstore -q --references ./result | wc -l) = 2 || fail "bad nr of references"
+test $(nix-store -q --references ./result | wc -l) = 2 || fail "bad nr of references"
 
 checkRef input-2
 for i in $(cat $outPath); do checkRef $i; done
 
 # Test the export of the build-time dependency graph.
 
-$nixstore --gc # should force rebuild of input-1
+nix-store --gc # should force rebuild of input-1
 
-outPath=$($nixbuild ./export-graph.nix -A buildGraph)
+outPath=$(nix-build ./export-graph.nix -A buildGraph)
 
 checkRef input-1
 checkRef input-1.drv
diff --git a/tests/export.sh b/tests/export.sh
index c7d0a8176720..136819742071 100644
--- a/tests/export.sh
+++ b/tests/export.sh
@@ -2,16 +2,16 @@ source common.sh
 
 clearStore
 
-outPath=$($nixbuild dependencies.nix)
+outPath=$(nix-build dependencies.nix)
 
-$nixstore --export $outPath > $TEST_ROOT/exp
+nix-store --export $outPath > $TEST_ROOT/exp
 
-$nixstore --export $($nixstore -qR $outPath) > $TEST_ROOT/exp_all
+nix-store --export $(nix-store -qR $outPath) > $TEST_ROOT/exp_all
 
 
 clearStore
 
-if $nixstore --import < $TEST_ROOT/exp; then
+if nix-store --import < $TEST_ROOT/exp; then
     echo "importing a non-closure should fail"
     exit 1
 fi
@@ -19,13 +19,13 @@ fi
 
 clearStore
 
-$nixstore --import < $TEST_ROOT/exp_all
+nix-store --import < $TEST_ROOT/exp_all
 
-$nixstore --export $($nixstore -qR $outPath) > $TEST_ROOT/exp_all2
+nix-store --export $(nix-store -qR $outPath) > $TEST_ROOT/exp_all2
 
 
 clearStore
 
 # Regression test: the derivers in exp_all2 are empty, which shouldn't
 # cause a failure.
-$nixstore --import < $TEST_ROOT/exp_all2
+nix-store --import < $TEST_ROOT/exp_all2
diff --git a/tests/fallback.sh b/tests/fallback.sh
index 24889a452881..f3a6b50515bf 100644
--- a/tests/fallback.sh
+++ b/tests/fallback.sh
@@ -2,19 +2,19 @@ source common.sh
 
 clearStore
 
-drvPath=$($nixinstantiate simple.nix)
+drvPath=$(nix-instantiate simple.nix)
 echo "derivation is $drvPath"
 
-outPath=$($nixstore -q --fallback "$drvPath")
+outPath=$(nix-store -q --fallback "$drvPath")
 echo "output path is $outPath"
 
 # 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
+if nix-store -r "$drvPath"; then echo unexpected fallback; exit 1; fi
 
 # Build with a substitute that fails.  This should fall back to a source build.
 export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh
-$nixstore -r --fallback "$drvPath"
+nix-store -r --fallback "$drvPath"
 
 text=$(cat "$outPath"/hello)
 if test "$text" != "Hello World!"; then exit 1; fi
diff --git a/tests/filter-source.sh b/tests/filter-source.sh
index 73f353024513..f7a096ed605d 100644
--- a/tests/filter-source.sh
+++ b/tests/filter-source.sh
@@ -10,7 +10,7 @@ touch $TEST_ROOT/filterin/bak
 touch $TEST_ROOT/filterin/bla.c.bak
 ln -s xyzzy $TEST_ROOT/filterin/link
 
-$NIX_BIN_DIR/nix-build ./filter-source.nix -o $TEST_ROOT/filterout
+nix-build ./filter-source.nix -o $TEST_ROOT/filterout
 
 set -x
 test ! -e $TEST_ROOT/filterout/foo/bar
diff --git a/tests/fixed.sh b/tests/fixed.sh
index 91c122083035..164791564b9a 100644
--- a/tests/fixed.sh
+++ b/tests/fixed.sh
@@ -6,31 +6,31 @@ export IMPURE_VAR1=foo
 export IMPURE_VAR2=bar
 
 echo 'testing good...'
-$nixbuild fixed.nix -A good
+nix-build fixed.nix -A good
 
 echo 'testing good2...'
-$nixbuild fixed.nix -A good2
+nix-build fixed.nix -A good2
 
 echo 'testing bad...'
-$nixbuild fixed.nix -A bad && fail "should fail"
+nix-build fixed.nix -A bad && fail "should fail"
 
 echo 'testing reallyBad...'
-$nixinstantiate fixed.nix -A reallyBad && fail "should fail"
+nix-instantiate fixed.nix -A reallyBad && fail "should fail"
 
 # While we're at it, check attribute selection a bit more.
 echo 'testing attribute selection...'
-test $($nixinstantiate fixed.nix -A good.1 | wc -l) = 1
+test $(nix-instantiate fixed.nix -A good.1 | wc -l) = 1
 
 # Test parallel builds of derivations that produce the same output.
 # Only one should run at the same time.
 echo 'testing parallelSame...'
 clearStore
-$nixbuild fixed.nix -A parallelSame -j2
+nix-build fixed.nix -A parallelSame -j2
 
 # Fixed-output derivations with a recursive SHA-256 hash should
 # produce the same path as "nix-store --add".
 echo 'testing sameAsAdd...'
-out=$($nixbuild fixed.nix -A sameAsAdd)
+out=$(nix-build fixed.nix -A sameAsAdd)
 
 # This is what fixed.builder2 produces...
 rm -rf $TEST_ROOT/fixed
@@ -39,14 +39,14 @@ mkdir $TEST_ROOT/fixed/bla
 echo "Hello World!" > $TEST_ROOT/fixed/foo
 ln -s foo $TEST_ROOT/fixed/bar
 
-out2=$($nixstore --add $TEST_ROOT/fixed)
+out2=$(nix-store --add $TEST_ROOT/fixed)
 echo $out2
 test "$out" = "$out2" || exit 1
 
-out3=$($nixstore --add-fixed --recursive sha256 $TEST_ROOT/fixed)
+out3=$(nix-store --add-fixed --recursive sha256 $TEST_ROOT/fixed)
 echo $out3
 test "$out" = "$out3" || exit 1
 
-out4=$($nixstore --print-fixed-path --recursive sha256 "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik" fixed)
+out4=$(nix-store --print-fixed-path --recursive sha256 "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik" fixed)
 echo $out4
 test "$out" = "$out4" || exit 1
diff --git a/tests/gc-concurrent.sh b/tests/gc-concurrent.sh
index 74251d7cbc08..0bc5a12d318f 100644
--- a/tests/gc-concurrent.sh
+++ b/tests/gc-concurrent.sh
@@ -2,14 +2,14 @@ source common.sh
 
 clearStore
 
-drvPath1=$($nixinstantiate gc-concurrent.nix -A test1)
-outPath1=$($nixstore -q $drvPath1)
+drvPath1=$(nix-instantiate gc-concurrent.nix -A test1)
+outPath1=$(nix-store -q $drvPath1)
 
-drvPath2=$($nixinstantiate gc-concurrent.nix -A test2)
-outPath2=$($nixstore -q $drvPath2)
+drvPath2=$(nix-instantiate gc-concurrent.nix -A test2)
+outPath2=$(nix-store -q $drvPath2)
 
-drvPath3=$($nixinstantiate simple.nix)
-outPath3=$($nixstore -r $drvPath3)
+drvPath3=$(nix-instantiate simple.nix)
+outPath3=$(nix-store -r $drvPath3)
 
 ! test -e $outPath3.lock
 touch $outPath3.lock
@@ -19,16 +19,16 @@ ln -s $drvPath2 "$NIX_STATE_DIR"/gcroots/foo
 ln -s $outPath3 "$NIX_STATE_DIR"/gcroots/foo2
 
 # Start build #1 in the background.  It starts immediately.
-$nixstore -rvv "$drvPath1" &
+nix-store -rvv "$drvPath1" &
 pid1=$!
 
 # Start build #2 in the background after 10 seconds.
-(sleep 10 && $nixstore -rvv "$drvPath2") &
+(sleep 10 && nix-store -rvv "$drvPath2") &
 pid2=$!
 
 # Run the garbage collector while the build is running.
 sleep 6
-$NIX_BIN_DIR/nix-collect-garbage
+nix-collect-garbage
 
 # Wait for build #1/#2 to finish.
 echo waiting for pid $pid1 to finish...
@@ -53,6 +53,6 @@ rm -f "$NIX_STATE_DIR"/gcroots/foo*
 ! test -e $outPath3.lock
 
 # If we run the collector now, it should delete outPath1/2.
-$NIX_BIN_DIR/nix-collect-garbage
+nix-collect-garbage
 ! test -e $outPath1
 ! test -e $outPath2
diff --git a/tests/gc-runtime.sh b/tests/gc-runtime.sh
index 7a50f9f41b71..df662bd0ea90 100644
--- a/tests/gc-runtime.sh
+++ b/tests/gc-runtime.sh
@@ -12,9 +12,9 @@ set -m # enable job control, needed for kill
 profiles="$NIX_STATE_DIR"/profiles
 rm -f $profiles/*
 
-$nixenv -p $profiles/test -f ./gc-runtime.nix -i gc-runtime
+nix-env -p $profiles/test -f ./gc-runtime.nix -i gc-runtime
 
-outPath=$($nixenv -p $profiles/test -q --no-name --out-path gc-runtime)
+outPath=$(nix-env -p $profiles/test -q --no-name --out-path gc-runtime)
 echo $outPath
 
 echo "backgrounding program..."
@@ -23,12 +23,12 @@ sleep 2 # hack - wait for the program to get started
 child=$!
 echo PID=$child
 
-$nixenv -p $profiles/test -e gc-runtime
-$nixenv -p $profiles/test --delete-generations old
+nix-env -p $profiles/test -e gc-runtime
+nix-env -p $profiles/test --delete-generations old
 
 cp $TOP/scripts/find-runtime-roots.pl $TEST_ROOT/foo.pl
 chmod +x $TEST_ROOT/foo.pl
-NIX_ROOT_FINDER=$TEST_ROOT/foo.pl $nixstore --gc
+NIX_ROOT_FINDER=$TEST_ROOT/foo.pl nix-store --gc
 
 kill -- -$child
 
diff --git a/tests/gc.sh b/tests/gc.sh
index e1b3a082046c..a375a35c2eb6 100644
--- a/tests/gc.sh
+++ b/tests/gc.sh
@@ -1,27 +1,27 @@
 source common.sh
 
-drvPath=$($nixinstantiate dependencies.nix)
-outPath=$($nixstore -rvv "$drvPath")
+drvPath=$(nix-instantiate dependencies.nix)
+outPath=$(nix-store -rvv "$drvPath")
 
 # Set a GC root.
 rm -f "$NIX_STATE_DIR"/gcroots/foo
 ln -sf $outPath "$NIX_STATE_DIR"/gcroots/foo
 
-$nixstore --gc --print-roots | grep $outPath
-$nixstore --gc --print-live | grep $outPath
-$nixstore --gc --print-dead | grep $drvPath
-if $nixstore --gc --print-dead | grep $outPath; then false; fi
+nix-store --gc --print-roots | grep $outPath
+nix-store --gc --print-live | grep $outPath
+nix-store --gc --print-dead | grep $drvPath
+if nix-store --gc --print-dead | grep $outPath; then false; fi
 
-$nixstore --gc --print-dead
+nix-store --gc --print-dead
 
 inUse=$(readLink $outPath/input-2)
-if $nixstore --delete $inUse; then false; fi
+if nix-store --delete $inUse; then false; fi
 test -e $inUse
 
-if $nixstore --delete $outPath; then false; fi
+if nix-store --delete $outPath; then false; fi
 test -e $outPath
 
-$NIX_BIN_DIR/nix-collect-garbage
+nix-collect-garbage
 
 # Check that the root and its dependencies haven't been deleted.
 cat $outPath/foobar
@@ -32,7 +32,7 @@ if test -e $drvPath; then false; fi
 
 rm "$NIX_STATE_DIR"/gcroots/foo
 
-$NIX_BIN_DIR/nix-collect-garbage
+nix-collect-garbage
 
 # Check that the output has been GC'd.
 if test -e $outPath/foobar; then false; fi
diff --git a/tests/hash.sh b/tests/hash.sh
index 5022ea246952..de18028eaa0f 100644
--- a/tests/hash.sh
+++ b/tests/hash.sh
@@ -2,7 +2,7 @@ source common.sh
 
 try () {
     printf "%s" "$2" > $TEST_ROOT/vector
-    hash=$($nixhash $EXTRA --flat --type "$1" $TEST_ROOT/vector)
+    hash=$(nix-hash $EXTRA --flat --type "$1" $TEST_ROOT/vector)
     if test "$hash" != "$3"; then
         echo "hash $1, expected $3, got $hash"
         exit 1
@@ -28,7 +28,7 @@ try sha256 "abc" "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s"
 EXTRA=
 
 try2 () {
-    hash=$($nixhash --type "$1" $TEST_ROOT/hash-path)
+    hash=$(nix-hash --type "$1" $TEST_ROOT/hash-path)
     if test "$hash" != "$2"; then
         echo "hash $1, expected $2, got $hash"
         exit 1
@@ -56,7 +56,7 @@ ln -s x $TEST_ROOT/hash-path/hello
 try2 md5 "f78b733a68f5edbdf9413899339eaa4a"
 
 # Conversion.
-test $($nixhash --type sha256 --to-base32 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") = "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s"
-test $($nixhash --type sha256 --to-base16 "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s") = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
-test $($nixhash --type sha1 --to-base32 "800d59cfcd3c05e900cb4e214be48f6b886a08df") = "vw46m23bizj4n8afrc0fj19wrp7mj3c0"
-test $($nixhash --type sha1 --to-base16 "vw46m23bizj4n8afrc0fj19wrp7mj3c0") = "800d59cfcd3c05e900cb4e214be48f6b886a08df"
+test $(nix-hash --type sha256 --to-base32 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") = "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s"
+test $(nix-hash --type sha256 --to-base16 "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s") = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
+test $(nix-hash --type sha1 --to-base32 "800d59cfcd3c05e900cb4e214be48f6b886a08df") = "vw46m23bizj4n8afrc0fj19wrp7mj3c0"
+test $(nix-hash --type sha1 --to-base16 "vw46m23bizj4n8afrc0fj19wrp7mj3c0") = "800d59cfcd3c05e900cb4e214be48f6b886a08df"
diff --git a/tests/init.sh b/tests/init.sh
index 104da432eaef..63e939dff10e 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -18,27 +18,19 @@ mkdir "$NIX_DB_DIR"
 mkdir "$NIX_CONF_DIR"
 
 mkdir $NIX_BIN_DIR
-ln -s $nixstore $NIX_BIN_DIR/
-ln -s $nixinstantiate $NIX_BIN_DIR/
-ln -s $nixhash $NIX_BIN_DIR/
-ln -s $nixenv $NIX_BIN_DIR/
-ln -s $nixworker $NIX_BIN_DIR/
+ln -s $TOP/src/nix-store/nix-store $NIX_BIN_DIR/
+ln -s $TOP/src/nix-instantiate/nix-instantiate $NIX_BIN_DIR/
+ln -s $TOP/src/nix-hash/nix-hash $NIX_BIN_DIR/
+ln -s $TOP/src/nix-env/nix-env $NIX_BIN_DIR/
+ln -s $TOP/src/nix-worker/nix-worker $NIX_BIN_DIR/
 ln -s $TOP/src/bsdiff-*/bsdiff $NIX_BIN_DIR/
 ln -s $TOP/src/bsdiff-*/bspatch $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/
-ln -s $TOP/scripts/nix-install-package $NIX_BIN_DIR/
-ln -s $TOP/scripts/nix-push $NIX_BIN_DIR/
 ln -s $TOP/scripts/nix-pull $NIX_BIN_DIR/
-ln -s $TOP/scripts/nix-generate-patches $NIX_BIN_DIR/
-mkdir $NIX_BIN_DIR/nix
-ln -s $bzip2_bin_test/bzip2 $NIX_BIN_DIR/nix/
-ln -s $bzip2_bin_test/bunzip2 $NIX_BIN_DIR/nix/
-ln -s $TOP/scripts/copy-from-other-stores.pl $NIX_BIN_DIR/nix/
-ln -s $TOP/scripts/download-using-manifests.pl $NIX_BIN_DIR/nix/
-ln -s $TOP/scripts/GeneratePatches.pm $NIX_BIN_DIR/nix/
-ln -s $TOP/scripts/NixManifest.pm $NIX_BIN_DIR/nix/
+mkdir -p $NIX_BIN_DIR/nix/substituters
+ln -s $NIX_BZIP2 $NIX_BIN_DIR/nix/
+ln -s $TOP/scripts/copy-from-other-stores.pl $NIX_BIN_DIR/nix/substituters
 
 cat > "$NIX_CONF_DIR"/nix.conf <<EOF
 gc-keep-outputs = false
@@ -53,17 +45,6 @@ cp -pr $TOP/corepkgs $NIX_DATA_DIR/nix/
 # (and likely to fail).
 for i in \
     $NIX_DATA_DIR/nix/corepkgs/nar/nar.sh \
-    $NIX_BIN_DIR/nix/download-using-manifests.pl \
-    $NIX_BIN_DIR/nix/copy-from-other-stores.pl \
-    $NIX_BIN_DIR/nix-prefetch-url \
-    $NIX_BIN_DIR/nix-collect-garbage \
-    $NIX_BIN_DIR/nix-build \
-    $NIX_BIN_DIR/nix-install-package \
-    $NIX_BIN_DIR/nix-push \
-    $NIX_BIN_DIR/nix-pull \
-    $NIX_BIN_DIR/nix-generate-patches \
-    $NIX_BIN_DIR/nix/NixManifest.pm \
-    $NIX_BIN_DIR/nix/GeneratePatches.pm \
     ; do
     sed < $i > $i.tmp \
         -e "s^$REAL_BIN_DIR/nix-store^$NIX_BIN_DIR/nix-store^" \
@@ -87,20 +68,15 @@ mv tmp $NIX_DATA_DIR/nix/corepkgs/nar/nar.sh
 # binaries sets DYLD_LIBRARY_PATH so that Perl finds Nix's (completely
 # different) libutil --- so it barfs.  So generate a shell wrapper
 # around download-using-manifests that clears DYLD_LIBRARY_PATH.
-mv $NIX_BIN_DIR/nix/download-using-manifests.pl $NIX_BIN_DIR/nix/download-using-manifests.pl.real
-cat > $NIX_BIN_DIR/nix/download-using-manifests.pl <<EOF
+cat > $NIX_BIN_DIR/nix/substituters/download-using-manifests.pl <<EOF
 #! $SHELL -e
 export DYLD_LIBRARY_PATH=
-exec $NIX_BIN_DIR/nix/download-using-manifests.pl.real "\$@"
+exec $TOP/scripts/download-using-manifests.pl "\$@"
 EOF
-chmod +x $NIX_BIN_DIR/nix/download-using-manifests.pl
-
-mkdir -p $NIX_BIN_DIR/nix/substituters
-mv $NIX_BIN_DIR/nix/copy-from-other-stores.pl $NIX_BIN_DIR/nix/substituters/copy-from-other-stores.pl
-mv $NIX_BIN_DIR/nix/download-using-manifests.pl $NIX_BIN_DIR/nix/substituters/download-using-manifests.pl
+chmod +x $NIX_BIN_DIR/nix/substituters/download-using-manifests.pl
 
 # Initialise the database.
-$nixstore --init
+nix-store --init
 
 # Did anything happen?
 test -e "$NIX_DB_DIR"/db.sqlite
diff --git a/tests/install-package.sh b/tests/install-package.sh
index 89d1d71f3286..b818eda121cf 100644
--- a/tests/install-package.sh
+++ b/tests/install-package.sh
@@ -2,8 +2,8 @@ source common.sh
 
 # Note: this test expects to be run *after* nix-push.sh.
 
-drvPath=$($nixinstantiate ./dependencies.nix)
-outPath=$($nixstore -q $drvPath)
+drvPath=$(nix-instantiate ./dependencies.nix)
+outPath=$(nix-store -q $drvPath)
 
 clearStore
 clearProfiles
@@ -12,10 +12,10 @@ cat > $TEST_ROOT/foo.nixpkg <<EOF
 NIXPKG1 file://$TEST_ROOT/manifest simple $system $drvPath $outPath
 EOF
 
-$NIX_BIN_DIR/nix-install-package --non-interactive -p $profiles/test $TEST_ROOT/foo.nixpkg
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
+nix-install-package --non-interactive -p $profiles/test $TEST_ROOT/foo.nixpkg
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1
 
 clearProfiles
 
-$NIX_BIN_DIR/nix-install-package --non-interactive -p $profiles/test --url file://$TEST_ROOT/foo.nixpkg
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
+nix-install-package --non-interactive -p $profiles/test --url file://$TEST_ROOT/foo.nixpkg
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1
diff --git a/tests/lang.sh b/tests/lang.sh
index 11267a23fd19..c9fc65e6ac37 100644
--- a/tests/lang.sh
+++ b/tests/lang.sh
@@ -7,7 +7,7 @@ fail=0
 for i in lang/parse-fail-*.nix; do
     echo "parsing $i (should fail)";
     i=$(basename $i .nix)
-    if $nixinstantiate --parse-only - < lang/$i.nix; then
+    if nix-instantiate --parse-only - < lang/$i.nix; then
         echo "FAIL: $i shouldn't parse"
         fail=1
     fi
@@ -16,7 +16,7 @@ done
 for i in lang/parse-okay-*.nix; do
     echo "parsing $i (should succeed)";
     i=$(basename $i .nix)
-    if ! $nixinstantiate --parse-only - < lang/$i.nix > lang/$i.out; then
+    if ! nix-instantiate --parse-only - < lang/$i.nix > lang/$i.out; then
         echo "FAIL: $i should parse"
         fail=1
     fi
@@ -25,7 +25,7 @@ done
 for i in lang/eval-fail-*.nix; do
     echo "evaluating $i (should fail)";
     i=$(basename $i .nix)
-    if $nixinstantiate --eval-only lang/$i.nix; then
+    if nix-instantiate --eval-only lang/$i.nix; then
         echo "FAIL: $i shouldn't evaluate"
         fail=1
     fi
@@ -40,7 +40,7 @@ for i in lang/eval-okay-*.nix; do
         if test -e lang/$i.flags; then
             flags=$(cat lang/$i.flags)
         fi
-        if ! NIX_PATH=lang/dir3:lang/dir4 $nixinstantiate $flags --eval-only --strict lang/$i.nix > lang/$i.out; then
+        if ! NIX_PATH=lang/dir3:lang/dir4 nix-instantiate $flags --eval-only --strict lang/$i.nix > lang/$i.out; then
             echo "FAIL: $i should evaluate"
             fail=1
         elif ! diff lang/$i.out lang/$i.exp; then
@@ -50,7 +50,7 @@ for i in lang/eval-okay-*.nix; do
     fi
     
     if test -e lang/$i.exp.xml; then
-        if ! $nixinstantiate --eval-only --xml --no-location --strict \
+        if ! nix-instantiate --eval-only --xml --no-location --strict \
                 lang/$i.nix > lang/$i.out.xml; then
             echo "FAIL: $i should evaluate"
             fail=1
diff --git a/tests/logging.sh b/tests/logging.sh
index dffedcfe59ca..8cedb470656b 100644
--- a/tests/logging.sh
+++ b/tests/logging.sh
@@ -4,7 +4,7 @@ clearStore
 
 # Produce an escaped log file.
 set -x
-$nixbuild --log-type escapes -vv dependencies.nix 2> $TEST_ROOT/log.esc
+nix-build --log-type escapes -vv dependencies.nix 2> $TEST_ROOT/log.esc
 
 # Convert it to an XML representation.
 $TOP/src/nix-log2xml/nix-log2xml < $TEST_ROOT/log.esc > $TEST_ROOT/log.xml
diff --git a/tests/misc.sh b/tests/misc.sh
index 9be2ac2f041c..5d88aae63ee4 100644
--- a/tests/misc.sh
+++ b/tests/misc.sh
@@ -3,14 +3,14 @@ source common.sh
 # Tests miscellaneous commands.
 
 # Do all commands have help?
-$nixenv --help | grep -q install
-$nixstore --help | grep -q realise
-$nixinstantiate --help | grep -q eval-only
-$nixhash --help | grep -q base32
+nix-env --help | grep -q install
+nix-store --help | grep -q realise
+nix-instantiate --help | grep -q eval-only
+nix-hash --help | grep -q base32
 
 # Can we ask for the version number?
-$nixenv --version | grep "$version"
+nix-env --version | grep "$version"
 
 # Usage errors.
-$nixenv --foo 2>&1 | grep "no operation"
-$nixenv -q --foo 2>&1 | grep "unknown flag"
+nix-env --foo 2>&1 | grep "no operation"
+nix-env -q --foo 2>&1 | grep "unknown flag"
diff --git a/tests/negative-caching.sh b/tests/negative-caching.sh
index e618e9443ef2..7cbab00e4f9b 100644
--- a/tests/negative-caching.sh
+++ b/tests/negative-caching.sh
@@ -7,16 +7,16 @@ set +e
 opts="--option build-cache-failure true --print-build-trace"
 
 # This build should fail, and the failure should be cached.
-log=$($nixbuild $opts negative-caching.nix -A fail 2>&1) && fail "should fail"
+log=$(nix-build $opts negative-caching.nix -A fail 2>&1) && fail "should fail"
 echo "$log" | grep -q "@ build-failed" || fail "no build-failed trace"
 
 # Do it again.  The build shouldn't be tried again.
-log=$($nixbuild $opts negative-caching.nix -A fail 2>&1) && fail "should fail"
+log=$(nix-build $opts negative-caching.nix -A fail 2>&1) && fail "should fail"
 echo "$log" | grep -q "FAIL" && fail "failed build not cached"
 echo "$log" | grep -q "@ build-failed .* cached" || fail "trace doesn't say cached"
 
 # Check that --keep-going works properly with cached failures.
-log=$($nixbuild $opts --keep-going negative-caching.nix -A depOnFail 2>&1) && fail "should fail"
+log=$(nix-build $opts --keep-going negative-caching.nix -A depOnFail 2>&1) && fail "should fail"
 echo "$log" | grep -q "FAIL" && fail "failed build not cached (2)"
 echo "$log" | grep -q "@ build-failed .* cached" || fail "trace doesn't say cached (2)"
 echo "$log" | grep -q "@ build-succeeded .*-succeed" || fail "didn't keep going"
diff --git a/tests/nix-build.sh b/tests/nix-build.sh
index aab3615cc51b..d575e9aae9f0 100644
--- a/tests/nix-build.sh
+++ b/tests/nix-build.sh
@@ -2,7 +2,7 @@ source common.sh
 
 clearStore
 
-(cd $TEST_ROOT && $nixbuild ../dependencies.nix)
+(cd $TEST_ROOT && nix-build ../dependencies.nix)
 test "$(cat $TEST_ROOT/result/foobar)" = FOOBAR
 
 # The result should be retained by a GC.
@@ -10,10 +10,10 @@ echo A
 target=$(readLink $TEST_ROOT/result)
 echo B
 echo target is $target
-$nixstore --gc
+nix-store --gc
 test -e $target/foobar
 
 # But now it should be gone.
 rm $TEST_ROOT/result
-$nixstore --gc
+nix-store --gc
 if test -e $target/foobar; then false; fi
diff --git a/tests/nix-copy-closure.nix b/tests/nix-copy-closure.nix
new file mode 100644
index 000000000000..7e2cf3a08870
--- /dev/null
+++ b/tests/nix-copy-closure.nix
@@ -0,0 +1,54 @@
+# Test ‘nix-copy-closure’.
+
+{ nixpkgs, nixos, system, nix }:
+
+with import "${nixos}/lib/testing.nix" { inherit nixpkgs system; };
+
+makeTest ({ pkgs, ... }: let pkgA = pkgs.aterm; pkgB = pkgs.wget; in {
+
+  nodes =
+    { client =
+        { config, pkgs, ... }:
+        { virtualisation.writableStore = true;
+          virtualisation.pathsInNixDB = [ pkgA ];
+          environment.nix = nix;
+        };
+        
+      server =
+        { config, pkgs, ... }:
+        { services.openssh.enable = true;
+          virtualisation.writableStore = true;
+          virtualisation.pathsInNixDB = [ pkgB ];
+          environment.nix = nix;
+        };        
+    };
+
+  testScript = { nodes }:
+    ''
+      startAll;
+
+      # Create an SSH key on the client.
+      my $key = `${pkgs.openssh}/bin/ssh-keygen -t dsa -f key -N ""`;
+      $client->succeed("mkdir -m 700 /root/.ssh");
+      $client->copyFileFromHost("key", "/root/.ssh/id_dsa");
+      $client->succeed("chmod 600 /root/.ssh/id_dsa");
+
+      # Install the SSH key on the server.
+      $server->succeed("mkdir -m 700 /root/.ssh");
+      $server->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys");
+      $server->waitForJob("sshd");
+      $client->waitForJob("network-interfaces");
+      $client->succeed("ssh -o StrictHostKeyChecking=no " . $server->name() . " 'echo hello world'");
+
+      # Copy the closure of package A from the client to the server.
+      $server->fail("nix-store --check-validity ${pkgA}");
+      $client->succeed("nix-copy-closure --to server --gzip ${pkgA} >&2");
+      $server->succeed("nix-store --check-validity ${pkgA}");
+
+      # Copy the closure of package B from the server to the client.
+      $client->fail("nix-store --check-validity ${pkgB}");
+      $client->succeed("nix-copy-closure --from server --gzip ${pkgB} >&2");
+      $client->succeed("nix-store --check-validity ${pkgB}");
+    '';
+
+})
diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh
index d2309742d217..9a89676cb99f 100644
--- a/tests/nix-pull.sh
+++ b/tests/nix-pull.sh
@@ -2,18 +2,18 @@ source common.sh
 
 pullCache () {
     echo "pulling cache..."
-    $NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest
+    nix-pull file://$TEST_ROOT/manifest
 }
 
 clearStore
 clearManifests
 pullCache
 
-drvPath=$($nixinstantiate dependencies.nix)
-outPath=$($nixstore -q $drvPath)
+drvPath=$(nix-instantiate dependencies.nix)
+outPath=$(nix-store -q $drvPath)
 
 echo "building $outPath using substitutes..."
-$nixstore -r $outPath
+nix-store -r $outPath
 
 cat $outPath/input-2/bar
 
@@ -22,12 +22,12 @@ clearManifests
 pullCache
 
 echo "building $drvPath using substitutes..."
-$nixstore -r $drvPath
+nix-store -r $drvPath
 
 cat $outPath/input-2/bar
 
 # Check that the derivers are set properly.
-test $($nixstore -q --deriver "$outPath") = "$drvPath"
-$nixstore -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" 
+test $(nix-store -q --deriver "$outPath") = "$drvPath"
+nix-store -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" 
 
 clearManifests
diff --git a/tests/nix-push.sh b/tests/nix-push.sh
index 0a35e3b97ab7..69f05141af69 100644
--- a/tests/nix-push.sh
+++ b/tests/nix-push.sh
@@ -1,11 +1,10 @@
 source common.sh
 
-drvPath=$($nixinstantiate dependencies.nix)
-outPath=$($nixstore -r $drvPath)
+drvPath=$(nix-instantiate dependencies.nix)
+outPath=$(nix-store -r $drvPath)
 
 echo "pushing $drvPath"
 
 mkdir -p $TEST_ROOT/cache
 
-$NIX_BIN_DIR/nix-push \
-    --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath
+nix-push --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath
diff --git a/tests/parallel.sh b/tests/parallel.sh
index 565c6f735ab2..13349e875f11 100644
--- a/tests/parallel.sh
+++ b/tests/parallel.sh
@@ -8,7 +8,7 @@ clearStore
 
 rm -f $SHARED.cur $SHARED.max
 
-outPath=$($nixbuild -j10000 parallel.nix)
+outPath=$(nix-build -j10000 parallel.nix)
 
 echo "output path is $outPath"
 
@@ -27,9 +27,9 @@ clearStore
 
 rm -f $SHARED.cur $SHARED.max
 
-drvPath=$($nixinstantiate parallel.nix --argstr sleepTime 15)
+drvPath=$(nix-instantiate parallel.nix --argstr sleepTime 15)
 
-cmd="$nixstore -j1 -r $drvPath"
+cmd="nix-store -j1 -r $drvPath"
 
 $cmd &
 pid1=$!
diff --git a/tests/referrers.sh b/tests/referrers.sh
index a0c195d5ab6c..d4604aec930b 100644
--- a/tests/referrers.sh
+++ b/tests/referrers.sh
@@ -6,7 +6,7 @@ max=500
 
 reference=$NIX_STORE_DIR/abcdef
 touch $reference
-(echo $reference && echo && echo 0) | $nixstore --register-validity 
+(echo $reference && echo && echo 0) | nix-store --register-validity 
 
 echo "making registration..."
 
@@ -22,11 +22,11 @@ done > $TEST_ROOT/reg_info
 
 echo "registering..."
 
-$nixstore --register-validity < $TEST_ROOT/reg_info
+nix-store --register-validity < $TEST_ROOT/reg_info
 
 echo "collecting garbage..."
 ln -sfn $reference "$NIX_STATE_DIR"/gcroots/ref
-$nixstore --gc
+nix-store --gc
 
 if test "$(sqlite3 ./test-tmp/db/db.sqlite 'select count(*) from Refs')" -ne 0; then
     echo "referrers not cleaned up"
diff --git a/tests/remote-builds.nix b/tests/remote-builds.nix
new file mode 100644
index 000000000000..201ca9dba19b
--- /dev/null
+++ b/tests/remote-builds.nix
@@ -0,0 +1,97 @@
+# Test Nix's remote build feature.
+
+{ nixpkgs, nixos, system, nix }:
+
+with import "${nixos}/lib/testing.nix" { inherit nixpkgs system; };
+
+makeTest ({ pkgs, ... }:
+
+let
+
+  # The configuration of the build slaves.
+  slave =
+    { config, pkgs, ... }:
+    { services.openssh.enable = true;
+      virtualisation.writableStore = true;
+      environment.nix = nix;
+    };
+
+  # Trivial Nix expression to build remotely.
+  expr = config: nr: pkgs.writeText "expr.nix"
+    ''
+      let utils = builtins.storePath ${config.system.build.extraUtils}; in
+      derivation {
+        name = "hello-${toString nr}";
+        system = "i686-linux";
+        PATH = "''${utils}/bin";
+        builder = "''${utils}/bin/sh";
+        args = [ "-c" "echo Hello; mkdir $out; cat /proc/sys/kernel/hostname > $out/host; sleep 3" ];
+      }
+    '';
+
+in
+
+{
+
+  nodes =
+    { slave1 = slave;
+      slave2 = slave;
+
+      client =
+        { config, pkgs, ... }:
+        { nix.maxJobs = 0; # force remote building
+          nix.distributedBuilds = true;
+          nix.buildMachines =
+            [ { hostName = "slave1";
+                sshUser = "root";
+                sshKey = "/root/.ssh/id_dsa";
+                system = "i686-linux";
+                maxJobs = 1;
+              }
+              { hostName = "slave2";
+                sshUser = "root";
+                sshKey = "/root/.ssh/id_dsa";
+                system = "i686-linux";
+                maxJobs = 1;
+              }
+            ];
+          virtualisation.writableStore = true;
+          virtualisation.pathsInNixDB = [ config.system.build.extraUtils ];
+          environment.nix = nix;
+        };
+    };
+
+  testScript = { nodes }:
+    ''
+      startAll;
+
+      # Create an SSH key on the client.
+      my $key = `${pkgs.openssh}/bin/ssh-keygen -t dsa -f key -N ""`;
+      $client->succeed("mkdir -m 700 /root/.ssh");
+      $client->copyFileFromHost("key", "/root/.ssh/id_dsa");
+      $client->succeed("chmod 600 /root/.ssh/id_dsa");
+
+      # Install the SSH key on the slaves.
+      foreach my $slave ($slave1, $slave2) {
+          $slave->succeed("mkdir -m 700 /root/.ssh");
+          $slave->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys");
+          $slave->waitForJob("sshd");
+          $client->succeed("ssh -o StrictHostKeyChecking=no " . $slave->name() . " 'echo hello world'");
+      }
+
+      # Perform a build and check that it was performed on the slave.
+      my $out = $client->succeed("nix-build ${expr nodes.client.config 1}");
+      $slave1->succeed("test -e $out");
+
+      # And a parallel build.
+      my ($out1, $out2) = split /\s/,
+          $client->succeed("nix-store -r \$(nix-instantiate ${expr nodes.client.config 2} ${expr nodes.client.config 3})");
+      $slave1->succeed("test -e $out1 -o -e $out2");
+      $slave2->succeed("test -e $out1 -o -e $out2");
+
+      # Test whether the build hook automatically skips unavailable slaves.
+      $slave1->block;
+      $client->succeed("nix-build ${expr nodes.client.config 4}");
+    '';
+
+})
diff --git a/tests/secure-drv-outputs.sh b/tests/secure-drv-outputs.sh
index 25dd6bfc01fe..3cb889996763 100644
--- a/tests/secure-drv-outputs.sh
+++ b/tests/secure-drv-outputs.sh
@@ -10,11 +10,11 @@ clearManifests
 startDaemon
 
 # Determine the output path of the "good" derivation.
-goodOut=$($nixstore -q $($nixinstantiate ./secure-drv-outputs.nix -A good))
+goodOut=$(nix-store -q $(nix-instantiate ./secure-drv-outputs.nix -A good))
 
 # Instantiate the "bad" derivation.
-badDrv=$($nixinstantiate ./secure-drv-outputs.nix -A bad)
-badOut=$($nixstore -q $badDrv)
+badDrv=$(nix-instantiate ./secure-drv-outputs.nix -A bad)
+badOut=$(nix-store -q $badDrv)
 
 # Rewrite the bad derivation to produce the output path of the good
 # derivation.
@@ -23,12 +23,12 @@ sed -e "s|$badOut|$goodOut|g" < $badDrv > $TEST_ROOT/bad.drv
 
 # Add the manipulated derivation to the store and build it.  This
 # should fail.
-if badDrv2=$($nixstore --add $TEST_ROOT/bad.drv); then
-    $nixstore -r "$badDrv2"
+if badDrv2=$(nix-store --add $TEST_ROOT/bad.drv); then
+    nix-store -r "$badDrv2"
 fi
 
 # Now build the good derivation.
-goodOut2=$($nixbuild ./secure-drv-outputs.nix -A good)
+goodOut2=$(nix-build ./secure-drv-outputs.nix -A good)
 test "$goodOut" = "$goodOut2"
 
 if ! test -e "$goodOut"/good; then
diff --git a/tests/simple.sh b/tests/simple.sh
index 4f9f6e964acd..af8bccc2b457 100644
--- a/tests/simple.sh
+++ b/tests/simple.sh
@@ -1,12 +1,12 @@
 source common.sh
 
-drvPath=$($nixinstantiate simple.nix)
+drvPath=$(nix-instantiate simple.nix)
 
-test "$($nixstore -q --binding system "$drvPath")" = "$system"
+test "$(nix-store -q --binding system "$drvPath")" = "$system"
 
 echo "derivation is $drvPath"
 
-outPath=$($nixstore -rvv "$drvPath")
+outPath=$(nix-store -rvv "$drvPath")
 
 echo "output path is $outPath"
 
@@ -15,10 +15,10 @@ if test "$text" != "Hello World!"; then exit 1; fi
 
 # Directed delete: $outPath is not reachable from a root, so it should
 # be deleteable.
-$nixstore --delete $outPath
+nix-store --delete $outPath
 if test -e $outPath/hello; then false; fi
 
-outPath="$(NIX_STORE_DIR=/foo $nixinstantiate --readonly-mode hash-check.nix)"
+outPath="$(NIX_STORE_DIR=/foo nix-instantiate --readonly-mode hash-check.nix)"
 if test "$outPath" != "/foo/lfy1s6ca46rm5r6w4gg9hc0axiakjcnm-dependencies.drv"; then
     echo "hashDerivationModulo appears broken, got $outPath"
     exit 1
diff --git a/tests/substitutes.sh b/tests/substitutes.sh
index b48576c8c302..0c6adf2601fa 100644
--- a/tests/substitutes.sh
+++ b/tests/substitutes.sh
@@ -3,20 +3,20 @@ source common.sh
 clearStore
 
 # Instantiate.
-drvPath=$($nixinstantiate simple.nix)
+drvPath=$(nix-instantiate simple.nix)
 echo "derivation is $drvPath"
 
 # Find the output path.
-outPath=$($nixstore -qvv "$drvPath")
+outPath=$(nix-store -qvv "$drvPath")
 echo "output path is $outPath"
 
 echo $outPath > $TEST_ROOT/sub-paths
 
 export NIX_SUBSTITUTERS=$(pwd)/substituter.sh
 
-$nixstore -r "$drvPath" --dry-run 2>&1 | grep -q "1.00 MiB.*2.00 MiB"
+nix-store -r "$drvPath" --dry-run 2>&1 | grep -q "1.00 MiB.*2.00 MiB"
 
-$nixstore -rvv "$drvPath"
+nix-store -rvv "$drvPath"
 
 text=$(cat "$outPath"/hello)
 if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi
diff --git a/tests/substitutes2.sh b/tests/substitutes2.sh
index ad0bfcc2687e..bd914575cca8 100644
--- a/tests/substitutes2.sh
+++ b/tests/substitutes2.sh
@@ -3,11 +3,11 @@ source common.sh
 clearStore
 
 # Instantiate.
-drvPath=$($nixinstantiate simple.nix)
+drvPath=$(nix-instantiate simple.nix)
 echo "derivation is $drvPath"
 
 # Find the output path.
-outPath=$($nixstore -qvvvvv "$drvPath")
+outPath=$(nix-store -qvvvvv "$drvPath")
 echo "output path is $outPath"
 
 echo $outPath > $TEST_ROOT/sub-paths
@@ -15,7 +15,7 @@ echo $outPath > $TEST_ROOT/sub-paths
 # First try a substituter that fails, then one that succeeds
 export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh:$(pwd)/substituter.sh
 
-$nixstore -j0 -rvv "$drvPath"
+nix-store -j0 -rvv "$drvPath"
 
 text=$(cat "$outPath"/hello)
 if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi
diff --git a/tests/timeout.sh b/tests/timeout.sh
index f27739fb2b52..2101d13a7894 100644
--- a/tests/timeout.sh
+++ b/tests/timeout.sh
@@ -2,14 +2,14 @@
 
 source common.sh
 
-drvPath=$($nixinstantiate timeout.nix)
+drvPath=$(nix-instantiate timeout.nix)
 
-test "$($nixstore -q --binding system "$drvPath")" = "$system"
+test "$(nix-store -q --binding system "$drvPath")" = "$system"
 
 echo "derivation is $drvPath"
 
 failed=0
-messages="`$nixstore -r --timeout 2 $drvPath 2>&1 || failed=1`"
+messages="`nix-store -r --timeout 2 $drvPath 2>&1 || failed=1`"
 if test $failed -ne 0; then
     echo "error: \`nix-store' succeeded; should have timed out" >&2
     exit 1
diff --git a/tests/user-envs.sh b/tests/user-envs.sh
index 647223ef8c4f..025a5ff81716 100644
--- a/tests/user-envs.sh
+++ b/tests/user-envs.sh
@@ -5,110 +5,110 @@ clearProfiles
 set -x
 
 # Query installed: should be empty.
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0
 
 # Query available: should contain several.
-test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5
+test "$(nix-env -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5
 
 # Query descriptions.
-$nixenv -p $profiles/test -f ./user-envs.nix -qa '*' --description | grep silly
+nix-env -p $profiles/test -f ./user-envs.nix -qa '*' --description | grep silly
 
 # Install "foo-1.0".
-$nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0
+nix-env -p $profiles/test -f ./user-envs.nix -i foo-1.0
 
 # Query installed: should contain foo-1.0 now (which should be
 # executable).
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
-$nixenv -p $profiles/test -q '*' | grep -q foo-1.0
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1
+nix-env -p $profiles/test -q '*' | grep -q foo-1.0
 test "$($profiles/test/bin/foo)" = "foo-1.0"
 
 # Store the path of foo-1.0.
-outPath10=$($nixenv -p $profiles/test -q --out-path --no-name '*' | grep foo-1.0)
+outPath10=$(nix-env -p $profiles/test -q --out-path --no-name '*' | grep foo-1.0)
 echo "foo-1.0 = $outPath10"
 test -n "$outPath10"
 
 # Install "foo-2.0pre1": should remove foo-1.0.
-$nixenv -p $profiles/test -f ./user-envs.nix -i foo-2.0pre1
+nix-env -p $profiles/test -f ./user-envs.nix -i foo-2.0pre1
 
 # Query installed: should contain foo-2.0pre1 now.
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
-$nixenv -p $profiles/test -q '*' | grep -q foo-2.0pre1
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1
+nix-env -p $profiles/test -q '*' | grep -q foo-2.0pre1
 test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
 
 # Upgrade "foo": should install foo-2.0.
-$nixenv -p $profiles/test -f ./user-envs.nix -u foo
+nix-env -p $profiles/test -f ./user-envs.nix -u foo
 
 # Query installed: should contain foo-2.0 now.
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
-$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 1
+nix-env -p $profiles/test -q '*' | grep -q foo-2.0
 test "$($profiles/test/bin/foo)" = "foo-2.0"
 
 # Store the path of foo-2.0.
-outPath20=$($nixenv -p $profiles/test -q --out-path --no-name '*' | grep foo-2.0)
+outPath20=$(nix-env -p $profiles/test -q --out-path --no-name '*' | grep foo-2.0)
 test -n "$outPath20"
 
 # Install bar-0.1, uninstall foo.
-$nixenv -p $profiles/test -f ./user-envs.nix -i bar-0.1
-$nixenv -p $profiles/test -f ./user-envs.nix -e foo
+nix-env -p $profiles/test -f ./user-envs.nix -i bar-0.1
+nix-env -p $profiles/test -f ./user-envs.nix -e foo
 
 # Query installed: should only contain bar-0.1 now.
-if $nixenv -p $profiles/test -q '*' | grep -q foo; then false; fi
-$nixenv -p $profiles/test -q '*' | grep -q bar
+if nix-env -p $profiles/test -q '*' | grep -q foo; then false; fi
+nix-env -p $profiles/test -q '*' | grep -q bar
 
 # Rollback: should bring "foo" back.
-$nixenv -p $profiles/test --rollback
-$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
-$nixenv -p $profiles/test -q '*' | grep -q bar
+nix-env -p $profiles/test --rollback
+nix-env -p $profiles/test -q '*' | grep -q foo-2.0
+nix-env -p $profiles/test -q '*' | grep -q bar
 
 # Rollback again: should remove "bar".
-$nixenv -p $profiles/test --rollback
-$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
-if $nixenv -p $profiles/test -q '*' | grep -q bar; then false; fi
+nix-env -p $profiles/test --rollback
+nix-env -p $profiles/test -q '*' | grep -q foo-2.0
+if nix-env -p $profiles/test -q '*' | grep -q bar; then false; fi
 
 # Count generations.
-$nixenv -p $profiles/test --list-generations
-test "$($nixenv -p $profiles/test --list-generations | wc -l)" -eq 5
+nix-env -p $profiles/test --list-generations
+test "$(nix-env -p $profiles/test --list-generations | wc -l)" -eq 5
 
 # Install foo-1.0, now using its store path.
 echo $outPath10
-$nixenv -p $profiles/test -i "$outPath10"
-$nixenv -p $profiles/test -q '*' | grep -q foo-1.0
+nix-env -p $profiles/test -i "$outPath10"
+nix-env -p $profiles/test -q '*' | grep -q foo-1.0
 
 # Uninstall foo-1.0, using a symlink to its store path.
 ln -sfn $outPath10/bin/foo $TEST_ROOT/symlink
-$nixenv -p $profiles/test -e $TEST_ROOT/symlink
-if $nixenv -p $profiles/test -q '*' | grep -q foo; then false; fi
+nix-env -p $profiles/test -e $TEST_ROOT/symlink
+if nix-env -p $profiles/test -q '*' | grep -q foo; then false; fi
 
 # Install foo-1.0, now using a symlink to its store path.
-$nixenv -p $profiles/test -i $TEST_ROOT/symlink
-$nixenv -p $profiles/test -q '*' | grep -q foo
+nix-env -p $profiles/test -i $TEST_ROOT/symlink
+nix-env -p $profiles/test -q '*' | grep -q foo
 
 # Delete all old generations.
-$nixenv -p $profiles/test --delete-generations old
+nix-env -p $profiles/test --delete-generations old
 
 # Run the garbage collector.  This should get rid of foo-2.0 but not
 # foo-1.0.
-$NIX_BIN_DIR/nix-collect-garbage
+nix-collect-garbage
 test -e "$outPath10"
 if test -e "$outPath20"; then false; fi
 
 # Uninstall everything
-$nixenv -p $profiles/test -f ./user-envs.nix -e '*'
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0
+nix-env -p $profiles/test -f ./user-envs.nix -e '*'
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0
 
 # Installing "foo" should only install the newest foo.
-$nixenv -p $profiles/test -f ./user-envs.nix -i foo
-test "$($nixenv -p $profiles/test -q '*' | grep foo- | wc -l)" -eq 1
-$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
+nix-env -p $profiles/test -f ./user-envs.nix -i foo
+test "$(nix-env -p $profiles/test -q '*' | grep foo- | wc -l)" -eq 1
+nix-env -p $profiles/test -q '*' | grep -q foo-2.0
 
 # On the other hand, this should install both (and should fail due to
 # a collision).
-$nixenv -p $profiles/test -f ./user-envs.nix -e '*'
-if $nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0 foo-2.0; then false; fi
+nix-env -p $profiles/test -f ./user-envs.nix -e '*'
+if nix-env -p $profiles/test -f ./user-envs.nix -i foo-1.0 foo-2.0; then false; fi
 
 # Installing "*" should install one foo and one bar.
-$nixenv -p $profiles/test -f ./user-envs.nix -e '*'
-$nixenv -p $profiles/test -f ./user-envs.nix -i '*'
-test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 2
-$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
-$nixenv -p $profiles/test -q '*' | grep -q bar-0.1.1
+nix-env -p $profiles/test -f ./user-envs.nix -e '*'
+nix-env -p $profiles/test -f ./user-envs.nix -i '*'
+test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 2
+nix-env -p $profiles/test -q '*' | grep -q foo-2.0
+nix-env -p $profiles/test -q '*' | grep -q bar-0.1.1
diff --git a/tests/verify.sh b/tests/verify.sh
index 39609c7cecf6..e0d68e849d09 100644
--- a/tests/verify.sh
+++ b/tests/verify.sh
@@ -1,3 +1,3 @@
 source common.sh
 
-$nixstore --verify
+nix-store --verify