[Solved] Perl include path

I’m new to nixos and have some trouble with Perl.

After installing e.g. perlPackages.WWWMechanize via environment.systemPackages in configuration.nix I get

Can’t locate WWW/Mechanize.pm in @INC

I’ve added /run/current-system/sw/lib/perl5/site_perl to my PERL5LIB but this leads me to another missing Perl package:

Can’t locate HTTP/Request.pm in @INC

But HTTP::Request is located at /nix/store/6jqiw3s7p8hpsrs9zd14ipq8r70wijld-perl-5.32.1-env/lib/perl5/site_perl/5.32.1/HTTP/Request.pm

Do I have to add every path to my PERL5LIB?
How is the Perl include path handled in nixos?

Many thanks :slightly_smiling_face:
Frank

Try this from your terminal:

nix-shell -p 'perl.withPackages (p: with p; [ WWWMechanize ])

This will drop you into a shell which contains perl with WWWMechanize.

Thank you, that works. :slightly_smiling_face:

But its not viable for me to add all dependent Perl modules to the list.
I’d have to keep a separate list for each script.
And how could I use it in my Eclipse IDE?

I read your post about Perl modules baked into perl
Promising, but I didn’t get it to work. :slightly_frowning_face:
Is it still up-to-date?

Sure. You want to add something like this to your configuration.nix:

{ config, pkgs, ... }:
let
  perlEnv = pkgs.perl.withPackages (p: with p; [
    WWWMechanize
    # and the rest of your modules
  ]);
in
{
  environment.systemPackages = [ perlEnv ];
}

This will make version of perl, with all of the modules you specify, available on your entire system - including to your IDE.

Exactly what I want. :+1:

But that gives me

error: attempt to call something which is not a function but a set, at /etc/nixos/configuration.nix:12:1

It’s the opening curly bracked right after in
Here are the first lines of my configuration.nix

{ config, pkgs, ... }:
let
  perlEnv = pkgs.perl.withPackages (p: with p; [
    WWWMechanize
    # and the rest of your modules
  ]);
in
{
  environment.systemPackages = [ perlEnv ];
}
{
  nix.extraOptions = "
    keep-outputs = false
    keep-derivations = false
  ";

  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

You need to move environment.systemPackages into the rest of your configuration, at the same level as nix.extraOptions and imports.

Yeah, perfect :tada:

I’d say it’s worth a wiki entry for all nixos newcomers like me.

Thank you so much :grinning: