···
#! /usr/bin/env nix-shell
2
-
#! nix-shell -i perl -p perl perlPackages.NetAmazonS3 perlPackages.FileSlurp perlPackages.JSON perlPackages.LWPProtocolHttps nix nix.perl-bindings
2
+
#! nix-shell -i perl -p perl perlPackages.NetAmazonS3 perlPackages.FileSlurp perlPackages.JSON perlPackages.LWPProtocolHttps nix
# This command uploads tarballs to tarballs.nixos.org, the
# content-addressed cache used by fetchurl as a fallback for when
···
25
-
isValidPath("/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo"); # FIXME: forces Nix::Store initialisation
die "Syntax: $0 [--dry-run] [--exclude REGEXP] [--expr EXPR | --file FILES...]\n";
28
+
sub computeFixedOutputPath {
29
+
my ($name, $algo, $hash) = @_;
30
+
my $expr = <<'EXPR';
31
+
{ name, outputHashAlgo, outputHash }:
32
+
builtins.toString (derivation {
33
+
inherit name outputHashAlgo outputHash;
35
+
system = "dontcare";
36
+
outputHashMode = "flat";
44
+
"--argstr", "name", $name,
45
+
"--argstr", "outputHashAlgo", $algo,
46
+
"--argstr", "outputHash", $hash) or die "Failed to run nix-instantiate: $!";
48
+
my $storePathJson = <$fh>;
49
+
chomp $storePathJson;
50
+
my $storePath = decode_json($storePathJson);
56
+
my ($algo, $base16, $path) = @_;
61
+
($base16 ? "--base16" : ()),
62
+
$path) or die "Failed to run nix-hash: $!";
···
93
-
my $md5_16 = hashFile("md5", 0, $fn) or die;
94
-
my $sha1_16 = hashFile("sha1", 0, $fn) or die;
95
-
my $sha256_32 = hashFile("sha256", 1, $fn) or die;
96
-
my $sha256_16 = hashFile("sha256", 0, $fn) or die;
97
-
my $sha512_32 = hashFile("sha512", 1, $fn) or die;
98
-
my $sha512_16 = hashFile("sha512", 0, $fn) or die;
130
+
my $md5_16 = nixHash("md5", 0, $fn) or die;
131
+
my $sha1_16 = nixHash("sha1", 0, $fn) or die;
132
+
my $sha256_32 = nixHash("sha256", 1, $fn) or die;
133
+
my $sha256_16 = nixHash("sha256", 0, $fn) or die;
134
+
my $sha512_32 = nixHash("sha512", 1, $fn) or die;
135
+
my $sha512_16 = nixHash("sha512", 0, $fn) or die;
my $mainKey = "sha512/$sha512_16";
···
foreach my $fn (@fileNames) {
133
-
if (alreadyMirrored("sha512", hashFile("sha512", 0, $fn))) {
170
+
if (alreadyMirrored("sha512", nixHash("sha512", 0, $fn))) {
print STDERR "$fn is already mirrored\n";
uploadFile($fn, basename $fn);
···
if ($hash =~ /^([a-z0-9]+)-([A-Za-z0-9+\/=]+)$/) {
179
-
$hash = `nix --extra-experimental-features nix-command hash to-base16 $hash` or die;
216
+
open(my $fh, "-|", "nix", "--extra-experimental-features", "nix-command", "hash", "convert", "--to", "base16", $hash) or die;
···
# Convert non-SRI base-64 to base-16.
if ($hash =~ /^[A-Za-z0-9+\/=]+$/) {
187
-
$hash = `nix --extra-experimental-features nix-command hash to-base16 --type '$algo' $hash` or die;
226
+
open(my $fh, "-|", "nix", "--extra-experimental-features", "nix-command", "hash", "convert", "--to", "base16", "--hash-algo", $algo, $hash) or die;
191
-
my $storePath = makeFixedOutputPath(0, $algo, $hash, $name);
232
+
my $storePath = computeFixedOutputPath($name, $algo, $hash);
if (defined $ENV{DEBUG}) {
···
print STDERR "mirroring $url ($storePath, $algo, $hash)...\n";
218
-
# Substitute the output.
219
-
if (!isValidPath($storePath)) {
220
-
system("nix-store", "-r", $storePath);
259
+
my $isValidPath = system("nix-store", "-r", $storePath) == 0;
# Otherwise download the file using nix-prefetch-url.
224
-
if (!isValidPath($storePath)) {
262
+
if (!$isValidPath) {