SATySFi icon indicating copy to clipboard operation
SATySFi copied to clipboard

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

Open AumyF opened this issue 2 years ago • 6 comments

It affects Nix, which requires deterministic build.

  • https://twitter.com/aumy_f/status/1424958320708706307?s=20
  • https://twitter.com/matsud224/status/1425016936748834824?s=20
❯ nix build --rebuild
error: derivation '/nix/store/fmkxj65j1s6iar75c1hm6jm6m201vh4r-pdf.drv' may not be deterministic: output '/nix/store/7i7hclybw9np21j3pl6j6xg1rlz6q13h-pdf' differs

AumyF avatar Nov 20 '21 13:11 AumyF

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

na4zagin3 avatar Nov 20 '21 14:11 na4zagin3

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.

leque avatar Nov 21 '21 13:11 leque

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.

AumyF avatar Nov 21 '21 14:11 AumyF

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.

leque avatar Nov 22 '21 10:11 leque

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?

AumyF avatar Apr 04 '22 20:04 AumyF