···
#! /usr/bin/env nix-shell
-
#! nix-shell -i perl -p perl perlPackages.NetAmazonS3 perlPackages.FileSlurp perlPackages.JSON perlPackages.LWPProtocolHttps nix nix.perl-bindings
# This command uploads tarballs to tarballs.nixos.org, the
# content-addressed cache used by fetchurl as a fallback for when
···
-
isValidPath("/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo"); # FIXME: forces Nix::Store initialisation
die "Syntax: $0 [--dry-run] [--exclude REGEXP] [--expr EXPR | --file FILES...]\n";
···
-
my $md5_16 = hashFile("md5", 0, $fn) or die;
-
my $sha1_16 = hashFile("sha1", 0, $fn) or die;
-
my $sha256_32 = hashFile("sha256", 1, $fn) or die;
-
my $sha256_16 = hashFile("sha256", 0, $fn) or die;
-
my $sha512_32 = hashFile("sha512", 1, $fn) or die;
-
my $sha512_16 = hashFile("sha512", 0, $fn) or die;
my $mainKey = "sha512/$sha512_16";
···
foreach my $fn (@fileNames) {
-
if (alreadyMirrored("sha512", hashFile("sha512", 0, $fn))) {
print STDERR "$fn is already mirrored\n";
uploadFile($fn, basename $fn);
···
if ($hash =~ /^([a-z0-9]+)-([A-Za-z0-9+\/=]+)$/) {
-
$hash = `nix --extra-experimental-features nix-command hash to-base16 $hash` or die;
···
# Convert non-SRI base-64 to base-16.
if ($hash =~ /^[A-Za-z0-9+\/=]+$/) {
-
$hash = `nix --extra-experimental-features nix-command hash to-base16 --type '$algo' $hash` or die;
-
my $storePath = makeFixedOutputPath(0, $algo, $hash, $name);
if (defined $ENV{DEBUG}) {
···
print STDERR "mirroring $url ($storePath, $algo, $hash)...\n";
-
# Substitute the output.
-
if (!isValidPath($storePath)) {
-
system("nix-store", "-r", $storePath);
# Otherwise download the file using nix-prefetch-url.
-
if (!isValidPath($storePath)) {
···
#! /usr/bin/env nix-shell
+
#! 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
···
die "Syntax: $0 [--dry-run] [--exclude REGEXP] [--expr EXPR | --file FILES...]\n";
+
sub computeFixedOutputPath {
+
my ($name, $algo, $hash) = @_;
+
{ name, outputHashAlgo, outputHash }:
+
builtins.toString (derivation {
+
inherit name outputHashAlgo outputHash;
+
outputHashMode = "flat";
+
"--argstr", "name", $name,
+
"--argstr", "outputHashAlgo", $algo,
+
"--argstr", "outputHash", $hash) or die "Failed to run nix-instantiate: $!";
+
my $storePathJson = <$fh>;
+
my $storePath = decode_json($storePathJson);
+
my ($algo, $base16, $path) = @_;
+
($base16 ? "--base16" : ()),
+
$path) or die "Failed to run nix-hash: $!";
···
+
my $md5_16 = nixHash("md5", 0, $fn) or die;
+
my $sha1_16 = nixHash("sha1", 0, $fn) or die;
+
my $sha256_32 = nixHash("sha256", 1, $fn) or die;
+
my $sha256_16 = nixHash("sha256", 0, $fn) or die;
+
my $sha512_32 = nixHash("sha512", 1, $fn) or die;
+
my $sha512_16 = nixHash("sha512", 0, $fn) or die;
my $mainKey = "sha512/$sha512_16";
···
foreach my $fn (@fileNames) {
+
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+\/=]+)$/) {
+
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+\/=]+$/) {
+
open(my $fh, "-|", "nix", "--extra-experimental-features", "nix-command", "hash", "convert", "--to", "base16", "--hash-algo", $algo, $hash) or die;
+
my $storePath = computeFixedOutputPath($name, $algo, $hash);
if (defined $ENV{DEBUG}) {
···
print STDERR "mirroring $url ($storePath, $algo, $hash)...\n";
+
my $isValidPath = system("nix-store", "-r", $storePath) == 0;
# Otherwise download the file using nix-prefetch-url.