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