Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

copy-tarballs.pl: Use substituters to obtain tarballs

(cherry picked from commit 35bd7708d5144036d350ece1342b3a104f9c8bdf)

+29 -12
+28 -11
maintainers/scripts/copy-tarballs.pl
··· 22 22 use Net::Amazon::S3; 23 23 use Nix::Store; 24 24 25 + isValidPath("/nix/store/foo"); # FIXME: forces Nix::Store initialisation 26 + 27 + 25 28 # S3 setup. 26 29 my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'} or die; 27 30 my $aws_secret_access_key = $ENV{'AWS_SECRET_ACCESS_KEY'} or die; ··· 127 130 my $url = $fetch->{url}; 128 131 my $algo = $fetch->{type}; 129 132 my $hash = $fetch->{hash}; 133 + my $name = $fetch->{name}; 130 134 131 135 if (defined $ENV{DEBUG}) { 132 136 print "$url $algo $hash\n"; ··· 143 147 next; 144 148 } 145 149 146 - print STDERR "mirroring $url...\n"; 150 + my $storePath = makeFixedOutputPath(0, $algo, $hash, $name); 151 + 152 + print STDERR "mirroring $url ($storePath)...\n"; 147 153 148 154 next if $ENV{DRY_RUN}; 149 155 150 - # Download the file using nix-prefetch-url. 151 - $ENV{QUIET} = 1; 152 - $ENV{PRINT_PATH} = 1; 153 - my $fh; 154 - my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; 155 - waitpid($pid, 0) or die; 156 - if ($? != 0) { 157 - print STDERR "failed to fetch $url: $?\n"; 158 - next; 156 + # Substitute the output. 157 + if (!isValidPath($storePath)) { 158 + system("nix-store", "-r", $storePath); 159 159 } 160 - <$fh>; my $storePath = <$fh>; chomp $storePath; 160 + 161 + # Otherwise download the file using nix-prefetch-url. 162 + if (!isValidPath($storePath)) { 163 + $ENV{QUIET} = 1; 164 + $ENV{PRINT_PATH} = 1; 165 + my $fh; 166 + my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; 167 + waitpid($pid, 0) or die; 168 + if ($? != 0) { 169 + print STDERR "failed to fetch $url: $?\n"; 170 + next; 171 + } 172 + <$fh>; my $storePath2 = <$fh>; chomp $storePath2; 173 + if ($storePath ne $storePath2) { 174 + warn "strange: $storePath != $storePath2\n"; 175 + next; 176 + } 177 + } 161 178 162 179 uploadFile($storePath, $url); 163 180 $mirrored++;
+1 -1
maintainers/scripts/find-tarballs.nix
··· 14 14 operator = const [ ]; 15 15 }); 16 16 17 - urls = map (drv: { url = head (drv.urls or [ drv.url ]); hash = drv.outputHash; type = drv.outputHashAlgo; }) fetchurlDependencies; 17 + urls = map (drv: { url = head (drv.urls or [ drv.url ]); hash = drv.outputHash; type = drv.outputHashAlgo; name = drv.name; }) fetchurlDependencies; 18 18 19 19 fetchurlDependencies = 20 20 filter