Perl: Difference between revisions
No edit summary |
m prefix shell commands with "$" and use syntax highlighting |
||
| Line 6: | Line 6: | ||
<syntaxHighlight lang=shell> | <syntaxHighlight lang=shell> | ||
#!/usr/bin/env perl | |||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 29: | Line 29: | ||
If you run a perl script and encounter a dependency error like this: | If you run a perl script and encounter a dependency error like this: | ||
<code> | |||
< | |||
Can't locate DB_File.pm in @INC (you may need to install the DB_File module) | Can't locate DB_File.pm in @INC (you may need to install the DB_File module) | ||
</ | </code> | ||
... use <code>nix-shell</code> to create a shell environment which includes the dependency. Here we searched NixOS packages and found an existing perl package which suits, [https://search.nixos.org/packages?channel=unstable&from=0&size=30&sort=relevance&type=packages&query=dbfile like so]. | ... use <code>nix-shell</code> to create a shell environment which includes the dependency. Here we searched NixOS packages and found an existing perl package which suits, [https://search.nixos.org/packages?channel=unstable&from=0&size=30&sort=relevance&type=packages&query=dbfile like so]. | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
nix-shell -p perl perl534Packages.DBFile --run ./myscript.pl | $ nix-shell -p perl perl534Packages.DBFile --run ./myscript.pl | ||
</syntaxHighlight > | </syntaxHighlight > | ||
| Line 43: | Line 42: | ||
By design, there is no <code>/usr/bin/perl</code> in Nix. So you may encounter messages like: | By design, there is no <code>/usr/bin/perl</code> in Nix. So you may encounter messages like: | ||
< | <code> | ||
./myscript.pl: bad interpreter: /usr/bin/perl: no such file or directory | ./myscript.pl: bad interpreter: /usr/bin/perl: no such file or directory | ||
</ | </code> | ||
Change the first line of the script to | Change the first line of the script to | ||
<syntaxHighlight lang=shell> | <syntaxHighlight lang=shell> | ||
| Line 55: | Line 54: | ||
==Adding something from CPAN to nixpkgs== | ==Adding something from CPAN to nixpkgs== | ||
# Enter a <tt>nix-shell</tt> that provides the necessary dependencies: <syntaxHighlight lang= | # Enter a <tt>nix-shell</tt> that provides the necessary dependencies: <syntaxHighlight lang=console>$ nix-shell -p perl perlPackages.CPANPLUS perlPackages.GetoptLongDescriptive perlPackages.LogLog4perl perlPackages.Readonly</syntaxHighlight> | ||
# Use the <tt>nix-generate-from-cpan.pl</tt> script (see <tt>nixpkgs/maintainers/scripts/</tt>) to generate something appropriate.<br/>Example usage: <syntaxHighlight lang= | # Use the <tt>nix-generate-from-cpan.pl</tt> script (see <tt>nixpkgs/maintainers/scripts/</tt>) to generate something appropriate.<br/>Example usage: <syntaxHighlight lang=console>$ nix-generate-from-cpan.pl Devel::REPL</syntaxHighlight> | ||
# After reviewing the result from the previous step and making appropriate modifications, add it to <code>pkgs/top-level/perl-packages.nix</code>. Note that some things use <code>buildPerlPackage</code> while some use <code>buildPerlModule</code>. Also note the mostly-followed naming convention as well as the mostly-followed alphabetical ordering. There are plenty of examples in <tt>perl-packages.nix</tt> — use the source, Luke! | # After reviewing the result from the previous step and making appropriate modifications, add it to <code>pkgs/top-level/perl-packages.nix</code>. Note that some things use <code>buildPerlPackage</code> while some use <code>buildPerlModule</code>. Also note the mostly-followed naming convention as well as the mostly-followed alphabetical ordering. There are plenty of examples in <tt>perl-packages.nix</tt> — use the source, Luke! | ||
# Build and test. | # Build and test. | ||