From 82ce465751df40ce7f68d41dc9c196dfcade620d Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Mon, 13 Nov 2006 19:01:39 +0000
Subject: [PATCH] * Use `exportReferencesGraph' to register the references of
 the   initial Nix installation correctly.

svn path=/nixu/trunk/; revision=7021
---
 test/installer.nix | 15 ++++++++++-----
 test/installer.sh  | 21 ++++++++++++++-------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/test/installer.nix b/test/installer.nix
index 4b3ec85939ca..2f8963a443b2 100644
--- a/test/installer.nix
+++ b/test/installer.nix
@@ -6,12 +6,17 @@ genericSubstituter {
   dir = "bin";
   isExecutable = true;
   inherit shell nix;
-  
+
   nixClosure = stdenv.mkDerivation {
     name = "closure";
-    builder = builtins.toFile "builder.sh"
-      "source $stdenv/setup; nix-store -qR $nix > $out";
-    buildInputs = [nix];
-    inherit nix;
+    exportReferencesGraph = ["refs" nix];
+    builder = builtins.toFile "builder.sh" "
+      source $stdenv/setup
+      if ! test -e refs; then
+        echo 'Your Nix installation is too old!'
+        exit 1
+      fi
+      cp refs $out
+    ";
   };
 }
diff --git a/test/installer.sh b/test/installer.sh
index c5dcecf20645..4abad8e38409 100644
--- a/test/installer.sh
+++ b/test/installer.sh
@@ -73,9 +73,21 @@ mkdir -m 0755 -p \
     $mountPoint/nix/var/log/nix/drvs
 
 
+# Get the store paths to copy from the references graph.
+storePaths=""
+while read storePath; do
+    storePaths="$storePaths $storePath"
+    read deriver
+    read count
+    for ((i = 0; i < $count; i++)); do
+        read ref
+    done
+done < @nixClosure@
+
+
 # Copy Nix to the Nix store on the target device.
 echo "copying Nix to $targetDevice...."
-for i in $(cat @nixClosure@); do
+for i in $storePaths; do
     echo "  $i"
     rsync -a $i $mountPoint/nix/store/
 done
@@ -86,12 +98,7 @@ done
 # something.  (I.e., Nix will see that, e.g., the glibc path is not
 # valid, delete it to get it out of the way, but as a result nothing
 # will work anymore.)
-for i in $(cat @nixClosure@); do
-    echo $i
-    echo # deriver
-    echo 0 # nr of references
-done \
-| chroot $mountPoint @nix@/bin/nix-store --register-validity
+chroot $mountPoint @nix@/bin/nix-store --register-validity < @nixClosure@
 
 
 # Create the required /bin/sh symlink; otherwise lots of things