From f4190c38bac1efdbfec9b1ff9c524808d23fe1cc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 1 Jul 2012 18:46:38 -0400 Subject: [PATCH] Allow both bzip2 and xz compression --- corepkgs/nar.nix | 18 ++++++-- scripts/download-from-binary-cache.pl.in | 19 ++++++-- scripts/nix-push.in | 59 ++++++++++++++++-------- 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/corepkgs/nar.nix b/corepkgs/nar.nix index c5155dcc9..cf8851d50 100644 --- a/corepkgs/nar.nix +++ b/corepkgs/nar.nix @@ -6,29 +6,37 @@ let '' export PATH=${nixBinDir}:${coreutils} + if [ $compressionType = "xz" ]; then + ext=xz + compressor=${xz} -9 + else + ext=bz2 + compressor=${bzip2} + fi + echo "packing ‘$storePath’..." mkdir $out - dst=$out/tmp.nar.xz + dst=$out/tmp.nar.$ext set -o pipefail - nix-store --dump "$storePath" | ${xz} -9 > $dst + nix-store --dump "$storePath" | $compressor -9 > $dst hash=$(nix-hash --flat --type $hashAlgo --base32 $dst) echo -n $hash > $out/nar-compressed-hash - mv $dst $out/$hash.nar.xz + mv $dst $out/$hash.nar.$ext ''; in -{ storePath, hashAlgo }: +{ storePath, hashAlgo, compressionType }: derivation { name = "nar"; system = builtins.currentSystem; builder = shell; args = [ "-e" builder ]; - inherit storePath hashAlgo; + inherit storePath hashAlgo compressionType; # Don't build in a chroot because Nix's dependencies may not be there. __noChroot = true; diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in index ccd28eafc..d121f2fc3 100644 --- a/scripts/download-from-binary-cache.pl.in +++ b/scripts/download-from-binary-cache.pl.in @@ -4,7 +4,7 @@ use strict; use Nix::Config; use Nix::Store; -my @binaryCacheUrls = ("file:///tmp/binary-cache"); +my @binaryCacheUrls = ("file:///tmp/binary-cache2"); sub getInfoFrom { my ($storePath, $pathHash, $binaryCacheUrl) = @_; @@ -15,14 +15,15 @@ sub getInfoFrom { print STDERR "GOT CURL REPLY ", $? >> 8, "\n"; return undef; } - my ($storePath2, $url, $fileHash, $fileSize, $narHash, $narSize, $deriver); + my ($storePath2, $url, $compression, $fileHash, $fileSize, $narHash, $narSize, $deriver); my @refs; foreach my $line (split "\n", $s) { $line =~ /^(.*): (.*)$/ or return undef; if ($1 eq "StorePath") { $storePath2 = $2; } elsif ($1 eq "URL") { $url = $2; } - elsif ($1 eq "CompressedHash") { $fileHash = $2; } - elsif ($1 eq "CompressedSize") { $fileSize = int($2); } + elsif ($1 eq "Compression") { $compression = $2; } + elsif ($1 eq "FileHash") { $fileHash = $2; } + elsif ($1 eq "FileSize") { $fileSize = int($2); } elsif ($1 eq "NarHash") { $narHash = $2; } elsif ($1 eq "NarSize") { $narSize = int($2); } elsif ($1 eq "References") { @refs = split / /, $2; } @@ -34,6 +35,7 @@ sub getInfoFrom { } return { url => $url + , compression => ($compression || "bzip2") , fileHash => $fileHash , fileSize => $fileSize , narHash => $narHash @@ -64,7 +66,14 @@ sub downloadBinary { cache: foreach my $binaryCacheUrl (@binaryCacheUrls) { my $info = getInfoFrom($storePath, $pathHash, $binaryCacheUrl); if (defined $info) { - if (system("$Nix::Config::curl --fail --location $binaryCacheUrl/$info->{url} | $Nix::Config::xz -d | $Nix::Config::binDir/nix-store --restore $storePath") == 0) { + my $decompressor; + if ($info->{compression} eq "bzip2") { $decompressor = "$Nix::Config::bzip2 -d"; } + elsif ($info->{compression} eq "xz") { $decompressor = "$Nix::Config::xz -d"; } + else { + print STDERR "unknown compression method ‘$info->{compression}’\n"; + next; + } + if (system("$Nix::Config::curl --fail --location $binaryCacheUrl/$info->{url} | $decompressor | $Nix::Config::binDir/nix-store --restore $storePath") == 0) { return 1; } } diff --git a/scripts/nix-push.in b/scripts/nix-push.in index 9f73b8127..c388429ec 100755 --- a/scripts/nix-push.in +++ b/scripts/nix-push.in @@ -22,16 +22,21 @@ $curl = "$curl $extraCurlFlags" if defined $extraCurlFlags; # Parse the command line. +my $compressionType = "xz"; +my $force = 0; + my $localCopy; my $localArchivesDir; my $archivesPutURL; my $archivesGetURL; +my @roots; + sub showSyntax { print STDERR <$tmp" or die; print INFO "$info" or die;