Paste number 158405: friendly container error messages

Index of paste annotations: 1

Paste number 158405: friendly container error messages
Pasted by: davexunit
When:6 years, 10 months ago
Share:Tweet this! | http://paste.lisp.org/+3E85
Channel:None
Paste contents:
Raw Source | XML | Display As
From b159be856bb4534207025e74d3fa3aaac406ed81 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Tue, 3 Nov 2015 09:02:10 -0500
Subject: [PATCH] scripts: environment: Display friendly container error
 messages.

* guix/scripts/environment.scm (assert-container-features): New
  procedure.
  (guix-environment): Use it.
---
 guix/scripts/environment.scm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 45b54a9..db35d3d 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -437,6 +437,20 @@ Otherwise, return the derivation for the Bash package."
           opts
           (alist-cons 'exec command opts)))))
 
+(define (assert-container-features)
+  "Check if containers can be created and exit with an informative error
+message if any test fails."
+  (unless (user-namespace-supported?)
+    (leave (_ "cannot create container: user namespaces unavailable, is your kernel version < 3.10?")))
+
+  (unless (unprivileged-user-namespace-supported?)
+    (leave
+     (_ "cannot create container: unprivileged user cannot create user namespaces, please set /proc/sys/kernel/unprivileged_userns_clone to \"1\"")))
+
+  (unless (setgroups-supported?)
+    (leave
+     (_ "cannot create container: /proc/self/setgroups does not exist, is your kernel version < 3.19?"))))
+
 ;; Entry point.
 (define (guix-environment . args)
   (with-error-handling
@@ -474,6 +488,9 @@ Otherwise, return the derivation for the Bash package."
                                             '()))
                                           inputs))
                         eq?)))
+
+      (when container? (assert-container-features))
+
       (with-store store
         (run-with-store store
           (mlet* %store-monad ((inputs (lower-inputs
-- 
2.5.0

Annotations for this paste:

Annotation number 1: fixed
Pasted by: davexunit
When:6 years, 10 months ago
Share:Tweet this! | http://paste.lisp.org/+3E85/1
Paste contents:
Raw Source | Display As
From db91c43bd30a95f2d4a2f60195019cc3dea5c251 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Tue, 3 Nov 2015 09:02:10 -0500
Subject: [PATCH] scripts: environment: Display friendly container error
 messages.

* guix/scripts/environment.scm (assert-container-features): New
  procedure.
  (guix-environment): Use it.
---
 guix/scripts/environment.scm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 45b54a9..5eea9c9 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -437,6 +437,21 @@ Otherwise, return the derivation for the Bash package."
           opts
           (alist-cons 'exec command opts)))))
 
+(define (assert-container-features)
+  "Check if containers can be created and exit with an informative error
+message if any test fails."
+  (unless (user-namespace-supported?)
+    (report-error (_ "cannot create container: user namespaces unavailable"))
+    (leave (_ "is your kernel version < 3.10?")))
+
+  (unless (unprivileged-user-namespace-supported?)
+    (report-error (_ "cannot create container: unprivileged user cannot create user namespaces"))
+    (leave (_ "please set /proc/sys/kernel/unprivileged_userns_clone to \"1\"")))
+
+  (unless (setgroups-supported?)
+    (report-error (_ "cannot create container: /proc/self/setgroups does not exist"))
+    (leave (_ "is your kernel version < 3.19?"))))
+
 ;; Entry point.
 (define (guix-environment . args)
   (with-error-handling
@@ -474,6 +489,9 @@ Otherwise, return the derivation for the Bash package."
                                             '()))
                                           inputs))
                         eq?)))
+
+      (when container? (assert-container-features))
+
       (with-store store
         (run-with-store store
           (mlet* %store-monad ((inputs (lower-inputs
-- 
2.5.0

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.