cups-pdf: misc improvements in package, module, vmtest (#387364)

Changed files
+46 -47
nixos
pkgs
by-name
cu
cups-pdf-to-pdf
+1 -1
nixos/tests/all-tests.nix
···
crabfit = handleTest ./crabfit.nix { };
cri-o = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./cri-o.nix { };
cryptpad = runTest ./cryptpad.nix;
-
cups-pdf = handleTest ./cups-pdf.nix { };
+
cups-pdf = runTest ./cups-pdf.nix;
curl-impersonate = handleTest ./curl-impersonate.nix { };
custom-ca = handleTest ./custom-ca.nix { };
croc = handleTest ./croc.nix { };
+40 -42
nixos/tests/cups-pdf.nix
···
-
import ./make-test-python.nix (
-
{ lib, pkgs, ... }:
-
{
-
name = "cups-pdf";
+
{ hostPkgs, lib, ... }:
+
{
+
name = "cups-pdf";
-
nodes.machine =
-
{ pkgs, ... }:
-
{
-
imports = [ ./common/user-account.nix ];
-
environment.systemPackages = [ pkgs.poppler-utils ];
-
fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
-
services.printing.cups-pdf.enable = true;
-
services.printing.cups-pdf.instances = {
-
opt = { };
-
noopt.installPrinter = false;
-
};
-
hardware.printers.ensurePrinters = [
-
{
-
name = "noopt";
-
model = "CUPS-PDF_noopt.ppd";
-
deviceUri = "cups-pdf:/noopt";
-
}
-
];
+
nodes.machine =
+
{ pkgs, ... }:
+
{
+
imports = [ ./common/user-account.nix ];
+
environment.systemPackages = [ pkgs.poppler-utils ];
+
fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
+
services.printing.cups-pdf.enable = true;
+
services.printing.cups-pdf.instances = {
+
opt = { };
+
noopt.installPrinter = false;
};
+
hardware.printers.ensurePrinters = [
+
{
+
name = "noopt";
+
model = "CUPS-PDF_noopt.ppd";
+
deviceUri = "cups-pdf:/noopt";
+
}
+
];
+
};
-
# we cannot check the files with pdftotext, due to
-
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
-
# we need `imagemagickBig` as it has ghostscript support
+
# we cannot check the files with pdftotext, due to
+
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
+
# we need `imagemagickBig` as it has ghostscript support
-
testScript = ''
-
from subprocess import run
-
machine.wait_for_unit("multi-user.target")
-
for name in ("opt", "noopt"):
-
text = f"test text {name}".upper()
-
machine.wait_until_succeeds(f"lpstat -v {name}")
-
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
-
# wait until the pdf files are completely produced and readable by alice
-
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
-
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
-
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
-
run(f"${pkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
-
assert text.encode() in run(f"${lib.getExe pkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
-
'';
+
testScript = ''
+
from subprocess import run
+
machine.wait_for_unit("multi-user.target")
+
for name in ("opt", "noopt"):
+
text = f"test text {name}".upper()
+
machine.wait_until_succeeds(f"lpstat -v {name}")
+
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
+
# wait until the pdf files are completely produced and readable by alice
+
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
+
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
+
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
+
run(f"${lib.getExe hostPkgs.imagemagickBig} -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
+
assert text.encode() in run(f"${lib.getExe hostPkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
+
'';
-
meta.maintainers = [ lib.maintainers.yarny ];
-
}
-
)
+
meta.maintainers = [ lib.maintainers.yarny ];
+
}
+5 -4
pkgs/by-name/cu/cups-pdf-to-pdf/package.nix
···
buildInputs = [ cups ];
postPatch = ''
-
sed -r 's|(gscall, size, ")cp |\1${coreutils}/bin/cp |' cups-pdf.c -i
+
substituteInPlace cups-pdf.c \
+
--replace-fail '"cp ' '"${lib.getExe' coreutils "cp"} '
'';
# gcc command line is taken from original cups-pdf's README file
···
passthru.tests.vmtest = nixosTests.cups-pdf;
-
meta = with lib; {
+
meta = {
description = "CUPS backend that turns print jobs into searchable PDF files";
homepage = "https://github.com/alexivkin/CUPS-PDF-to-PDF";
-
license = licenses.gpl2Only;
-
maintainers = [ maintainers.yarny ];
+
license = lib.licenses.gpl2Only;
+
maintainers = [ lib.maintainers.yarny ];
longDescription = ''
cups-pdf is a CUPS backend that generates a PDF file for each print job and puts this file
into a folder on the local machine such that the print job's owner can access the file.