Installing perl packages globally

Back from the time before I was using NixOS, I have a bunch of perl scripts that I want to continue to use as before. I have already changed the shebang to #!/usr/bin/env perl, but it seems that it won’t pick up Perl packages that I installed globally, via /etc/nixos/configuration.nix, where I include, say, perlPackages.XMLSimple in the packages.

I can run the script in a nix-shell -p perl perlPackages.XMLSimple.

I understand it’s cleaner to package my scripts in nix derivations, or at least use shell.nix and direnv for a per-project environments… but to ~cater for my laziness~ allow a incremental transition, is there a way to install perl packages globally?

Not sure about installing perl packages globally, but I’m sure there should be a way. In the meantime, you might be able to work out a quick and dirty solution by adding a nix-shell shebang to your scripts.

Ah, right, that’s also an option. I’m going for shell.nix and direnv for now.

You could probably add this code into your configuration.nix (untested):

  environment.profileRelativeEnvVars = {
    PERL5LIB = [ "/lib/perl5/site_perl" ];
  };

Ref. https://github.com/NixOS/nixpkgs/commit/74442da768d4dc74f182b3623416a2bbeea32460

maybe

environment.systemPackages = [ (perl.withPackages(ps: [ ps.XMLSimple ])) ];

The perl.withPackages variant works for me!

(Although I have now already set up a shell.nix, where just listing perlPackages.XMLSimple works, and it is probably cleaner this way.)