···11-import ./make-test-python.nix (
22- { lib, pkgs, ... }:
33- {
44- name = "cups-pdf";
11+{ hostPkgs, lib, ... }:
22+{
33+ name = "cups-pdf";
5466- nodes.machine =
77- { pkgs, ... }:
88- {
99- imports = [ ./common/user-account.nix ];
1010- environment.systemPackages = [ pkgs.poppler-utils ];
1111- fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
1212- services.printing.cups-pdf.enable = true;
1313- services.printing.cups-pdf.instances = {
1414- opt = { };
1515- noopt.installPrinter = false;
1616- };
1717- hardware.printers.ensurePrinters = [
1818- {
1919- name = "noopt";
2020- model = "CUPS-PDF_noopt.ppd";
2121- deviceUri = "cups-pdf:/noopt";
2222- }
2323- ];
55+ nodes.machine =
66+ { pkgs, ... }:
77+ {
88+ imports = [ ./common/user-account.nix ];
99+ environment.systemPackages = [ pkgs.poppler-utils ];
1010+ fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
1111+ services.printing.cups-pdf.enable = true;
1212+ services.printing.cups-pdf.instances = {
1313+ opt = { };
1414+ noopt.installPrinter = false;
2415 };
1616+ hardware.printers.ensurePrinters = [
1717+ {
1818+ name = "noopt";
1919+ model = "CUPS-PDF_noopt.ppd";
2020+ deviceUri = "cups-pdf:/noopt";
2121+ }
2222+ ];
2323+ };
25242626- # we cannot check the files with pdftotext, due to
2727- # https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
2828- # we need `imagemagickBig` as it has ghostscript support
2525+ # we cannot check the files with pdftotext, due to
2626+ # https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
2727+ # we need `imagemagickBig` as it has ghostscript support
29283030- testScript = ''
3131- from subprocess import run
3232- machine.wait_for_unit("multi-user.target")
3333- for name in ("opt", "noopt"):
3434- text = f"test text {name}".upper()
3535- machine.wait_until_succeeds(f"lpstat -v {name}")
3636- machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
3737- # wait until the pdf files are completely produced and readable by alice
3838- machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
3939- machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
4040- machine.copy_from_vm(f"/tmp/{name}.pdf", "")
4141- run(f"${pkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
4242- assert text.encode() in run(f"${lib.getExe pkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
4343- '';
2929+ testScript = ''
3030+ from subprocess import run
3131+ machine.wait_for_unit("multi-user.target")
3232+ for name in ("opt", "noopt"):
3333+ text = f"test text {name}".upper()
3434+ machine.wait_until_succeeds(f"lpstat -v {name}")
3535+ machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
3636+ # wait until the pdf files are completely produced and readable by alice
3737+ machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
3838+ machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
3939+ machine.copy_from_vm(f"/tmp/{name}.pdf", "")
4040+ run(f"${lib.getExe hostPkgs.imagemagickBig} -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
4141+ assert text.encode() in run(f"${lib.getExe hostPkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
4242+ '';
44434545- meta.maintainers = [ lib.maintainers.yarny ];
4646- }
4747-)
4444+ meta.maintainers = [ lib.maintainers.yarny ];
4545+}
+5-4
pkgs/by-name/cu/cups-pdf-to-pdf/package.nix
···2121 buildInputs = [ cups ];
22222323 postPatch = ''
2424- sed -r 's|(gscall, size, ")cp |\1${coreutils}/bin/cp |' cups-pdf.c -i
2424+ substituteInPlace cups-pdf.c \
2525+ --replace-fail '"cp ' '"${lib.getExe' coreutils "cp"} '
2526 '';
26272728 # gcc command line is taken from original cups-pdf's README file
···44454546 passthru.tests.vmtest = nixosTests.cups-pdf;
46474747- meta = with lib; {
4848+ meta = {
4849 description = "CUPS backend that turns print jobs into searchable PDF files";
4950 homepage = "https://github.com/alexivkin/CUPS-PDF-to-PDF";
5050- license = licenses.gpl2Only;
5151- maintainers = [ maintainers.yarny ];
5151+ license = lib.licenses.gpl2Only;
5252+ maintainers = [ lib.maintainers.yarny ];
5253 longDescription = ''
5354 cups-pdf is a CUPS backend that generates a PDF file for each print job and puts this file
5455 into a folder on the local machine such that the print job's owner can access the file.