Subject: bug#30729: r-lambda-r not reproducible

From: Ricardo Wurmus <[email-masked]>
Date: Fri, 9 Mar 2018 22:43:15 +0100

Ricardo Wurmus <[email-masked]> writes:

> The r-lambda-r package is not reproducible.  The differences in the RDX
> files indicates that the package’s RDB file includes references to
> environments that differ in size, which leads to variables being stored
> at different offsets in the RDB file.
[…]

> │ │  $references$`env::6`
> │ │ -[1] 17999   584
> │ │ +[1] 17999   588
> │ │
> │ │  $references$`env::7`
> │ │ -[1] 18583   807
> │ │ +[1] 18587   810
> │ │
> │ │  $references$`env::8`
> │ │ -[1] 19390   617
> │ │ +[1] 19397   618
> │ │
> │ │  $references$`env::9`
> │ │ -[1] 20007  1550
> │ │ +[1] 20015  1548

The problem is indeed that the sizes of the serialised environments
differ.  But how can I inspect these environments?

The RDX file is an index into the compressed binary RDB.  The index
tells me that `env::6` is found at offset 17999 and has a size of 584
bytes (or 588 in the second build).

R internally uses lazyLoadDBfetch to look up values in serialised files
without having to load the full file into memory.  We can do the same in
an R session.  Here I use a different offset and size for the new build
I have here:

--8<---------------cut here---------------start------------->8---
e <- lazyLoadDBfetch(as.integer(c(16386, 659)),
                     file="/gnu/store/z53g4n9frbgcvbkpq0ai1y286177gz3i-r-lambda-r-1.2/site-library/lambda.r/R/lambda.r.rdb",
                     compressed=TRUE,
                     hook=NULL)
--8<---------------cut here---------------end--------------->8---

Now looking at the contents of “e”, I see that it has a “bindings”
field.  And this contains values like this:

--8<---------------cut here---------------start------------->8---
$Enc
[1] "unknown"

$filename
[1] "<text>"

$fixedNewlines
[1] TRUE

$isFile
[1] FALSE

$lines
[1] "function(...) UseFunction(describe,\"describe\",...)"

[…]

$timestamp
[1] "2018-03-08 01:21:11 CET"

$wd
[1] "/tmp/guix-build-r-lambda-r-1.2.drv-0/lambda.r"
--8<---------------cut here---------------end--------------->8---

“timestamp”?  Hah!

Searching the R sources indicates that this value is set in
“src/library/base/R/srcfile.R”, which I’ve previously encountered in the
arguments field of “r-minimal”.  It looks like this value is taken from
the source file’s mtime, but resetting the timestamps before the
“install” phase didn’t seem to have helped.  Maybe this needs to be done
at some other point that is somewhere deep within R CMD INSTALL.

In that case, I think we can do the same as for Python and introduce a
check for DETERMINISTIC_BUILD into “srcfile”.

--
Ricardo