Wrong build directory number shown in environment-variables file

  • Open
  • quality assurance status badge
Details
4 participants
  • Christine Lemmer-Webber
  • Sarah Morgensen
  • Ludovic Courtès
  • Tobias Geerinckx-Rice
Owner
unassigned
Submitted by
Christine Lemmer-Webber
Severity
normal
C
C
Christine Lemmer-Webber wrote on 6 Sep 2021 23:22
(address . bug-guix@gnu.org)
87a6kpcs85.fsf@dustycloud.org
I was doing guix build with "--keep-missing" and looking around in a few
of the output directories. I was peeking in:

/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-4

But wait... the "environment-variables" file says:

#+BEGIN_SRC sh
export TEMP=\
"/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
export TEMPDIR=\
"/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
export TMP=\
"/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
export TMPDIR=\
"/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
#+END_SRC

Now wait a minute. Look at that last number. What the hell is going on
here? Is this a bug in Guix? Why is it pointing at -0 in the -4 build
directory?

Does this point at a more serious issue? What's going on?
T
T
Tobias Geerinckx-Rice wrote on 7 Sep 2021 06:34
(name . Christine Lemmer-Webber)(address . cwebber@dustycloud.org)
87k0jtvw3e.fsf@nckx
Christine,

Christine Lemmer-Webber ???
Toggle quote (12 lines)
> I was doing guix build with "--keep-missing" and looking around
> in a few
> of the output directories. I was peeking in:
>
> /tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-4
>
> But wait... the "environment-variables" file says:
>
> #+BEGIN_SRC sh
> export TEMP=\
> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"

Part of the build environment isolation/reproducibility is that
processes inside it always see a build directory ending in ‘-0’,
regardless of the file name on the host system.

Kind regards,

T G-R
-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYTbsxQ0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW15thUA/0dz4LAOzKOgFvRI1LpMX6vZJ7s5mSDS5hf3PIGj
hI14AP0Xod8RsCLklceqo7pQnDGEy/mQKSpdL5mx/a8dh/pWAQ==
=K/e4
-----END PGP SIGNATURE-----

S
S
Sarah Morgensen wrote on 7 Sep 2021 06:44
(name . Christine Lemmer-Webber)(address . cwebber@dustycloud.org)(address . 50441@debbugs.gnu.org)
86eea1hu44.fsf@mgsn.dev
Hello Christine,

Christine Lemmer-Webber <cwebber@dustycloud.org> writes:

Toggle quote (24 lines)
> I was doing guix build with "--keep-missing" and looking around in a few
> of the output directories. I was peeking in:
>
> /tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-4
>
> But wait... the "environment-variables" file says:
>
> #+BEGIN_SRC sh
> export TEMP=\
> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
> export TEMPDIR=\
> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
> export TMP=\
> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
> export TMPDIR=\
> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
> #+END_SRC
>
> Now wait a minute. Look at that last number. What the hell is going on
> here? Is this a bug in Guix? Why is it pointing at -0 in the -4 build
> directory?
>
> Does this point at a more serious issue? What's going on?

I've definitely noticed this before as well, and had to work around it
(I needed to inspect temp caches). Thanks for actually sending a bug
report :)

I'm not at all familiar with the nix code, but it looks like this might
be related:

nix/libstore/build.cc:1654
Toggle snippet (18 lines)
/* In a sandbox, for determinism, always use the same temporary
directory. */
tmpDirInSandbox = useChroot ? canonPath("/tmp", true) + "/guix-build-" + drvName + "-0" : tmpDir;

/* For convenience, set an environment pointing to the top build
directory. */
env["NIX_BUILD_TOP"] = tmpDirInSandbox;

/* Also set TMPDIR and variants to point to this directory. */
env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = tmpDirInSandbox;

/* Explicitly set PWD to prevent problems with chroot builds. In
particular, dietlibc cannot figure out the cwd because the
inode of the current directory doesn't appear in .. (because
getdents returns the inode of the mount point). */
env["PWD"] = tmpDirInSandbox;

I'm not entirely sure what's going on. I think we build in chroot by
default, which would explain why the temp vars get set to "-0" even
though everything else seems to work okay.

--
Sarah
C
C
Christine Lemmer-Webber wrote on 7 Sep 2021 16:25
(name . Sarah Morgensen)(address . iskarian@mgsn.dev)(address . 50441@debbugs.gnu.org)
877dfscvh8.fsf@dustycloud.org
Loops like Tobias gave the explanation in their reply:

Toggle quote (4 lines)
> Part of the build environment isolation/reproducibility is that
> processes inside it always see a build directory ending in ‘-0’,
> regardless of the file name on the host system.

