From 35bd7708d5144036d350ece1342b3a104f9c8bdf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 18 Apr 2016 15:17:13 +0200 Subject: copy-tarballs.pl: Use substituters to obtain tarballs --- maintainers/scripts/copy-tarballs.pl | 39 +++++++++++++++++++++++++---------- maintainers/scripts/find-tarballs.nix | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'maintainers') diff --git a/maintainers/scripts/copy-tarballs.pl b/maintainers/scripts/copy-tarballs.pl index b1233827ad88..db0cea3e670d 100755 --- a/maintainers/scripts/copy-tarballs.pl +++ b/maintainers/scripts/copy-tarballs.pl @@ -22,6 +22,9 @@ use JSON; use Net::Amazon::S3; use Nix::Store; +isValidPath("/nix/store/foo"); # FIXME: forces Nix::Store initialisation + + # S3 setup. my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'} or die; my $aws_secret_access_key = $ENV{'AWS_SECRET_ACCESS_KEY'} or die; @@ -127,6 +130,7 @@ elsif ($op eq "--expr") { my $url = $fetch->{url}; my $algo = $fetch->{type}; my $hash = $fetch->{hash}; + my $name = $fetch->{name}; if (defined $ENV{DEBUG}) { print "$url $algo $hash\n"; @@ -143,21 +147,34 @@ elsif ($op eq "--expr") { next; } - print STDERR "mirroring $url...\n"; + my $storePath = makeFixedOutputPath(0, $algo, $hash, $name); + + print STDERR "mirroring $url ($storePath)...\n"; next if $ENV{DRY_RUN}; - # Download the file using nix-prefetch-url. - $ENV{QUIET} = 1; - $ENV{PRINT_PATH} = 1; - my $fh; - my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; - waitpid($pid, 0) or die; - if ($? != 0) { - print STDERR "failed to fetch $url: $?\n"; - next; + # Substitute the output. + if (!isValidPath($storePath)) { + system("nix-store", "-r", $storePath); + } + + # Otherwise download the file using nix-prefetch-url. + if (!isValidPath($storePath)) { + $ENV{QUIET} = 1; + $ENV{PRINT_PATH} = 1; + my $fh; + my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; + waitpid($pid, 0) or die; + if ($? != 0) { + print STDERR "failed to fetch $url: $?\n"; + next; + } + <$fh>; my $storePath2 = <$fh>; chomp $storePath2; + if ($storePath ne $storePath2) { + warn "strange: $storePath != $storePath2\n"; + next; + } } - <$fh>; my $storePath = <$fh>; chomp $storePath; uploadFile($storePath, $url); $mirrored++; diff --git a/maintainers/scripts/find-tarballs.nix b/maintainers/scripts/find-tarballs.nix index ad79af90901e..bd6afda900c8 100644 --- a/maintainers/scripts/find-tarballs.nix +++ b/maintainers/scripts/find-tarballs.nix @@ -14,7 +14,7 @@ let operator = const [ ]; }); - urls = map (drv: { url = head (drv.urls or [ drv.url ]); hash = drv.outputHash; type = drv.outputHashAlgo; }) fetchurlDependencies; + urls = map (drv: { url = head (drv.urls or [ drv.url ]); hash = drv.outputHash; type = drv.outputHashAlgo; name = drv.name; }) fetchurlDependencies; fetchurlDependencies = filter -- cgit 1.4.1