on master help sign in
give directions on how to fix namespaces when they are disabled
f2fa3ecMichael Bishop
nix-user-chroot/main.cpp+6−2
@@ -112,7 +112,6 @@ int main(int argc, char *argv[]) {
112 switch (opt) {
112 switch (opt) {
113 case 'c':
113 case 'c':
114 clear_env = 1;
114 clear_env = 1;
115− puts("clearing env");
116 break;
115 break;
117 case 'n':
116 case 'n':
118 // determine absolute directory for nix dir
117 // determine absolute directory for nix dir
@@ -167,7 +166,12 @@ int main(int argc, char *argv[]) {
167
166
168 // "unshare" into new namespace
167 // "unshare" into new namespace
169 if (unshare(CLONE_NEWNS | CLONE_NEWUSER) < 0) {
168 if (unshare(CLONE_NEWNS | CLONE_NEWUSER) < 0) {
169+ if (errno == EPERM) {
170+ fputs("Run the following as root to enable unprivileged namespace use:\nsysctl -w kernel.unprivileged_userns_clone=1 ; echo kernel.unprivileged_userns_clone=1 > /etc/sysctl.d/nix-user-chroot.conf\n\n", stderr);
171+ exit(EXIT_FAILURE);
172+ } else {
170− err_exit("unshare()");
173+ err_exit("unshare()");
174+ }
171 }
175 }
172
176
173 // add necessary system stuff to rootdir namespace
177 // add necessary system stuff to rootdir namespace