gfngfn / SATySFi

A statically-typed, functional typesetting system
GNU Lesser General Public License v3.0
1.16k stars 82 forks source link

The ID of the generated PDF changes every time and is not deterministic #309

Open AumyF opened 2 years ago

AumyF commented 2 years ago

It affects Nix, which requires deterministic build.

❯ nix build --rebuild
error: derivation '/nix/store/fmkxj65j1s6iar75c1hm6jm6m201vh4r-pdf.drv' may not be deterministic: output '/nix/store/7i7hclybw9np21j3pl6j6xg1rlz6q13h-pdf' differs
na4zagin3 commented 2 years ago

I think SATySFi can have an option to give a random seed to generate reproducible results.

leque commented 2 years ago

After some searching, I found that upcoming camlpdf 2.5 introduces CAMLPDF_REPRODUCIBLE_IDS environment variable ^1 which ensures reproducible ids. I think it would be modester to use a method like this rather than fixing a random seed.

AumyF commented 2 years ago

I just found it too and was wondering why it does not work in my environment...

Anyway, this issue will be closed when camlpdf is updated to 2.5.

leque commented 2 years ago

Current code calls the id generating function Pdf.generate_id via (SATySFi) HandlePdf.write_to_file → (CamlPDF) Pdfwrite.pdf_to_filePdfwrite.pdf_to_file_optionsPdfwrite.change_idPdf.generate_id.

Pdfwrite.pdf_to_file_options function does not call Pdfwrite.change_id if mkid argument is false^1. It might be another choice to use Pdfwrite.pdf_to_file_options with mkid = false in HandlePdf.write_to_file, and attach an ID in SATySFi side.

AumyF commented 2 years ago

camlpdf 2.5 has been released, so upgrading it can solve the issue. However, the changelog says that the feature is for testing. Are there any downsides using fixed ID for PDF files? Or should we pass an ID as command-line options or generate it reproducibly on SATySFi side?

leque commented 2 years ago

Cf. What is the ID field in a pdf file? - Stack Overflow