about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-26T22·28-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-26T22·28-0400
commit67c6f3eded7dcb7c79243ed41f177c960f2b6aad (patch)
tree792842e32598a9201fcee341469799e936da9dfa
parent50395b71a90314abfcc39d8343dbaa8e9aa199a6 (diff)
nix-push: Support generating a manifest again
This makes all the tests succeed.  Woohoo!
-rwxr-xr-xscripts/nix-push.in44
-rw-r--r--tests/binary-patching.sh9
-rw-r--r--tests/install-package.sh2
-rw-r--r--tests/nix-channel.sh2
-rw-r--r--tests/nix-pull.sh2
-rw-r--r--tests/nix-push.sh4
6 files changed, 46 insertions, 17 deletions
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index 45a0695a64d7..39fdd6da9e39 100755
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -8,31 +8,28 @@ use File::stat;
 use File::Copy;
 use Nix::Config;
 use Nix::Store;
-
-my $hashAlgo = "sha256";
+use Nix::Manifest;
 
 my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
     or die "cannot create a temporary directory";
 
 my $nixExpr = "$tmpDir/create-nars.nix";
 
-my $curl = "$Nix::Config::curl --fail --silent";
-my $extraCurlFlags = ${ENV{'CURL_FLAGS'}};
-$curl = "$curl $extraCurlFlags" if defined $extraCurlFlags;
-
 
 # Parse the command line.
 my $compressionType = "xz";
 my $force = 0;
 my $destDir;
+my $writeManifest = 0;
+my $archivesURL;
 my @roots;
 
 sub showSyntax {
     print STDERR <<EOF
-Usage: nix-push --dest DIR PATHS...
+Usage: nix-push --dest DIR [--manifest] [--url-prefix URL] PATHS...
 
-`nix-push' packs the closure of PATHS into a set of NAR archives
-stored in DIR.
+`nix-push' packs the closure of PATHS into a set of NAR files stored
+in DIR.  Optionally generate a manifest.
 EOF
     ; # `
     exit 1;
@@ -52,6 +49,12 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
         die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
         $destDir = $ARGV[$n];
         mkpath($destDir, 0, 0755);
+    } elsif ($arg eq "--manifest") {
+        $writeManifest = 1;
+    } elsif ($arg eq "--url-prefix") {
+        $n++;
+        die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
+        $archivesURL = $ARGV[$n];
     } elsif (substr($arg, 0, 1) eq "-") {
         showSyntax;
     } else {
@@ -61,6 +64,8 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
         
 showSyntax if !defined $destDir;
 
+$archivesURL = "file://$destDir" unless defined $archivesURL;
+
 
 # From the given store paths, determine the set of requisite store
 # paths, i.e, the paths required to realise them.
@@ -98,7 +103,7 @@ foreach my $storePath (@storePaths) {
     # Construct a Nix expression that creates a Nix archive.
     my $nixexpr = 
         "(import <nix/nar.nix> " .
-        "{ storePath = builtins.storePath \"$storePath\"; hashAlgo = \"$hashAlgo\"; compressionType = \"$compressionType\"; }) ";
+        "{ storePath = builtins.storePath \"$storePath\"; hashAlgo = \"sha256\"; compressionType = \"$compressionType\"; }) ";
     
     print NIX $nixexpr;
 }
@@ -126,6 +131,8 @@ print STDERR "copying archives...\n";
 my $totalNarSize = 0;
 my $totalCompressedSize = 0;
 
+my %narFiles;
+
 for (my $n = 0; $n < scalar @storePaths; $n++) {
     my $storePath = $storePaths[$n];
     my $narDir = $narPaths[$n];
@@ -205,7 +212,24 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
         close INFO or die;
         rename($tmp, $dst) or die "cannot rename $tmp to $dst: $!\n";
     }
+
+    $narFiles{$storePath} = [
+        { url => "$archivesURL/$narName"
+        , hash => "sha256:$compressedHash"
+        , size => $compressedSize
+        , narHash => "$narHash"
+        , narSize => $narSize
+        , references => join(" ", @{$refs})
+        , deriver => $deriver
+        }
+    ] if $writeManifest;
 }
 
 printf STDERR "total compressed size %.2f MiB, %.1f%%\n",
     $totalCompressedSize / (1024 * 1024), $totalCompressedSize / $totalNarSize * 100;
