git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit7ca412a2fad51eb7f819f5954dbbb7d9bf978197 authorRobert Helgesson <robert@rycee.net> dateSun 15 May 2016, 22:49 (11 years ago) parentbf9afcc
2 files changed+9−8
maintainers/scripts/nix-generate-from-cpan.nix+2−1 maintainers/scripts/nix-generate-from-cpan.pl+7−7
maintainers/scripts/nix-generate-from-cpan.nix+2−1
@@ -1,7 +1,7 @@
11{ stdenv, makeWrapper, perl, perlPackages }:
22
33stdenv.mkDerivation {
4− name = "nix-generate-from-cpan-2";
4+ name = "nix-generate-from-cpan-3";
55
66 buildInputs = with perlPackages; [
77 makeWrapper perl CPANMeta GetoptLongDescriptive CPANPLUS Readonly Log4Perl
@@ -20,5 +20,6 @@ stdenv.mkDerivation {
2020 meta = {
2121 maintainers = with stdenv.lib.maintainers; [ eelco rycee ];
2222 description = "Utility to generate a Nix expression for a Perl package from CPAN";
23+ platforms = stdenv.lib.platforms.unix;
2324 };
2425}
maintainers/scripts/nix-generate-from-cpan.pl+7−7
@@ -278,13 +278,13 @@ sub get_deps {
278278 foreach my $n ( $deps->required_modules ) {
279279 next if $n eq "perl";
280280
281− # Hacky way to figure out if this module is part of Perl.
282− if ( $n !~ /^JSON/ && $n !~ /^YAML/ && $n !~ /^Module::Pluggable/ && $n !~ /^if$/ ) {
283− eval "use $n;";
284− if ( !$@ ) {
285− DEBUG("skipping Perl-builtin module $n");
286− next;
287− }
281+ # Figure out whether the module is a core module by attempting
282+ # to `use` the module in a pure Perl interpreter and checking
283+ # whether it succeeded. Note, $^X is a magic variable holding
284+ # the path to the running Perl interpreter.
285+ if ( system("env -i $^X -M$n -e1 >/dev/null 2>&1") == 0 ) {
286+ DEBUG("skipping Perl-builtin module $n");
287+ next;
288288 }
289289
290290 my $pkg = module_to_pkg( $cb, $n );