Merge pull request #243781 from jamespwilliams/jpw/nix-generate-cpan-to-nix-sri

nix-generate-from-cpan: generate SRI hashes

authored by Stig and committed by GitHub e5df6872 934817ce

+9 -2
+9 -2
maintainers/scripts/nix-generate-from-cpan.pl
··· 6 6 7 7 use CPAN::Meta(); 8 8 use CPANPLUS::Backend(); 9 + use MIME::Base64; 9 10 use Module::CoreList; 10 11 use Getopt::Long::Descriptive qw( describe_options ); 11 12 use JSON::PP qw( encode_json ); ··· 354 355 return $license_line; 355 356 } 356 357 358 + sub sha256_to_sri { 359 + my ($sha256) = @_; 360 + return "sha256-" . encode_base64(pack("H*", $sha256), ''); 361 + } 362 + 357 363 my ( $opt, $module_name ) = handle_opts(); 358 364 359 365 Log::Log4perl->easy_init( ··· 380 386 INFO( "path: ", $module->path ); 381 387 382 388 my $tar_path = $module->fetch(); 389 + my $sri_hash = sha256_to_sri($module->status->checksum_value); 383 390 INFO( "downloaded to: ", $tar_path ); 384 - INFO( "sha-256: ", $module->status->checksum_value ); 391 + INFO( "hash: ", $sri_hash ); 385 392 386 393 my $pkg_path = $module->extract(); 387 394 INFO( "unpacked to: ", $pkg_path ); ··· 436 443 version = "$pkg_version"; 437 444 src = fetchurl { 438 445 url = "mirror://cpan/${\$module->path}/${\$module->package}"; 439 - sha256 = "${\$module->status->checksum_value}"; 446 + hash = "$sri_hash"; 440 447 }; 441 448 EOF 442 449 print <<EOF if scalar @build_deps > 0;