1import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "cups-pdf";
3
4 nodes.machine = { pkgs, ... }: {
5 imports = [ ./common/user-account.nix ];
6 environment.systemPackages = [ pkgs.poppler_utils ];
7 fonts.fonts = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
8 services.printing.cups-pdf.enable = true;
9 services.printing.cups-pdf.instances = {
10 opt = {};
11 noopt.installPrinter = false;
12 };
13 hardware.printers.ensurePrinters = [{
14 name = "noopt";
15 model = "CUPS-PDF_noopt.ppd";
16 deviceUri = "cups-pdf:/noopt";
17 }];
18 };
19
20 # we cannot check the files with pdftotext, due to
21 # https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
22 # we need `imagemagickBig` as it has ghostscript support
23
24 testScript = ''
25 from subprocess import run
26 machine.wait_for_unit("multi-user.target")
27 for name in ("opt", "noopt"):
28 text = f"test text {name}".upper()
29 machine.wait_until_succeeds(f"lpstat -v {name}")
30 machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
31 # wait until the pdf files are completely produced and readable by alice
32 machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
33 machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
34 machine.copy_from_vm(f"/tmp/{name}.pdf", "")
35 run(f"${pkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
36 assert text.encode() in run(f"${lib.getExe pkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
37 '';
38
39 meta.maintainers = [ lib.maintainers.yarny ];
40})