Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

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.

+9 -8
+2 -1
maintainers/scripts/nix-generate-from-cpan.nix
··· 1 1 { stdenv, makeWrapper, perl, perlPackages }: 2 2 3 3 stdenv.mkDerivation { 4 - name = "nix-generate-from-cpan-2"; 4 + name = "nix-generate-from-cpan-3"; 5 5 6 6 buildInputs = with perlPackages; [ 7 7 makeWrapper perl CPANMeta GetoptLongDescriptive CPANPLUS Readonly Log4Perl ··· 20 20 meta = { 21 21 maintainers = with stdenv.lib.maintainers; [ eelco rycee ]; 22 22 description = "Utility to generate a Nix expression for a Perl package from CPAN"; 23 + platforms = stdenv.lib.platforms.unix; 23 24 }; 24 25 }
+7 -7
maintainers/scripts/nix-generate-from-cpan.pl
··· 278 278 foreach my $n ( $deps->required_modules ) { 279 279 next if $n eq "perl"; 280 280 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; 288 288 } 289 289 290 290 my $pkg = module_to_pkg( $cb, $n );