1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2020, 2021, 2022 Mathieu Othacehe <othacehe@gnu.org>
3 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
4 ;;; Copyright © 2022 Pavel Shlyak <p.shlyak@pantherx.org>
5 ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
6 ;;; Copyright © 2022 Alex Griffin <a@ajgrf.com>
8 ;;; This file is part of GNU Guix.
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23 (define-module (gnu system image)
24 #:use-module (guix diagnostics)
25 #:use-module (guix discovery)
26 #:use-module (guix gexp)
27 #:use-module (guix modules)
28 #:use-module (guix monads)
29 #:use-module (guix records)
30 #:use-module (guix store)
31 #:use-module (guix ui)
32 #:use-module (guix utils)
33 #:use-module ((guix self) #:select (make-config.scm))
34 #:use-module (gnu bootloader)
35 #:use-module (gnu bootloader grub)
36 #:use-module (gnu compression)
37 #:use-module (gnu image)
38 #:use-module (guix platform)
39 #:use-module (gnu services)
40 #:use-module (gnu services base)
41 #:use-module (gnu system)
42 #:use-module (gnu system accounts)
43 #:use-module (gnu system file-systems)
44 #:use-module (gnu system linux-container)
45 #:use-module (gnu system uuid)
46 #:use-module (gnu system vm)
47 #:use-module (guix packages)
48 #:use-module (gnu packages base)
49 #:use-module (gnu packages bash)
50 #:use-module (gnu packages bootloaders)
51 #:use-module (gnu packages cdrom)
52 #:use-module (gnu packages compression)
53 #:use-module (gnu packages disk)
54 #:use-module (gnu packages gawk)
55 #:use-module (gnu packages genimage)
56 #:use-module (gnu packages guile)
57 #:autoload (gnu packages gnupg) (guile-gcrypt)
58 #:use-module (gnu packages hurd)
59 #:use-module (gnu packages linux)
60 #:use-module (gnu packages mtools)
61 #:use-module (gnu packages virtualization)
62 #:use-module ((srfi srfi-1) #:prefix srfi-1:)
63 #:use-module (srfi srfi-11)
64 #:use-module (srfi srfi-26)
65 #:use-module (srfi srfi-34)
66 #:use-module (srfi srfi-35)
67 #:use-module (rnrs bytevectors)
68 #:use-module (ice-9 format)
69 #:use-module (ice-9 match)
83 raw-with-offset-disk-image
90 uncompressed-iso-image-type
94 raw-with-offset-image-type
100 lookup-image-type-by-name))
104 ;;; Images definitions.
107 ;; This is the offset before the first partition. GRUB will install itself in
108 ;; this post-MBR gap.
109 (define root-offset (* 512 2048))
111 ;; Generic root partition label.
112 (define root-label "Guix_image")
114 (define-syntax-rule (image-without-os . fields)
115 "Return an image record with the mandatory operating-system field set to
116 #false. This is useful when creating an image record that will serve as a
117 parent image record."
118 (image (operating-system #false) . fields))
120 (define esp-partition
122 (size (* 40 (expt 2 20)))
124 (label "GNU-ESP") ;cosmetic only
125 ;; Use "vfat" here since this property is used when mounting. The actual
126 ;; FAT-ness is based on file system size (16 in this case).
129 (initializer (gexp initialize-efi-partition))))
131 (define esp32-partition
133 (inherit esp-partition)
134 (initializer (gexp initialize-efi32-partition))))
136 (define root-partition
142 (initializer (gexp initialize-root-partition))))
144 (define efi-disk-image
147 (partitions (list esp-partition root-partition))))
149 (define efi32-disk-image
152 (partitions (list esp32-partition root-partition))))
154 (define iso9660-image
167 (define tarball-image
175 (define* (raw-with-offset-disk-image #:optional (offset root-offset))
180 (inherit root-partition)
182 ;; FIXME: Deleting and creating "/var/run" and "/tmp" on the overlayfs
184 (volatile-root? #f)))
191 (define-syntax-rule (image-with-os base-image os)
192 "Return an image inheriting from BASE-IMAGE, with the operating-system field
193 set to the given OS."
196 (operating-system os)))
198 (define efi-raw-image-type
201 (constructor (cut image-with-os efi-disk-image <>))))
203 (define efi32-raw-image-type
206 (constructor (cut image-with-os efi32-disk-image <>))))
208 (define qcow2-image-type
211 (constructor (cut image-with-os
213 (inherit efi-disk-image)
215 (format 'compressed-qcow2))
218 (define iso-image-type
221 (constructor (cut image-with-os iso9660-image <>))))
223 (define uncompressed-iso-image-type
225 (name 'uncompressed-iso9660)
226 (constructor (cut image-with-os
228 (inherit iso9660-image)
232 (define docker-image-type
235 (constructor (cut image-with-os docker-image <>))))
237 (define tarball-image-type
240 (constructor (cut image-with-os tarball-image <>))))
242 (define wsl2-image-type
245 (constructor (cut image-with-os wsl2-image <>))))
247 (define raw-with-offset-image-type
249 (name 'raw-with-offset)
250 (constructor (cut image-with-os (raw-with-offset-disk-image) <>))))
258 ;; Select (guix …) and (gnu …) modules, except (guix config).
261 (('guix rest ...) #t)
265 (define (partition->gexp partition)
266 "Turn PARTITION, a <partition> object, into a list-valued gexp suitable for
267 'make-partition-image'."
268 #~'(#$@(list (partition-size partition))
269 #$(partition-file-system partition)
270 #$(partition-file-system-options partition)
271 #$(partition-label partition)
272 #$(and=> (partition-uuid partition)
274 #$(partition-flags partition)))
276 (define gcrypt-sqlite3&co
277 ;; Guile-Gcrypt, Guile-SQLite3, and their propagated inputs.
281 (match (package-transitive-propagated-inputs package)
282 (((labels packages) ...)
284 (list guile-gcrypt guile-sqlite3)))
286 (define-syntax-rule (with-imported-modules* gexp* ...)
287 (with-extensions gcrypt-sqlite3&co
288 (with-imported-modules `(,@(source-module-closure
290 (gnu build bootloader)
291 (gnu build hurd-boot)
292 (gnu build linux-boot)
293 (guix store database))
294 #:select? not-config?)
295 ((guix config) => ,(make-config.scm)))
297 (use-modules (gnu build image)
298 (gnu build bootloader)
299 (gnu build hurd-boot)
300 (gnu build linux-boot)
301 (guix store database)
305 (define (root-partition? partition)
306 "Return true if PARTITION is the root partition, false otherwise."
307 (member 'boot (partition-flags partition)))
309 (define (find-root-partition image)
310 "Return the root partition of the given IMAGE."
311 (or (srfi-1:find root-partition? (image-partitions image))
312 (raise (formatted-message
313 (G_ "image lacks a partition with the 'boot' flag")))))
315 (define (root-partition-index image)
316 "Return the index of the root partition of the given IMAGE."
317 (1+ (srfi-1:list-index root-partition? (image-partitions image))))
324 (define* (system-disk-image image
331 "Return as a file-like object, the disk-image described by IMAGE. Said
332 image can be copied on a USB stick as is. BOOTLOADER is the bootloader that
333 will be installed and configured according to BOOTCFG parameter.
335 Raw images of the IMAGE partitions are first created. Then, genimage is used
336 to assemble the partition images into a disk-image without resorting to a
339 INPUTS is a list of inputs (as for packages). When REGISTER-CLOSURES? is
340 true, register INPUTS in the store database of the image so that Guix can be
343 (define genimage-name "image")
345 (define (image->genimage-cfg image)
346 ;; Return as a file-like object, the genimage configuration file
347 ;; describing the given IMAGE.
348 (define (format->image-type format)
349 ;; Return the genimage format corresponding to FORMAT. For now, only
350 ;; the hdimage format (raw disk-image) is supported.
352 ((memq format '(disk-image compressed-qcow2)) "hdimage")
357 (format #f (G_ "unsupported image type: ~a")
360 (define (partition->dos-type partition)
361 ;; Return the MBR partition type corresponding to the given PARTITION.
362 ;; See: https://en.wikipedia.org/wiki/Partition_type.
363 (let ((flags (partition-flags partition))
364 (file-system (partition-file-system partition)))
366 ((member 'esp flags) "0xEF")
367 ((string-prefix? "ext" file-system) "0x83")
368 ((or (string=? file-system "vfat")
369 (string=? file-system "fat16")) "0x0E")
370 ((string=? file-system "fat32") "0x0C")
375 (format #f (G_ "unsupported partition type: ~a")
378 (define (partition->gpt-type partition)
379 ;; Return the genimage GPT partition type code corresponding to the
380 ;; given PARTITION. See:
381 ;; https://github.com/pengutronix/genimage/blob/master/README.rst
382 (let ((flags (partition-flags partition))
383 (file-system (partition-file-system partition)))
385 ((member 'esp flags) "U")
386 ((string-prefix? "ext" file-system) "L")
387 ((or (string=? file-system "vfat")
388 (string=? file-system "fat16")
389 (string=? file-system "fat32")) "F")
394 (format #f (G_ "unsupported partition type: ~a")
397 (define (partition-image partition)
398 ;; Return as a file-like object, an image of the given PARTITION. A
399 ;; directory, filled by calling the PARTITION initializer procedure, is
400 ;; first created within the store. Then, an image of this directory is
401 ;; created using tools such as 'mke2fs' or 'mkdosfs', depending on the
402 ;; partition file-system type.
403 (let* ((os (image-operating-system image))
404 (schema (local-file (search-path %load-path
405 "guix/store/schema.sql")))
409 (type (partition-file-system partition))
411 (with-imported-modules*
412 (let ((initializer (or #$(partition-initializer partition)
413 initialize-root-partition))
414 (inputs '#+(list e2fsprogs fakeroot dosfstools mtools))
415 (image-root "tmp-root"))
416 (sql-schema #$schema)
418 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
420 ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be
422 (setenv "GUIX_LOCPATH"
423 #+(file-append glibc-utf8-locales "/lib/locale"))
424 (setlocale LC_ALL "en_US.utf8")
426 (initializer image-root
427 #:references-graphs '#$graph
429 #:copy-closures? (not
430 #$(image-shared-store? image))
431 #:system-directory #$os
432 #:grub-efi #+grub-efi
433 #:grub-efi32 #+grub-efi32
435 #+(bootloader-package bootloader)
436 #:bootloader-installer
437 #+(bootloader-installer bootloader)
440 #$(bootloader-configuration-file bootloader))
441 (make-partition-image #$(partition->gexp partition)
444 (computed-file "partition.img" image-builder
445 ;; Allow offloading so that this I/O-intensive process
446 ;; doesn't run on the build farm's head node.
448 #:options `(#:references-graphs ,inputs))))
450 (define (gpt-image? image)
451 (eq? 'gpt (image-partition-table-type image)))
453 (define (partition-type-values image partition)
454 (if (gpt-image? image)
455 (values "partition-type-uuid" (partition->gpt-type partition))
456 (values "partition-type" (partition->dos-type partition))))
458 (define (partition->config image partition)
459 ;; Return the genimage partition configuration for PARTITION.
460 (let-values (((partition-type-attribute partition-type-value)
461 (partition-type-values image partition)))
462 (let ((label (partition-label partition))
463 (image (partition-image partition))
464 (offset (partition-offset partition))
465 (bootable (if (memq 'boot (partition-flags partition))
467 #~(format #f "~/partition ~a {
471 ~/~/bootable = \"~a\"
474 #$partition-type-attribute
475 #$partition-type-value
480 (define (genimage-type-options image-type image)
482 ((equal? image-type "hdimage")
483 (format #f "~%~/~/partition-table-type = \"~a\"~%~/"
484 (image-partition-table-type image)))
487 (let* ((format (image-format image))
488 (image-type (format->image-type format))
489 (image-type-options (genimage-type-options image-type image))
490 (partitions (image-partitions image))
491 (partitions-config (map (cut partition->config image <>) partitions))
494 (let ((format (@ (ice-9 format) format)))
495 (call-with-output-file #$output
502 }~%" #$genimage-name #$image-type #$image-type-options
503 (list #$@partitions-config))))))))
504 (computed-file "genimage.cfg" builder)))
506 (let* ((image-name (image-name image))
508 (symbol->string image-name)
510 (format (image-format image))
511 (substitutable? (image-substitutable? image))
513 (with-imported-modules*
514 (let ((inputs '#+(list genimage coreutils findutils qemu-minimal))
515 (bootloader-installer
516 #+(bootloader-disk-image-installer bootloader))
517 (out-image (string-append "images/" #$genimage-name)))
518 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
519 (genimage #$(image->genimage-cfg image))
520 ;; Install the bootloader directly on the disk-image.
521 (when bootloader-installer
522 (bootloader-installer
523 #+(bootloader-package bootloader)
524 #$(root-partition-index image)
526 (convert-disk-image out-image '#$format #$output)))))
527 (computed-file name builder
528 #:local-build? #f ;too I/O-intensive
529 #:options `(#:substitutable? ,substitutable?))))
536 (define (has-guix-service-type? os)
537 "Return true if OS contains a service of the type GUIX-SERVICE-TYPE."
538 (not (not (srfi-1:find (lambda (service)
539 (eq? (service-kind service) guix-service-type))
540 (operating-system-services os)))))
542 (define* (system-iso9660-image image
549 (grub-mkrescue-environment '()))
550 "Return as a file-like object a bootable, stand-alone iso9660 image.
552 INPUTS is a list of inputs (as for packages). When REGISTER-CLOSURES? is
553 true, register INPUTS in the store database of the image so that Guix can be
556 (match (image-partitions image)
558 (partition-label partition))))
561 (match (image-partitions image)
563 (uuid-bytevector (partition-uuid partition)))))
565 (let* ((os (image-operating-system image))
566 (bootloader (bootloader-package bootloader))
567 (compression? (image-compression? image))
568 (substitutable? (image-substitutable? image))
569 (schema (local-file (search-path %load-path
570 "guix/store/schema.sql")))
575 (with-imported-modules*
576 (let* ((inputs '#$(list parted e2fsprogs dosfstools xorriso
577 sed grep coreutils findutils gawk))
578 (image-root "tmp-root"))
579 (sql-schema #$schema)
581 ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be decoded.
582 (setenv "GUIX_LOCPATH"
583 #+(file-append glibc-utf8-locales "/lib/locale"))
585 (setlocale LC_ALL "en_US.utf8")
587 (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
589 (initialize-root-partition image-root
590 #:references-graphs '#$graph
592 #:system-directory #$os)
593 (make-iso9660-image #$xorriso
594 '#$grub-mkrescue-environment
600 #:references-graphs '#$graph
601 #:register-closures? #$register-closures?
602 #:compression? #$compression?
603 #:volume-id #$root-label
604 #:volume-uuid #$root-uuid)))))
605 (computed-file name builder
606 ;; Allow offloading so that this I/O-intensive process
607 ;; doesn't run on the build farm's head node.
609 #:options `(#:references-graphs ,inputs
610 #:substitutable? ,substitutable?))))
612 (define (image-with-label base-image label)
613 "The volume ID of an ISO is the label of the first partition. This procedure
614 returns an image record where the first partition's label is set to <label>."
618 (match (image-partitions base-image)
631 (define* (system-docker-image image
633 (name "docker-image"))
634 "Build a docker image for IMAGE. NAME is the base name to use for the
637 ;; Program that runs the boot script of OS, which in turn starts shepherd.
638 (program-file "boot-program"
639 #~(let ((system (cadr (command-line))))
640 (setenv "GUIX_NEW_SYSTEM" system)
641 (execl #$(file-append guile-3.0 "/bin/guile")
642 "guile" "--no-auto-compile"
643 (string-append system "/boot")))))
645 (define shared-network?
646 (image-shared-network? image))
648 (let* ((os (operating-system-with-gc-roots
649 (containerized-operating-system
650 (image-operating-system image) '()
653 (list boot-program)))
654 (substitutable? (image-substitutable? image))
655 (image-target (or (%current-target-system)
656 (nix-system->gnu-triplet)))
657 (register-closures? (has-guix-service-type? os))
658 (schema (and register-closures?
659 (local-file (search-path %load-path
660 "guix/store/schema.sql"))))
661 (name (string-append name ".tar.gz"))
662 (graph "system-graph"))
664 (with-extensions (cons guile-json-3 ;for (guix docker)
665 gcrypt-sqlite3&co) ;for (guix store database)
666 (with-imported-modules `(,@(source-module-closure
668 (guix store database)
670 (guix build store-copy)
672 #:select? not-config?)
673 ((guix config) => ,(make-config.scm)))
675 (use-modules (guix docker)
679 (guix build store-copy)
680 (guix store database))
682 ;; Set the SQL schema location.
683 (sql-schema #$schema)
685 ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be decoded.
686 (setenv "GUIX_LOCPATH"
687 #+(file-append glibc-utf8-locales "/lib/locale"))
688 (setlocale LC_ALL "en_US.utf8")
690 (set-path-environment-variable "PATH" '("bin" "sbin") '(#+tar))
692 (let ((image-root (string-append (getcwd) "/tmp-root")))
694 (initialize-root-partition image-root
695 #:references-graphs '(#$graph)
697 #:register-closures? #$register-closures?
699 #:system-directory #$os)
704 (call-with-input-file #$graph
705 read-reference-graph)))
707 #:entry-point '(#$boot-program #$os)
708 #:compressor '(#+(file-append gzip "/bin/gzip") "-9n")
709 #:creation-time (make-time time-utc 0 1)
710 #:system #$image-target
711 #:transformations `((,image-root -> ""))))))))
713 (computed-file name builder
714 ;; Allow offloading so that this I/O-intensive process
715 ;; doesn't run on the build farm's head node.
717 #:options `(#:references-graphs ((,graph ,os))
718 #:substitutable? ,substitutable?))))
725 ;; TODO: Some bits can be factorized with (guix scripts pack).
726 (define* (system-tarball-image image
729 (compressor (srfi-1:first %compressors))
731 "Build a tarball of IMAGE. NAME is the base name to use for the
733 (let* ((os (image-operating-system image))
734 (substitutable? (image-substitutable? image))
735 (schema (local-file (search-path %load-path
736 "guix/store/schema.sql")))
737 (name (string-append name ".tar" (compressor-extension compressor)))
738 (graph "system-graph")
739 (root (srfi-1:find (lambda (user)
740 (and=> (user-account-uid user) zero?))
741 (operating-system-users os)))
742 (root-shell (or (and=> root user-account-shell)
743 (file-append bash "/bin/bash"))))
745 (with-extensions gcrypt-sqlite3&co ;for (guix store database)
746 (with-imported-modules `(,@(source-module-closure
748 (guix build store-copy)
750 (guix store database)
752 #:select? not-config?)
753 ((guix config) => ,(make-config.scm)))
755 (use-modules (guix build pack)
756 (guix build store-copy)
758 (guix store database)
761 ;; Set the SQL schema location.
762 (sql-schema #$schema)
764 ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be decoded.
765 (setenv "GUIX_LOCPATH"
766 #+(file-append glibc-utf8-locales "/lib/locale"))
767 (setlocale LC_ALL "en_US.utf8")
769 (let ((image-root (string-append (getcwd) "/tmp-root"))
770 (tar #+(file-append tar "/bin/tar")))
773 (initialize-root-partition image-root
774 #:references-graphs '(#$graph)
776 #:system-directory #$os)
778 (with-directory-excursion image-root
780 #~(;; WSL requires /bin/sh. Will be overwritten by
781 ;; system activation.
782 (symlink #$root-shell "./bin/sh")
784 ;; WSL requires /bin/mount to access the host fs.
785 (symlink #$(file-append util-linux "/bin/mount")
789 (apply invoke tar "-cvf" #$output "."
793 #+(and=> compressor compressor-command)))))))))
795 (computed-file name builder
796 ;; Allow offloading so that this I/O-intensive process
797 ;; doesn't run on the build farm's head node.
799 #:options `(#:references-graphs ((,graph ,os))
800 #:substitutable? ,substitutable?))))
807 (define (image->root-file-system image)
808 "Return the IMAGE root partition file-system type."
809 (case (image-format image)
810 ((iso9660) "iso9660")
811 ((docker tarball wsl2) "dummy")
813 (partition-file-system (find-root-partition image)))))
815 (define (root-size image)
816 "Return the root partition size of IMAGE."
817 (let* ((image-size (image-size image))
818 (root-partition (find-root-partition image))
819 (root-size (partition-size root-partition)))
821 ((and (eq? root-size 'guess) image-size)
825 (define* (image-with-os* base-image os)
826 "Return an image based on BASE-IMAGE but with the operating-system field set
827 to OS. Also set the UUID and the size of the root partition."
828 (define root-file-system
831 (string=? (file-system-mount-point fs) "/"))
832 (operating-system-file-systems os)))
836 (operating-system os)
839 (if (root-partition? p)
842 (uuid (file-system-device root-file-system))
843 (size (root-size base-image)))
845 (image-partitions base-image)))))
847 (define (operating-system-for-image image)
848 "Return an operating-system based on the one specified in IMAGE, but
849 suitable for image creation. Assign an UUID to the root file-system, so that
850 it can be used for bootloading."
851 (define volatile-root? (if (eq? (image-format image) 'iso9660)
853 (image-volatile-root? image)))
855 (define (root-uuid os)
856 ;; UUID of the root file system, computed in a deterministic fashion.
857 ;; This is what we use to locate the root file system so it has to be
858 ;; different from the user's own file system UUIDs.
859 (let ((type (if (eq? (image-format image) 'iso9660)
862 (operating-system-uuid os type)))
864 (let* ((root-file-system-type (image->root-file-system image))
865 (base-os (image-operating-system image))
866 (file-systems-to-keep
869 (let ((mount-point (file-system-mount-point fs)))
870 (or (string=? mount-point "/")
871 (string=? mount-point "/boot/efi"))))
872 (operating-system-file-systems base-os)))
873 (format (image-format image))
877 (initrd (lambda (file-systems . rest)
878 (apply (operating-system-initrd base-os)
880 #:volatile-root? volatile-root?
882 (bootloader (if (eq? format 'iso9660)
883 (bootloader-configuration
885 (operating-system-bootloader base-os))
886 (bootloader grub-mkrescue-bootloader))
887 (operating-system-bootloader base-os)))
888 (file-systems (cons (file-system
890 (device "/dev/placeholder")
891 (type root-file-system-type))
892 file-systems-to-keep))))
893 (uuid (root-uuid os)))
896 (file-systems (cons (file-system
899 (type root-file-system-type))
900 file-systems-to-keep)))))
902 (define* (system-image image)
903 "Return the derivation of IMAGE. It can be a raw disk-image or an ISO9660
904 image, depending on IMAGE format."
905 (define platform (image-platform image))
907 ;; The image platform definition may provide the appropriate "system"
908 ;; architecture for the image. If we are already running on this system,
909 ;; the image can be built natively. If we are running on a different
910 ;; system, then we need to cross-compile, using the "target" provided by the
912 (define system (and=> platform platform-system))
914 ;; No defined platform, let's use the user defined
915 ;; system/target parameters.
917 (%current-target-system))
918 ;; The current system is the same as the platform system, no
919 ;; need to cross-compile.
921 (string=? system (%current-system)))
923 ;; If there is a user defined target let's override the
924 ;; platform target. Otherwise, we can cross-compile to the
927 (or (%current-target-system)
928 (and=> platform platform-target)))))
930 (with-parameters ((%current-target-system target))
931 (let* ((os (operating-system-for-image image))
932 (image* (image-with-os* image os))
933 (image-format (image-format image))
934 (register-closures? (has-guix-service-type? os))
935 (bootcfg (operating-system-bootcfg os))
936 (bootloader (bootloader-configuration-bootloader
937 (operating-system-bootloader os))))
939 ((memq image-format '(disk-image compressed-qcow2))
940 (system-disk-image image*
942 #:bootloader bootloader
943 #:register-closures? register-closures?
944 #:inputs `(("system" ,os)
945 ("bootcfg" ,bootcfg))))
946 ((memq image-format '(docker))
947 (system-docker-image image*))
948 ((memq image-format '(tarball))
949 (system-tarball-image image*))
950 ((memq image-format '(wsl2))
951 (system-tarball-image image* #:wsl? #t))
952 ((memq image-format '(iso9660))
953 (system-iso9660-image
956 #:bootloader bootloader
957 #:register-closures? register-closures?
958 #:inputs `(("system" ,os)
959 ("bootcfg" ,bootcfg))
960 ;; Make sure to use a mode that does no imply
961 ;; HFS+ tree creation that may fail with:
963 ;; "libisofs: FAILURE : Too much files to mangle,
964 ;; cannot guarantee unique file names"
966 ;; This happens if some limits are exceeded, see:
967 ;; https://lists.gnu.org/archive/html/grub-devel/2020-06/msg00048.html
968 #:grub-mkrescue-environment
969 '(("MKRESCUE_SED_MODE" . "mbr_only"))))
971 (raise (formatted-message
972 (G_ "~a: unsupported image format") image-format)))))))
979 (define (image-modules)
980 "Return the list of image modules."
981 (cons (resolve-interface '(gnu system image))
982 (all-modules (map (lambda (entry)
983 `(,entry . "gnu/system/images/"))
985 #:warn warn-about-load-error)))
988 ;; The list of publically-known image types.
989 (delay (fold-module-public-variables (lambda (obj result)
990 (if (image-type? obj)
996 (define (lookup-image-type-by-name name)
997 "Return the image type called NAME."
998 (or (srfi-1:find (lambda (image-type)
999 (eq? name (image-type-name image-type)))
1000 (force %image-types))
1002 (formatted-message (G_ "~a: no such image type") name))))
1004 ;;; image.scm ends here