scripts: system: Add support for image-type.

* guix/scripts/system.scm (list-image-types): New procedure,
(%options): add "image-type" and "list-image-types" options, remove
"file-system-type" option,
(show-help): adapt accordingly,
(%default-options): also adapt, and set the default "image-type" to "raw",
(perform-action): add image-type argument and remove file-system-type argument,
(process-action):  adapt perform-action call,
(system-derivation-for-action): remove base-image
argument, add image-type argument, and use it to create the image passed to
"system-image".
* tests/guix-system.sh: Adapt accordingly and add a test for
"--list-image-types" command.
* doc/guix.texi (Building the Installation Image,
Invoking guix system): Adapt accordingly.

Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
This commit is contained in:
Mathieu Othacehe 2020-07-31 16:49:29 +02:00 committed by Mathieu Othacehe
parent 10b135cef5
commit 313f492657
No known key found for this signature in database
GPG key ID: 8354763531769CA6
4 changed files with 75 additions and 52 deletions

View file

@ -833,9 +833,8 @@ release: dist-with-updated-version
-v1 --no-grafts --fallback -v1 --no-grafts --fallback
for system in $(GUIX_SYSTEM_SUPPORTED_SYSTEMS) ; do \ for system in $(GUIX_SYSTEM_SUPPORTED_SYSTEMS) ; do \
image=`$(top_builddir)/pre-inst-env \ image=`$(top_builddir)/pre-inst-env \
guix system disk-image \ guix system disk-image -t iso9660 \
--file-system-type=iso9660 \ --label="GUIX_$${system}_$(VERSION)" \
--label="GUIX_$${system}_$(VERSION)" \
--system=$$system --fallback \ --system=$$system --fallback \
gnu/system/install.scm` ; \ gnu/system/install.scm` ; \
if [ ! -f "$$image" ] ; then \ if [ ! -f "$$image" ] ; then \

View file

@ -40,7 +40,7 @@ Copyright @copyright{} 2016, 2017, 2018, 2019, 2020 Julien Lepiller@*
Copyright @copyright{} 2016 Alex ter Weele@* Copyright @copyright{} 2016 Alex ter Weele@*
Copyright @copyright{} 2016, 2017, 2018, 2019 Christopher Baines@* Copyright @copyright{} 2016, 2017, 2018, 2019 Christopher Baines@*
Copyright @copyright{} 2017, 2018, 2019 Clément Lassieur@* Copyright @copyright{} 2017, 2018, 2019 Clément Lassieur@*
Copyright @copyright{} 2017, 2018 Mathieu Othacehe@* Copyright @copyright{} 2017, 2018, 2020 Mathieu Othacehe@*
Copyright @copyright{} 2017 Federico Beffa@* Copyright @copyright{} 2017 Federico Beffa@*
Copyright @copyright{} 2017, 2018 Carlo Zancanaro@* Copyright @copyright{} 2017, 2018 Carlo Zancanaro@*
Copyright @copyright{} 2017 Thomas Danckaert@* Copyright @copyright{} 2017 Thomas Danckaert@*
@ -2568,8 +2568,7 @@ The installation image described above was built using the @command{guix
system} command, specifically: system} command, specifically:
@example @example
guix system disk-image --file-system-type=iso9660 \ guix system disk-image -t iso9660 gnu/system/install.scm
gnu/system/install.scm
@end example @end example
Have a look at @file{gnu/system/install.scm} in the source tree, Have a look at @file{gnu/system/install.scm} in the source tree,
@ -29375,24 +29374,28 @@ a value. Docker images are built to contain exactly what they need, so
the @option{--image-size} option is ignored in the case of the @option{--image-size} option is ignored in the case of
@code{docker-image}. @code{docker-image}.
You can specify the root file system type by using the The @code{disk-image} command can produce various image types. The
@option{--file-system-type} option. It defaults to @code{ext4}. When its image type can be selected using the @command{--image-type} option. It
value is @code{iso9660}, the @option{--label} option can be used to specify defaults to @code{raw}. When its value is @code{iso9660}, the
a volume ID with @code{disk-image}. @option{--label} option can be used to specify a volume ID with
@code{disk-image}.
When using @code{vm-image}, the returned image is in qcow2 format, which When using the @code{raw} image type, a raw disk image is produced; it
the QEMU emulator can efficiently use. @xref{Running Guix in a VM}, can be copied as is to a USB stick, for instance. Assuming
for more information on how to run the image in a virtual machine. @code{/dev/sdc} is the device corresponding to a USB stick, one can copy
the image to it using the following command:
When using @code{disk-image}, a raw disk image is produced; it can be
copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
the device corresponding to a USB stick, one can copy the image to it
using the following command:
@example @example
# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc status=progress # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc status=progress
@end example @end example
The @code{--list-image-types} command lists all the available image
types.
When using @code{vm-image}, the returned image is in qcow2 format, which
the QEMU emulator can efficiently use. @xref{Running Guix in a VM},
for more information on how to run the image in a virtual machine.
When using @code{docker-image}, a Docker image is produced. Guix builds When using @code{docker-image}, a Docker image is produced. Guix builds
the image from scratch, not from a pre-existing Docker base image. As a the image from scratch, not from a pre-existing Docker base image. As a
result, it contains @emph{exactly} what you define in the operating result, it contains @emph{exactly} what you define in the operating
@ -29494,17 +29497,17 @@ information, one can rebuild the image to make sure it really contains
what it pretends to contain; or they could use that to derive a variant what it pretends to contain; or they could use that to derive a variant
of the image. of the image.
@item --file-system-type=@var{type} @item --image-type=@var{type}
@itemx -t @var{type} @itemx -t @var{type}
For the @code{disk-image} action, create a file system of the given For the @code{disk-image} action, create an image with given @var{type}.
@var{type} on the image.
When this option is omitted, @command{guix system} uses @code{ext4}. When this option is omitted, @command{guix system} uses the @code{raw}
image type.
@cindex ISO-9660 format @cindex ISO-9660 format
@cindex CD image format @cindex CD image format
@cindex DVD image format @cindex DVD image format
@option{--file-system-type=iso9660} produces an ISO-9660 image, suitable @option{--image-type=iso9660} produces an ISO-9660 image, suitable
for burning on CDs and DVDs. for burning on CDs and DVDs.
@item --image-size=@var{size} @item --image-size=@var{size}

