Perl: Difference between revisions

From NixOS Wiki
imported>NieDzejkob
describe wrapping PERL5LIB
imported>Artturin
No edit summary
Line 16: Line 16:


To make perl modules available to a program in your derivation:
To make perl modules available to a program in your derivation:
* add <code>makeWrapper</code> to <code>buildInputs</code>
* add <code>makeWrapper</code> to <code>nativeBuildInputs</code>
* run <code>wrapProgram $pathToScript --set PERL5LIB ${perlPackages.makeFullPerlPath [ perlPackages.Whatever ]}</code> in <code>postInstall</code>
* add <syntaxhighlight lang="nix">
postFixup = ''
  wrapProgram $out/bin/something \
    --prefix PERL5LIB : "${with perlPackages; makePerlPath [ something ]}"
'';
</syntaxhighlight>


[[Category:Languages]]
[[Category:Languages]]

Revision as of 23:26, 5 September 2021

Running a Perl script

Common problems and solutions:

Can't locate DB_File.pm in @INC (you may need to install the DB_File module): run it with nix-shell -p perl -p perlPackages.DBFile --run ./myscript.pl

./myscript.pl: bad interpreter: /usr/bin/perl: no such file or directory: change the first line of the script to #!/usr/bin/env -S perl or start it with perl ./myscript.pl

Adding something from CPAN to nixpkgs

  • Use the nix-generate-from-cpan.pl script (see nixpkgs/maintainers/scripts/) to generate something appropriate.
    Example usage: nix-generate-from-cpan.pl Devel::REPL
  • After reviewing the result from the previous step and making appropriate modifications, add it to pkgs/top-level/perl-packages.nix. Note that some things use buildPerlPackage while some use buildPerlModule. Also note the mostly-followed naming convention as well as the mostly-followed alphabetical ordering. There are plenty of examples in perl-packages.nix — use the source, Luke!
  • Build and test.

Wrappers for installed programs

To make perl modules available to a program in your derivation:

  • add makeWrapper to nativeBuildInputs
  • add
    postFixup = ''
      wrapProgram $out/bin/something \
        --prefix PERL5LIB : "${with perlPackages; makePerlPath [ something ]}"
    '';