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