Perl script with shebang used in a CUPS printing pipeline: no such file or directory

Hi there, I am a new NixOS user, on a HP EliteBook 840 G3 notebook. I use it with Gnome 3. Before, I used Arch Linux with the i3 window manager for a couple of years.

Context: I installed CUPS via configuration.nix. Using a script provided by my employer’s IT department, I added a custom ppd file for our printing setup. This ppd file containes a CUPS filter that is used for authentication in the network. This filter is a Perl script.

This Perl script starts with a shebang of:

#!/usr/bin/perl -w

Executing the script in a terminal with my user results in:

no such file or directory: /usr/bin/perl

Indeed, the command

which perl

tells me that perl resides elsewhere, namely:

/run/current-system/sw/bin/perl

Replacing the original shebang with

#!/run/current-system/sw/bin/perl

makes the printer setup work. (I removed the “-w” because the script already contains “use warnings”)

However, I wonder what would be a more canonical NixOS way to do this. I don’t think the idea is to change every (Perl) script’s shebang. I found out and then remembered that a more robust way to write shebangs is with

#!/usr/bin/env perl

and indeed, executing

/usr/bin/env perl

just like this on the command line works, it gives me a Perl interactive shell. If I change the shebang of the script to this, and execute the script directly in my terminal, this also works (= does not crash, no error message). But inside the printer pipeline, it does not work: CUPS tells me “Filter failed”, and with journalctl I see

/usr/bin/env: 'perl': no such file or directory

It seems like the environment of the user CUPS runs with, is different than my environment.

What would be the NixOS way to fix this?

The best thing would be to write a derivation for the script you got from IT. As part of the build, Nix will rewrite the shebangs to point to the appropriate Perl in the Nix store.

Hi @qyliss, thanks a lot for this pointer. I’ll try to write my first derivation then. Looks like Nix Pills | Nix & NixOS could be a good starter to dive into that.

that tutorial is a bit low-level and tries to explain the complete abstraction.
You can start with this: Packaging/Quirks and Caveats - NixOS Wiki

Just replace python with perl.