[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/05: scripts: system: Add 'container' action.

From: David Thompson
Subject: 03/05: scripts: system: Add 'container' action.
Date: Sat, 12 Sep 2015 02:16:34 +0000

davexunit pushed a commit to branch wip-container
in repository guix.

commit 8aa1daaf2a47cb94cc08a77514fb5802e513e435
Author: David Thompson <address@hidden>
Date:   Mon Jun 8 09:04:38 2015 -0400

    scripts: system: Add 'container' action.
    * guix/scripts/system.scm (show-help): Display 'container' action.
      (system-derivation-for-action, guix-system): Add 'container' case.
      (perform-action): Skip GRUB config generation when building a container.
    * doc/guix.texi (Invoking guix system): Document it.
 doc/guix.texi                  |   21 +++++++++++++++++++++
 gnu/system/linux-container.scm |    7 ++++++-
 guix/scripts/system.scm        |   19 +++++++++++++------
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 2a7d9c7..e30d185 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6865,6 +6865,27 @@ using the following command:
 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
 @end example
address@hidden container
+Return a script to run the operating system declared in @var{file}
+within a container.  Currently, the script must be run as root in order
+to support more than a single user and group.
+The container shares its store with the host system.
+Additional file systems can be shared between the host and the container
+using the @code{--share} and @code{--expose} command-line options: the
+former specifies a directory to be shared with write access, while the
+latter provides read-only access to the shared directory.
+The example below creates a container in which the user's home directory
+is accessible read-only, and where the @file{/exchange} directory is a
+read-write mapping of the host's @file{$HOME/tmp}:
+guix system container my-config.scm \
+   --expose=$HOME --share=$HOME/tmp=/exchange
address@hidden example
 @end table
 @var{options} can contain any of the common build options provided by
diff --git a/gnu/system/linux-container.scm b/gnu/system/linux-container.scm
index fdf7460..08513e8 100644
--- a/gnu/system/linux-container.scm
+++ b/gnu/system/linux-container.scm
@@ -106,7 +106,12 @@ that will be shared with the host system."
                 (setenv "TMPDIR" "/tmp")
                 (setenv "GUIX_NEW_SYSTEM" #$os-drv)
                 (for-each mkdir-p '("/run" "/bin" "/etc" "/home" "/var"))
-                (primitive-load (string-append #$os-drv "/boot"))))))
+                (primitive-load (string-append #$os-drv "/boot")))
+              ;; A range of 65536 uid/gids is used to cover 16 bits worth of
+              ;; users and groups, which is sufficient for most cases.
+              ;;
+              ;; See:
+              #:host-uids 65536)))
       (gexp->script "run-container" script
                     #:modules '((ice-9 match)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 4245925..6d99a1f 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -31,6 +31,7 @@
   #:use-module (gnu build install)
   #:use-module (gnu system)
   #:use-module (gnu system file-systems)
+  #:use-module (gnu system linux-container)
   #:use-module (gnu system vm)
   #:use-module (gnu system grub)
   #:use-module (gnu packages grub)
@@ -288,6 +289,8 @@ it atomically, and then run OS's activation script."
   (case action
     ((build init reconfigure)
      (operating-system-derivation os))
+    ((container)
+     (container-script os #:mappings mappings))
      (system-qemu-image os #:disk-image-size image-size))
@@ -327,10 +330,12 @@ boot directly to the kernel or to the bootloader."
                                                 #:full-boot? full-boot?
                                                 #:mappings mappings))
        (grub      (package->derivation grub))
-       (grub.cfg  (operating-system-grub.cfg os
-                                             (if (eq? 'init action)
-                                                 '()
-                                                 (previous-grub-entries))))
+       (grub.cfg  (if (eq? 'container action)
+                      (return #f)
+                      (operating-system-grub.cfg os
+                                                 (if (eq? 'init action)
+                                                     '()
        (drvs   -> (if (and grub? (memq action '(init reconfigure)))
                       (list sys grub grub.cfg)
                       (list sys)))
@@ -385,6 +390,8 @@ Build the operating system declared in FILE according to 
   (display (_ "\
    build            build the operating system without installing anything\n"))
   (display (_ "\
+  container         build a Linux container that shares the host's store\n"))
+  (display (_ "\
    vm               build a virtual machine image that shares the host's 
   (display (_ "\
    vm-image         build a freestanding virtual machine image\n"))
@@ -481,7 +488,7 @@ Build the operating system declared in FILE according to 
         (alist-cons 'argument arg result)
         (let ((action (string->symbol arg)))
           (case action
-            ((build vm vm-image disk-image reconfigure init)
+            ((build container vm vm-image disk-image reconfigure init)
              (alist-cons 'action action result))
             (else (leave (_ "~a: unknown action~%") action))))))
@@ -502,7 +509,7 @@ Build the operating system declared in FILE according to 
       (case action
-        ((build vm vm-image disk-image reconfigure)
+        ((build container vm vm-image disk-image reconfigure)
          (unless (= count 1)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]