View file

@ -666,8 +666,8 @@ (define file-systems
;;; Action. ;;; Action.
;;; ;;;
(define* (system-derivation-for-action os base-image action (define* (system-derivation-for-action os action
#:key image-size file-system-type #:key image-size image-type
full-boot? container-shared-network? full-boot? container-shared-network?
mappings label) mappings label)
"Return as a monadic value the derivation for OS according to ACTION." "Return as a monadic value the derivation for OS according to ACTION."
@ -690,12 +690,15 @@ (define* (system-derivation-for-action os base-image action
(* 70 (expt 2 20))) (* 70 (expt 2 20)))
#:mappings mappings)) #:mappings mappings))
((disk-image) ((disk-image)
(lower-object (let ((base-image (os->image os #:type image-type)))
(system-image (lower-object
(image (system-image
(inherit (if label (image-with-label base-image label) base-image)) (image
(size image-size) (inherit (if label
(operating-system os))))) (image-with-label base-image label)
base-image))
(size image-size)
(operating-system os))))))
((docker-image) ((docker-image)
(system-docker-image os #:shared-network? container-shared-network?)))) (system-docker-image os #:shared-network? container-shared-network?))))
@ -748,18 +751,19 @@ (define* (perform-action action os
install-bootloader? install-bootloader?
dry-run? derivations-only? dry-run? derivations-only?
use-substitutes? bootloader-target target use-substitutes? bootloader-target target
image-size file-system-type full-boot? label image-size image-type
container-shared-network? full-boot? label container-shared-network?
(mappings '()) (mappings '())
(gc-root #f)) (gc-root #f))
"Perform ACTION for OS. INSTALL-BOOTLOADER? specifies whether to install "Perform ACTION for OS. INSTALL-BOOTLOADER? specifies whether to install
bootloader; BOOTLOADER-TAGET is the target for the bootloader; TARGET is the bootloader; BOOTLOADER-TAGET is the target for the bootloader; TARGET is the
target root directory; IMAGE-SIZE is the size of the image to be built, for target root directory; IMAGE-SIZE is the size of the image to be built, for
the 'vm-image' and 'disk-image' actions. The root file system is created as a the 'vm-image' and 'disk-image' actions. IMAGE-TYPE is the type of image to
FILE-SYSTEM-TYPE file system. FULL-BOOT? is used for the 'vm' action; it be built.
determines whether to boot directly to the kernel or to the bootloader.
CONTAINER-SHARED-NETWORK? determines if the container will use a separate FULL-BOOT? is used for the 'vm' action; it determines whether to
network namespace. boot directly to the kernel or to the bootloader. CONTAINER-SHARED-NETWORK?
determines if the container will use a separate network namespace.
When DERIVATIONS-ONLY? is true, print the derivation file name(s) without When DERIVATIONS-ONLY? is true, print the derivation file name(s) without
building anything. building anything.
@ -799,11 +803,9 @@ (define bootcfg
(check-initrd-modules os))) (check-initrd-modules os)))
(mlet* %store-monad (mlet* %store-monad
((target* (current-target-system)) ((sys (system-derivation-for-action os action
(image -> (find-image file-system-type target*))
(sys (system-derivation-for-action os image action
#:label label #:label label
#:file-system-type file-system-type #:image-type image-type
#:image-size image-size #:image-size image-size
#:full-boot? full-boot? #:full-boot? full-boot?
#:container-shared-network? container-shared-network? #:container-shared-network? container-shared-network?
@ -886,6 +888,17 @@ (define (export-shepherd-graph os port)
#:node-type (shepherd-service-node-type shepherds) #:node-type (shepherd-service-node-type shepherds)
#:reverse-edges? #t))) #:reverse-edges? #t)))
;;;
;;; Images.
;;;
(define (list-image-types)
"Print the available image types."
(display (G_ "The available image types are:\n"))
(newline)
(format #t "~{ - ~a ~%~}" (map image-type-name (force %image-types))))
;;; ;;;
;;; Options. ;;; Options.
@ -945,9 +958,9 @@ (define (show-help)
apply STRATEGY (one of nothing-special, backtrace, apply STRATEGY (one of nothing-special, backtrace,
or debug) when an error occurs while reading FILE")) or debug) when an error occurs while reading FILE"))
(display (G_ " (display (G_ "
--file-system-type=TYPE --list-image-types list available image types"))
for 'disk-image', produce a root file system of TYPE (display (G_ "
(one of 'ext4', 'iso9660')")) -t, --image-type=TYPE for 'disk-image', produce an image of TYPE"))
(display (G_ " (display (G_ "
--image-size=SIZE for 'vm-image', produce an image of SIZE")) --image-size=SIZE for 'vm-image', produce an image of SIZE"))
(display (G_ " (display (G_ "
@ -1008,10 +1021,14 @@ (define %options
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'on-error (string->symbol arg) (alist-cons 'on-error (string->symbol arg)
result))) result)))
(option '(#\t "file-system-type") #t #f (option '(#\t "image-type") #t #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'file-system-type arg (alist-cons 'image-type (string->symbol arg)
result))) result)))
(option '("list-image-types") #f #f
(lambda (opt name arg result)
(list-image-types)
(exit 0)))
(option '("image-size") #t #f (option '("image-size") #t #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'image-size (size->number arg) (alist-cons 'image-size (size->number arg)
@ -1080,7 +1097,7 @@ (define %default-options
(debug . 0) (debug . 0)
(verbosity . #f) ;default (verbosity . #f) ;default
(validate-reconfigure . ,ensure-forward-reconfigure) (validate-reconfigure . ,ensure-forward-reconfigure)
(file-system-type . "ext4") (image-type . raw)
(image-size . guess) (image-size . guess)
(install-bootloader? . #t) (install-bootloader? . #t)
(label . #f))) (label . #f)))
@ -1177,7 +1194,8 @@ (define save-provenance?
(assoc-ref opts 'skip-safety-checks?) (assoc-ref opts 'skip-safety-checks?)
#:validate-reconfigure #:validate-reconfigure
(assoc-ref opts 'validate-reconfigure) (assoc-ref opts 'validate-reconfigure)
#:file-system-type (assoc-ref opts 'file-system-type) #:image-type (lookup-image-type-by-name
(assoc-ref opts 'image-type))
#:image-size (assoc-ref opts 'image-size) #:image-size (assoc-ref opts 'image-size)
#:full-boot? (assoc-ref opts 'full-boot?) #:full-boot? (assoc-ref opts 'full-boot?)
#:container-shared-network? #:container-shared-network?

View file

@ -261,8 +261,8 @@ guix system vm "$tmpfile" -d | grep '\.drv$'
drv1="`guix system vm "$tmpfile" -d`" drv1="`guix system vm "$tmpfile" -d`"
drv2="`guix system vm "$tmpfile" -d`" drv2="`guix system vm "$tmpfile" -d`"
test "$drv1" = "$drv2" test "$drv1" = "$drv2"
drv1="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`" drv1="`guix system disk-image -t iso9660 "$tmpfile" -d`"
drv2="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`" drv2="`guix system disk-image -t iso9660 "$tmpfile" -d`"
test "$drv1" = "$drv2" test "$drv1" = "$drv2"
make_user_config "group-that-does-not-exist" "users" make_user_config "group-that-does-not-exist" "users"
@ -320,5 +320,8 @@ guix system -n vm gnu/system/examples/vm-image.tmpl
guix system -n vm-image gnu/system/examples/vm-image.tmpl guix system -n vm-image gnu/system/examples/vm-image.tmpl
# This invocation was taken care of in the loop above: # This invocation was taken care of in the loop above:
# guix system -n disk-image gnu/system/examples/bare-bones.tmpl # guix system -n disk-image gnu/system/examples/bare-bones.tmpl
guix system -n disk-image --file-system-type=iso9660 gnu/system/examples/bare-bones.tmpl guix system -n disk-image -t iso9660 gnu/system/examples/bare-bones.tmpl
guix system -n docker-image gnu/system/examples/docker-image.tmpl guix system -n docker-image gnu/system/examples/docker-image.tmpl
# Verify that at least the raw image type is available.
guix system --list-image-types | grep "raw"