From d66d9e8425d52cc698851e2e85bd56aa96f45fc9 Mon Sep 17 00:00:00 2001
From: Shea Levy <shea@shealevy.com>
Date: Wed, 4 Feb 2015 11:46:38 -0500
Subject: [PATCH] Require linux 3.13 or later for chroot

Fixes #453
---
 doc/manual/command-ref/conf-file.xml | 3 ++-
 src/libstore/build.cc                | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/manual/command-ref/conf-file.xml b/doc/manual/command-ref/conf-file.xml
index 053f4d43c..4bd73b2fc 100644
--- a/doc/manual/command-ref/conf-file.xml
+++ b/doc/manual/command-ref/conf-file.xml
@@ -243,7 +243,8 @@ flag, e.g. <literal>--option gc-keep-outputs false</literal>.</para>
     users” feature</link> to perform the actual builds under different
     users than root).  Currently, chroot builds only work on Linux
     because Nix uses “bind mounts” to make the Nix store and other
-    directories available inside the chroot.</para>
+    directories available inside the chroot. Kernel version 3.13 or later
+    is needed due to a PID namespace fix nix depends on.</para>
 
     </listitem>
 
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index e0398e2fb..259324734 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1970,7 +1970,12 @@ void DerivationGoal::startBuilder()
             char stack[32 * 1024];
             pid_t child = clone(childEntry, stack + sizeof(stack) - 8,
                 CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_PARENT | SIGCHLD, this);
-            if (child == -1) throw SysError("cloning builder process");
+            if (child == -1) {
+                if (errno == EINVAL)
+                    throw SysError("cloning builder process (Linux chroot builds require 3.13 or later)");
+                else
+                    throw SysError("cloning builder process");
+            }
             writeFull(builderOut.writeSide, int2String(child) + "\n");
             _exit(0);
         });
-- 
GitLab