Sarah Morgensen <iskarian@mgsn.dev> writes:

Toggle quote (57 lines)
> Hello Christine,
>
> Christine Lemmer-Webber <cwebber@dustycloud.org> writes:
>
>> I was doing guix build with "--keep-missing" and looking around in a few
>> of the output directories. I was peeking in:
>>
>> /tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-4
>>
>> But wait... the "environment-variables" file says:
>>
>> #+BEGIN_SRC sh
>> export TEMP=\
>> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
>> export TEMPDIR=\
>> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
>> export TMP=\
>> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
>> export TMPDIR=\
>> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
>> #+END_SRC
>>
>> Now wait a minute. Look at that last number. What the hell is going on
>> here? Is this a bug in Guix? Why is it pointing at -0 in the -4 build
>> directory?
>>
>> Does this point at a more serious issue? What's going on?
>
> I've definitely noticed this before as well, and had to work around it
> (I needed to inspect temp caches). Thanks for actually sending a bug
> report :)
>
> I'm not at all familiar with the nix code, but it looks like this might
> be related:
>
> nix/libstore/build.cc:1654
>
> /* In a sandbox, for determinism, always use the same temporary
> directory. */
> tmpDirInSandbox = useChroot ? canonPath("/tmp", true) + "/guix-build-" + drvName + "-0" : tmpDir;
>
> /* For convenience, set an environment pointing to the top build
> directory. */
> env["NIX_BUILD_TOP"] = tmpDirInSandbox;
>
> /* Also set TMPDIR and variants to point to this directory. */
> env["TMPDIR"] = env["TEMPDIR"] = env["TMP"] = env["TEMP"] = tmpDirInSandbox;
>
> /* Explicitly set PWD to prevent problems with chroot builds. In
> particular, dietlibc cannot figure out the cwd because the
> inode of the current directory doesn't appear in .. (because
> getdents returns the inode of the mount point). */
> env["PWD"] = tmpDirInSandbox;
>
> I'm not entirely sure what's going on. I think we build in chroot by
> default, which would explain why the temp vars get set to "-0" even
> though everything else seems to work okay.
C
C
Christine Lemmer-Webber wrote on 7 Sep 2021 16:26
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)
874kawcvey.fsf@dustycloud.org
Hi Tobias!

Tobias Geerinckx-Rice <me@tobias.gr> writes:

Toggle quote (26 lines)
> [[PGP Signed Part:Undecided]]
> Christine,
>
> Christine Lemmer-Webber ???
>> I was doing guix build with "--keep-missing" and looking around in a
>> few
>> of the output directories. I was peeking in:
>>
>> /tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-4
>>
>> But wait... the "environment-variables" file says:
>>
>> #+BEGIN_SRC sh
>> export TEMP=\
>> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
>
> Part of the build environment isolation/reproducibility is that
> processes inside it always see a build directory ending in ‘-0’,
> regardless of the file name on the host system.
>
> Kind regards,
>
> T G-R
>
> [[End of PGP Signed Part]]

This makes sense in general, though I wonder if when using --keep-failed
if environment-variables should dump out something different, since
that file is around for debugging, and sourcing it might set up the
wrong paths I guess? What do you think?
L
L
Ludovic Courtès wrote on 14 Sep 2021 09:47
(name . Christine Lemmer-Webber)(address . cwebber@dustycloud.org)
87y27z7g5m.fsf@gnu.org
Hi,

Christine Lemmer-Webber <cwebber@dustycloud.org> skribis:

Toggle quote (2 lines)
> Tobias Geerinckx-Rice <me@tobias.gr> writes:

[...]

Toggle quote (19 lines)
>>> #+BEGIN_SRC sh
>>> export TEMP=\
>>> "/tmp/guix-build-u-boot-mnt-reform2-2021.06.drv-0"
>>
>> Part of the build environment isolation/reproducibility is that
>> processes inside it always see a build directory ending in ‘-0’,
>> regardless of the file name on the host system.
>>
>> Kind regards,
>>
>> T G-R
>>
>> [[End of PGP Signed Part]]
>
> This makes sense in general, though I wonder if when using --keep-failed
> if environment-variables should dump out something different, since
> that file is around for debugging, and sourcing it might set up the
> wrong paths I guess? What do you think?

There’s no good solution I’m afraid. Directory names within the build
environment must be fixed to ensure reproducibility, as Tobias writes;
yet, the daemon shouldn’t overwrite directories that happen to already
exist in the “real” /tmp.

Thanks,
Ludo’.
?