+
+
+# Optionally write a manifest.
+if ($writeManifest) {
+    writeManifest "$destDir/MANIFEST", \%narFiles, \();
+}
diff --git a/tests/binary-patching.sh b/tests/binary-patching.sh
index 8c52c2f1421b..188be109a0b5 100644
--- a/tests/binary-patching.sh
+++ b/tests/binary-patching.sh
@@ -7,14 +7,17 @@ mkdir -p $TEST_ROOT/cache2 $TEST_ROOT/patches
 RESULT=$TEST_ROOT/result
 
 # Build version 1 and 2 of the "foo" package.
-nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \
+nix-push --dest $TEST_ROOT/cache2 --manifest --bzip2 \
     $(nix-build -o $RESULT binary-patching.nix --arg version 1)
+mv $TEST_ROOT/cache2/MANIFEST $TEST_ROOT/manifest1 
 
 out2=$(nix-build -o $RESULT binary-patching.nix --arg version 2)
-nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2
+nix-push --dest $TEST_ROOT/cache2 --manifest --bzip2 $out2
+mv $TEST_ROOT/cache2/MANIFEST $TEST_ROOT/manifest2
     
 out3=$(nix-build -o $RESULT binary-patching.nix --arg version 3)
-nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest3 $out3
+nix-push --dest $TEST_ROOT/cache2 --manifest --bzip2 $out3
+mv $TEST_ROOT/cache2/MANIFEST $TEST_ROOT/manifest3
 
 rm $RESULT
 
diff --git a/tests/install-package.sh b/tests/install-package.sh
index b818eda121cf..653dfee4c8d1 100644
--- a/tests/install-package.sh
+++ b/tests/install-package.sh
@@ -9,7 +9,7 @@ clearStore
 clearProfiles
 
 cat > $TEST_ROOT/foo.nixpkg <<EOF
-NIXPKG1 file://$TEST_ROOT/manifest simple $system $drvPath $outPath
+NIXPKG1 file://$TEST_ROOT/cache/MANIFEST simple $system $drvPath $outPath
 EOF
 
 nix-install-package --non-interactive -p $profiles/test $TEST_ROOT/foo.nixpkg
diff --git a/tests/nix-channel.sh b/tests/nix-channel.sh
index eb1d572953d7..a25d56bec11e 100644
--- a/tests/nix-channel.sh
+++ b/tests/nix-channel.sh
@@ -19,7 +19,7 @@ nix-channel --remove xyzzy
 # Create a channel.
 rm -rf $TEST_ROOT/foo
 mkdir -p $TEST_ROOT/foo
-nix-push --copy $TEST_ROOT/foo $TEST_ROOT/foo/MANIFEST $(nix-store -r $(nix-instantiate dependencies.nix))
+nix-push --dest $TEST_ROOT/foo --manifest --bzip2 $(nix-store -r $(nix-instantiate dependencies.nix))
 rm -rf $TEST_ROOT/nixexprs
 mkdir -p $TEST_ROOT/nixexprs
 cp config.nix dependencies.nix dependencies.builder*.sh $TEST_ROOT/nixexprs/
diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh
index 9a89676cb99f..79e7ae26b5cc 100644
--- a/tests/nix-pull.sh
+++ b/tests/nix-pull.sh
@@ -2,7 +2,7 @@ source common.sh
 
 pullCache () {
     echo "pulling cache..."
-    nix-pull file://$TEST_ROOT/manifest
+    nix-pull file://$TEST_ROOT/cache/MANIFEST
 }
 
 clearStore
diff --git a/tests/nix-push.sh b/tests/nix-push.sh
index 69f05141af69..8ea59516c62c 100644
--- a/tests/nix-push.sh
+++ b/tests/nix-push.sh
@@ -1,5 +1,7 @@
 source common.sh
 
+clearStore
+
 drvPath=$(nix-instantiate dependencies.nix)
 outPath=$(nix-store -r $drvPath)
 
@@ -7,4 +9,4 @@ echo "pushing $drvPath"
 
 mkdir -p $TEST_ROOT/cache
 
-nix-push --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath
+nix-push --dest $TEST_ROOT/cache --manifest $drvPath --bzip2