about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-10-16T13·13+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-10-16T13·13+0000
commitab5e8767fafb2d62213e3f1558ead2882bc65c05 (patch)
tree852077324a6b9a65dead66c2b4854c455fed097d /scripts
parentc78bf115248f62fa355e7a9b2b9532b37e693085 (diff)
* Get nix-push to work again.
* Fixed svn:ignore on externals/.

Diffstat (limited to 'scripts')
-rw-r--r--scripts/nix-push.in110
1 files changed, 78 insertions, 32 deletions
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index d9f5cf756b2f..c0aba5322b8f 100644
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -1,21 +1,32 @@
 #! /usr/bin/perl -w
 
-my $fixfile = "/tmp/nix-push-tmp.fix";
+use strict;
+use POSIX qw(tmpnam);
+
+my $tmpdir;
+do { $tmpdir = tmpnam(); }
+until mkdir $tmpdir, 0777;
+
+my $fixfile = "$tmpdir/create-nars.fix";
+my $manifest = "$tmpdir/MANIFEST";
+
+END { unlink $manifest; unlink $fixfile; rmdir $tmpdir; }
+
 open FIX, ">$fixfile";
 print FIX "[";
 my $first = 1;
 
+my @paths;
+
 foreach my $id (@ARGV) {
 
-    die unless $id =~ /^([0-9a-z]{32})$/;
+    die unless $id =~ /^\//;
 
     # Get all paths referenced by the normalisation of the given 
     # Nix expression.
-    system "nix --install $id";
+    system "nix --install $id > /dev/null";
     if ($?) { die "`nix --install' failed"; }
 
-    my @paths;
-
     open PATHS, "nix --query --requisites --include-successors $id 2> /dev/null |" or die "nix -qr";
     while (<PATHS>) {
         chomp;
@@ -24,35 +35,17 @@ foreach my $id (@ARGV) {
     }
     close PATHS;
 
-    # Also add all normal forms that are contained in these paths.
-#    open PATHS, "nix --query --generators --path @paths |" or die "nix -qg";
-#    while (<PATHS>) {
-#	chomp;
-#        die "bad: $_" unless /^\//;
-#	push @paths, $_;
-#    }
-#    close PATHS;
-
     # For each path, create a Fix expression that turns the path into
     # a Nix archive.
     foreach my $path (@paths) {
 
-	next unless ($path =~ /\/([0-9a-z]{32})[^\/]*/);
+	die unless ($path =~ /\/[0-9a-z]{32}.*$/);
 	print "$path\n";
-	my $pathid = $1;
-
-        # Construct a name for the Nix archive.  If the file is an
-        # fstate successor, encode this into the name.
-        my $name = $pathid;
-        if ($path =~ /-s-([0-9a-z]{32}).nix$/) {
-            $name = "$name-s-$1";
-        }
-        $name = $name . ".nar.bz2";
 
         # Construct a Fix expression that creates a Nix archive.
         my $fixexpr = 
-          "App(IncludeFix(\"nar/nar.fix\"), " .
-          "[ (\"path\", Closure([\"$path\"], [(\"$path\", \"$pathid\", [])]))" .
+          "Call(IncludeFix(\"nar/nar.fix\"), " .
+          "[ (\"path\", Closure([\"$path\"], [(\"$path\", [])]))" .
           "])";
 	
 	print FIX "," unless ($first);
@@ -65,32 +58,85 @@ foreach my $id (@ARGV) {
 print FIX "]";
 close FIX;
 
+
 # Instantiate a Nix expression from the Fix expression.
 my @nids;
 print STDERR "running fix...\n";
 open NIDS, "fix $fixfile |" or die "cannot run fix";
 while (<NIDS>) {
     chomp;
-    die unless /^([0-9a-z]{32})$/;
-    push @nids, $1;
+    die unless /^\//;
+    push @nids, $_;
 }
+close NIDS;
 
 
 # Realise the Nix expression.
-my @pushlist;
 print STDERR "creating archives...\n";
-system "nix --install @nids > /dev/null";
+system "nix --install -v @nids > /dev/null";
 if ($?) { die "`nix --install' failed"; }
 
+my @narpaths;
 open NIDS, "nix --query --list @nids |" or die "cannot run nix";
 while (<NIDS>) {
     chomp;
     die unless (/^\//);
-    print "$_\n";
-    push @pushlist, "$_/*";
+    push @narpaths, "$_";
 }
+close NIDS;
+
+    
+# Create the manifest.
+print STDERR "creating manifest...\n";
+
+open MANIFEST, ">$manifest";
+
+my @pushlist;
+push @pushlist, $manifest;
+
+for (my $n = 0; $n < scalar @paths; $n++) {
+    my $storepath = $paths[$n];
+    my $nardir = $narpaths[$n];
+    
+    $storepath =~ /\/([^\/]*)$/;
+    my $basename = $1;
+    defined $basename or die;
+
+    my $narname = "$basename.nar.bz2";
+
+    my $narfile = "$nardir/$narname";
+    (-f $narfile) or die "narfile for $storepath not found";
+    push @pushlist, $narfile;
+
+    open MD5, "$nardir/md5" or die "cannot open hash";
+    my $hash = <MD5>;
+    chomp $hash;
+    $hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
+    close MD5;
+
+    print MANIFEST "{\n";
+    print MANIFEST "  StorePath: $storepath\n";
+    print MANIFEST "  NarPath: $basename\n";
+    print MANIFEST "  MD5: $hash\n";
+
+    if ($storepath =~ /\.nix$/) {
+	open PREDS, "nix --query --predecessors $storepath |" or die "cannot run nix";
+	while (<PREDS>) {
+	    chomp;
+	    die unless (/^\//);
+	    print MANIFEST "  SuccOf: $_\n";
+	}
+	close PREDS;
+    }
+
+    print MANIFEST "}\n";
+}
+
+close MANIFEST;
+
 
 # Push the prebuilts to the server. !!! FIXME
+print STDERR "pushing to server...\n";
 if (scalar @pushlist > 0) {
     system "rsync -av -e ssh @pushlist eelco\@losser.st-lab.cs.uu.nl:/home/eelco/public_html/nix-dist/";
 }