about summary refs log tree commit diff
path: root/src/nix
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2019-07-25T13·37-0400
committerMatthew Bauer <mjbauer95@gmail.com>2019-07-25T18·42-0400
commitd171090530f4a2a79efec2c385bee1a10844c706 (patch)
tree709ddf2bd276cb5cea94b7a4088547b37ec67c76 /src/nix
parentb640f69a4d33eb3833cf0ac3000d189dacbd0f5a (diff)
Disable CLONE_NEWUSER when it’s unavailable
Some kernels disable "unpriveleged user namespaces". This is
unfortunate, but we can still use mount namespaces. Anyway, since each
builder has its own nixbld user, we already have most of the benefits
of user namespaces.
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/run.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/nix/run.cc b/src/nix/run.cc
index 35b763345872..90b76d6663e9 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -199,7 +199,10 @@ void chrootHelper(int argc, char * * argv)
     uid_t gid = getgid();
 
     if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == -1)
-        throw SysError("setting up a private mount namespace");
+        /* Try with just CLONE_NEWNS in case user namespaces are
+           specifically disabled. */
+        if (unshare(CLONE_NEWNS) == -1)
+            throw SysError("setting up a private mount namespace");
 
     /* Bind-mount realStoreDir on /nix/store. If the latter mount
        point doesn't already exists, we have to create a chroot