mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-22 20:14:37 +00:00
Merge pull request #243781 from jamespwilliams/jpw/nix-generate-cpan-to-nix-sri
nix-generate-from-cpan: generate SRI hashes
This commit is contained in:
commit
e5df687280
@ -6,6 +6,7 @@ use warnings;
|
|||||||
|
|
||||||
use CPAN::Meta();
|
use CPAN::Meta();
|
||||||
use CPANPLUS::Backend();
|
use CPANPLUS::Backend();
|
||||||
|
use MIME::Base64;
|
||||||
use Module::CoreList;
|
use Module::CoreList;
|
||||||
use Getopt::Long::Descriptive qw( describe_options );
|
use Getopt::Long::Descriptive qw( describe_options );
|
||||||
use JSON::PP qw( encode_json );
|
use JSON::PP qw( encode_json );
|
||||||
@ -354,6 +355,11 @@ sub render_license {
|
|||||||
return $license_line;
|
return $license_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub sha256_to_sri {
|
||||||
|
my ($sha256) = @_;
|
||||||
|
return "sha256-" . encode_base64(pack("H*", $sha256), '');
|
||||||
|
}
|
||||||
|
|
||||||
my ( $opt, $module_name ) = handle_opts();
|
my ( $opt, $module_name ) = handle_opts();
|
||||||
|
|
||||||
Log::Log4perl->easy_init(
|
Log::Log4perl->easy_init(
|
||||||
@ -380,8 +386,9 @@ INFO( "package: ", $module->package, " (", "$pkg_name-$pkg_version", ", ", $attr
|
|||||||
INFO( "path: ", $module->path );
|
INFO( "path: ", $module->path );
|
||||||
|
|
||||||
my $tar_path = $module->fetch();
|
my $tar_path = $module->fetch();
|
||||||
|
my $sri_hash = sha256_to_sri($module->status->checksum_value);
|
||||||
INFO( "downloaded to: ", $tar_path );
|
INFO( "downloaded to: ", $tar_path );
|
||||||
INFO( "sha-256: ", $module->status->checksum_value );
|
INFO( "hash: ", $sri_hash );
|
||||||
|
|
||||||
my $pkg_path = $module->extract();
|
my $pkg_path = $module->extract();
|
||||||
INFO( "unpacked to: ", $pkg_path );
|
INFO( "unpacked to: ", $pkg_path );
|
||||||
@ -436,7 +443,7 @@ print <<EOF;
|
|||||||
version = "$pkg_version";
|
version = "$pkg_version";
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = "mirror://cpan/${\$module->path}/${\$module->package}";
|
url = "mirror://cpan/${\$module->path}/${\$module->package}";
|
||||||
sha256 = "${\$module->status->checksum_value}";
|
hash = "$sri_hash";
|
||||||
};
|
};
|
||||||
EOF
|
EOF
|
||||||
print <<EOF if scalar @build_deps > 0;
|
print <<EOF if scalar @build_deps > 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user