Subject: bug#25242: closed (Re: bug#25242: Cannot build source derivations with a custom TMPDIR)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 29 Dec 2016 17:24:02 +0000

Your bug report

#25242: Cannot build source derivations with a custom TMPDIR

which was filed against the guix package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
25242: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=25242
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#25242: Cannot build source derivations with a custom TMPDIR
From: [email-masked] (Ludovic Courtès)
To: Leo Famulari <[email-masked]>
Cc: [email-masked]
Date: Thu, 29 Dec 2016 18:23:45 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Leo Famulari <[email-masked]> skribis:

> On Wed, Dec 21, 2016 at 10:20:20AM +0100, Ludovic Courtès wrote:
>> AFAICS the flaw is that there’s one place where I wrote:
>> 
>>   if (useChroot && !isBuiltin(drv))
>> 
>> while several other places just do something like:
>> 
>>   if (useChroot)
>> 
>> Could the patch below solve the problem?
>> 
>
>> diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
>> index e823001..38048ce 100644
>> --- a/nix/libstore/build.cc
>> +++ b/nix/libstore/build.cc
>> @@ -1680,7 +1680,11 @@ void DerivationGoal::startBuilder()
>>              % drv.platform % settings.thisSystem % drvPath);
>>      }
>>  
>> -    useChroot = settings.useChroot;
>> +    /* Note: built-in builders are *not* running in a chroot environment so
>> +       that we can easily implement them in Guile without having it as a
>> +       derivation input (they are running under a separate build user,
>> +       though).  */
>> +    useChroot = settings.useChroot && !isBuiltin(drv);
>>  
>>      /* Construct the environment passed to the builder. */
>>      env.clear();
>> @@ -2048,12 +2052,7 @@ void DerivationGoal::runChild()
>>          commonChildInit(builderOut);
>>  
>>  #if CHROOT_ENABLED
>> -	/* Note: built-in builders are *not* running in a chroot environment
>> -	   so that we can easily implement them in Guile without having it as
>> -	   a derivation input (they are running under a separate build user,
>> -	   though).  */
>> -
>> -        if (useChroot && !isBuiltin(drv)) {
>> +        if (useChroot) {
>>              /* Initialise the loopback interface. */
>>              AutoCloseFD fd(socket(PF_INET, SOCK_DGRAM, IPPROTO_IP));
>>              if (fd == -1) throw SysError("cannot open IP socket");
>
> Yes, this does fix the problem!

Awesome!

> I wonder if I should commit this while Ludo is away?

You could have done it.  :-)

I’ve just pushed it as 8ecc3c6c447765b1f7c15b980f985d1826f48659.

Thank you!

Ludo’.

Subject: Cannot build source derivations with a custom TMPDIR
From: Leo Famulari <[email-masked]>
To: [email-masked]
Date: Wed, 21 Dec 2016 03:22:40 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

Since Guix 0.11.0-4.1f41, I can't build source derivations while using a
custom $TMPDIR.

I first described this issue in <http://bugs.gnu.org/25089>, but I'm
splitting it into its own report.

On my Debian system, I set 'TMPDIR=/home/leo/tmp/guix-build'.

Then, I can do this:

$ ./pre-inst-env guix build nmap
guix build: error: build failed: while setting up the build environment: changing into `/home/leo/tmp/guix-build/guix-build-nmap-7.40.tar.bz2.drv-0': No such file or directory

And some monitoring of the TMPDIR:

$ cd /home/leo/tmp/guix-build && inotifywait --monitor .
Setting up watches.
Watches established.
./ CREATE,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ ATTRIB,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ ATTRIB,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ OPEN,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ ACCESS,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ ACCESS,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ CLOSE_NOWRITE,CLOSE,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0
./ DELETE,ISDIR guix-build-nmap-7.40.tar.bz2.drv-0

I ran the guix-daemon with strace, and I see these relevant lines:

15337 [pid 30675] mkdir("/home/leo/tmp/guix-build/guix-build-nmap-7.40.tar.bz2.drv-0", 0700) = 0
15338 [pid 30675] getegid()                   = 0
15339 [pid 30675] chown("/home/leo/tmp/guix-build/guix-build-nmap-7.40.tar.bz2.drv-0", -1, 0) = 0

... and just a bit later ...

15438 [pid 30693] chdir("/tmp/guix-build-nmap-7.40.tar.bz2.drv-0") = -1 ENOENT (No such file or directory)

I'm still trying to figure out where the problem is in the code. I guess
it's somewhere in these commits or code they interact with:

05ceb8dca download: Use the built-in 'download' builder when available.
f9aefa2d5 daemon: Add 'built-in-builders' RPC.
94d92c779 daemon: Add "builtin:download" derivation builder.