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


#1

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?


#2

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.


#3

Hi @qyliss, thanks a lot for this pointer. I’ll try to write my first derivation then. Looks like https://nixos.org/nixos/nix-pills/our-first-derivation.html could be a good starter to dive into that.


#4

that tutorial is a bit low-level and tries to explain the complete abstraction.
You can start with this: https://nixos.wiki/wiki/Packaging/Quirks_and_Caveats#Package_simple_python_scripts

Just replace python with perl.