nix-generate-from-cpan: fix core module detection

This makes the detection of core modules a bit more robust by checking
the module inclusion in a pure Perl interpreter. This ensures that any
extra path in the `nix-generate-from-cpan` script's `PERL5LIB` does not
affect the generated package expression.
This commit is contained in:
Robert Helgesson 2016-05-15 22:49:16 +02:00
parent bf9afccdfe
commit 7ca412a2fa
2 changed files with 9 additions and 8 deletions

View File

@ -1,7 +1,7 @@
{ stdenv, makeWrapper, perl, perlPackages }: { stdenv, makeWrapper, perl, perlPackages }:
stdenv.mkDerivation { stdenv.mkDerivation {
name = "nix-generate-from-cpan-2"; name = "nix-generate-from-cpan-3";
buildInputs = with perlPackages; [ buildInputs = with perlPackages; [
makeWrapper perl CPANMeta GetoptLongDescriptive CPANPLUS Readonly Log4Perl makeWrapper perl CPANMeta GetoptLongDescriptive CPANPLUS Readonly Log4Perl
@ -20,5 +20,6 @@ stdenv.mkDerivation {
meta = { meta = {
maintainers = with stdenv.lib.maintainers; [ eelco rycee ]; maintainers = with stdenv.lib.maintainers; [ eelco rycee ];
description = "Utility to generate a Nix expression for a Perl package from CPAN"; description = "Utility to generate a Nix expression for a Perl package from CPAN";
platforms = stdenv.lib.platforms.unix;
}; };
} }

View File

@ -278,13 +278,13 @@ sub get_deps {
foreach my $n ( $deps->required_modules ) { foreach my $n ( $deps->required_modules ) {
next if $n eq "perl"; next if $n eq "perl";
# Hacky way to figure out if this module is part of Perl. # Figure out whether the module is a core module by attempting
if ( $n !~ /^JSON/ && $n !~ /^YAML/ && $n !~ /^Module::Pluggable/ && $n !~ /^if$/ ) { # to `use` the module in a pure Perl interpreter and checking
eval "use $n;"; # whether it succeeded. Note, $^X is a magic variable holding
if ( !$@ ) { # the path to the running Perl interpreter.
DEBUG("skipping Perl-builtin module $n"); if ( system("env -i $^X -M$n -e1 >/dev/null 2>&1") == 0 ) {
next; DEBUG("skipping Perl-builtin module $n");
} next;
} }
my $pkg = module_to_pkg( $cb, $n ); my $pkg = module_to_pkg( $cb, $n );