about summary refs log tree commit diff
path: root/scripts/nix-push.in
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-17T20·45-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-17T20·58-0400
commit167e36a5c3127da63d120d9fdaf5e046b829f287 (patch)
treed396fefa5dd8e3d1d35b82722bce385dd734766c /scripts/nix-push.in
parentac238d619c2469ea89b8707ae340d3f19c77eadf (diff)
nix-push: Only generate and copy a NAR if it doesn't already exist
This prevents unnecessary and slow rebuilds of NARs that already exist
in the binary cache.
Diffstat (limited to 'scripts/nix-push.in')
-rwxr-xr-xscripts/nix-push.in42
1 files changed, 36 insertions, 6 deletions
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index 993b94adf064..4a88a3a17066 100755
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -9,6 +9,7 @@ use File::Copy;
 use Nix::Config;
 use Nix::Store;
 use Nix::Manifest;
+use Nix::Utils;
 
 my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
     or die "cannot create a temporary directory";
@@ -81,12 +82,43 @@ foreach my $path (@roots) {
 my @storePaths = keys %storePaths;
 
 
+# Don't create archives for files that are already in the binary cache.
+my @storePaths2;
+my %narFiles;
+foreach my $storePath (@storePaths) {
+    my $pathHash = substr(basename($storePath), 0, 32);
+    my $narInfoFile = "$destDir/$pathHash.narinfo";
+    if (-e $narInfoFile) {
+        my $narInfo = parseNARInfo($storePath, readFile($narInfoFile));
+        my $narFile = "$destDir/$narInfo->{url}";
+        if (-e $narFile) {
+            print STDERR "skipping existing $storePath\n";
+            # Add the NAR info to $narFiles if we're writing a
+            # manifest.
+            $narFiles{$storePath} = [
+                { url => ("$archivesURL/" . basename $narInfo->{url})
+                  , hash => $narInfo->{fileHash}
+                  , size => $narInfo->{fileSize}
+                  , compressionType => $narInfo->{compression}
+                  , narHash => $narInfo->{narHash}
+                  , narSize => $narInfo->{narSize}
+                  , references => join(" ", map { "$Nix::Config::storeDir/$_" } @{$narInfo->{refs}})
+                  , deriver => $narInfo->{deriver} ? "$Nix::Config::storeDir/$narInfo->{deriver}" : undef
+                  }
+            ] if $writeManifest;
+            next;
+        }
+    }
+    push @storePaths2, $storePath;
+}
+
+
 # Create a list of Nix derivations that turn each path into a Nix
 # archive.
 open NIX, ">$nixExpr";
 print NIX "[";
 
-foreach my $storePath (@storePaths) {
+foreach my $storePath (@storePaths2) {
     die unless ($storePath =~ /\/[0-9a-z]{32}[^\"\\\$]*$/);
 
     # Construct a Nix expression that creates a Nix archive.
@@ -130,10 +162,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];
+for (my $n = 0; $n < scalar @storePaths2; $n++) {
+    my $storePath = $storePaths2[$n];
     my $narDir = $narPaths[$n];
     my $baseName = basename $storePath;
 
@@ -226,7 +256,7 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
 }
 
 printf STDERR "total compressed size %.2f MiB, %.1f%%\n",
-    $totalCompressedSize / (1024 * 1024), $totalCompressedSize / $totalNarSize * 100;
+    $totalCompressedSize / (1024 * 1024), $totalCompressedSize / ($totalNarSize || 1) * 100;
 
 
 # Optionally write a manifest.