From: guix-patches--- via <guix-patches@gnu.org>
To: othacehe@gnu.org
Cc: 45957@debbugs.gnu.org, Joshua Branson <jbranso@dismail.de>
Subject: [bug#45957] [PATCH] * doc/guix-cookbook.texi (Guix System Image API): new section
Date: Wed, 20 Jan 2021 12:12:54 -0500 [thread overview]
Message-ID: <20210120171254.3403-1-jbranso@dismail.de> (raw)
In-Reply-To: <87o8hjzrk3.fsf@gnu.org>
---
doc/guix-cookbook.texi | 222 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 222 insertions(+)
diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi
index 54ab99558e..3971edf83f 100644
--- a/doc/guix-cookbook.texi
+++ b/doc/guix-cookbook.texi
@@ -1353,6 +1353,7 @@ reference.
@menu
* Customizing the Kernel:: Creating and using a custom Linux kernel on Guix System.
+* Guix System Image API:: Customizing disk images to target specific platforms.
* Connecting to Wireguard VPN:: Connecting to a Wireguard VPN.
* Customizing a Window Manager:: Handle customization of a Window manager on Guix System.
* Running Guix on a Linode Server:: Running Guix on a Linode Server
@@ -1601,6 +1602,227 @@ likely that you'll need to modify the initrd on a machine using a custom
kernel, since certain modules which are expected to be built may not be
available for inclusion into the initrd.
+@node Guix System Image API
+@section Guix System Image API
+
+Historically, Guix System is centered around an @code{operating-system}
+structure. This structure contains various fields ranging from the
+bootloader and kernel declaration to the services to install. This is
+useful to create an installer image, but the new Guix System image API
+makes it possible to create an image that the user boots into directly.
+For example, an image that targets the Beagleboard or PinePhone
+directly.
+
+Turning an @code{operating-system} structure into a image requires
+additional information such as the image label, size and
+partitioning. To this end, we can use the new @code{image} record.
+
+@lisp
+(define-record-type* <image>
+ image make-image
+ image?
+ (name image-name ;symbol
+ (default #f))
+ (format image-format) ;symbol
+ (target image-target
+ (default #f))
+ (size image-size ;size in bytes as integer
+ (default 'guess))
+ (operating-system image-operating-system ;<operating-system>
+ (default #f))
+ (partitions image-partitions ;list of <partition>
+ (default '()))
+ (compression? image-compression? ;boolean
+ (default #t))
+ (volatile-root? image-volatile-root? ;boolean
+ (default #t))
+ (substitutable? image-substitutable? ;boolean
+ (default #t)))
+@end lisp
+
+This record also contains the operating-system to instantiate. The
+@code{format} field defines the image type and can be @code{disk-image},
+@code{compressed-qcow2} or @code{iso9660}. In the future, it could be
+extended to @code{docker} or other image types.
+
+A new directory in the Guix sources is dedicated to images definition. For now
+there are four files:
+
+@itemize @bullet
+@item
+@file{gnu/system/images/hurd.scm}
+
+@item
+@file{gnu/system/images/pine64.scm}
+
+@item
+@file{gnu/guix/guix-src/gnu/system/images/novena.scm}
+
+@item
+@file{gnu/guix/guix-src/gnu/system/images/pinebook-pro.scm}
+
+@end itemize
+
+Let's have a look to @file{pine64.scm}. It contains the
+@code{pine64-barebones-os} variable which is a minimal definition of an
+operating-system dedicated to the @b{Pine A64 LTS} board.
+
+@lisp
+(define pine64-barebones-os
+ (operating-system
+ (host-name "vignemale")
+ (timezone "Europe/Paris")
+ (locale "en_US.utf8")
+ (bootloader (bootloader-configuration
+ (bootloader u-boot-pine64-lts-bootloader)
+ (target "/dev/vda")))
+ (initrd-modules '())
+ (kernel linux-libre-arm64-generic)
+ (file-systems (cons (file-system
+ (device (file-system-label "my-root"))
+ (mount-point "/")
+ (type "ext4"))
+ %base-file-systems))
+ (services (cons (service agetty-service-type
+ (agetty-configuration
+ (extra-options '("-L")) ; no carrier detect
+ (baud-rate "115200")
+ (term "vt100")
+ (tty "ttyS0")))
+ %base-services))))
+@end lisp
+
+The @code{kernel} and @code{bootloader} fields are pointing to packages
+dedicated to this board.
+
+Right below, the @code{pine64-image-type} variable is also defined.
+
+@lisp
+(define pine64-image-type
+ (image-type
+ (name 'pine64-raw)
+ (constructor (cut image-with-os arm64-disk-image <>))))
+@end lisp
+
+It's using a record we haven't talked about yet, the @code{image-type} record,
+defined this way:
+
+@lisp
+(define-record-type* <image-type>
+ image-type make-image-type
+ image-type?
+ (name image-type-name) ;symbol
+ (constructor image-type-constructor)) ;<operating-system> -> <image>
+@end lisp
+
+The main purpose of this record is to associate a name to a procedure
+transforming an @code{operating-system} to an image. To understand why
+it is necessary, let's have a look to the command producing an image
+from an @code{operating-system} configuration file:
+
+@example
+guix system image my-os.scm
+@end example
+
+This command expects an @code{operating-system} configuration but how
+should we indicate that we want an image targeting a Pine64 board? We
+need to provide an extra information, the @code{image-type}, by passing
+the @code{--image-type} or @code{-t} flag, this way:
+
+@example
+guix system image --image-type=pine64-raw my-os.scm
+@end example
+
+This @code{image-type} parameter points to the @code{pine64-image-type}
+defined above. Hence, the @code{operating-system} declared in
+@code{my-os.scm} will be applied the @code{(cut image-with-os
+arm64-disk-image <>)} procedure to turn it into an image.
+
+The resulting image looks like:
+
+@lisp
+(image
+ (format 'disk-image)
+ (target "aarch64-linux-gnu")
+ (operating-system my-os)
+ (partitions
+ (list (partition
+ (inherit root-partition)
+ (offset root-offset)))))
+@end lisp
+
+which is the aggregation of the @code{operating-system} defined in
+ @code{my-os.scm} to the @code{arm64-disk-image} record.
+
+But enough Scheme madness. What does this image API bring to the Guix user?
+
+One can run:
+
+@example
+mathieu@@cervin:~$ guix system --list-image-types
+The available image types are:
+
+ - pinebook-pro-raw
+ - pine64-raw
+ - novena-raw
+ - hurd-raw
+ - hurd-qcow2
+ - qcow2
+ - uncompressed-iso9660
+ - raw
+ - arm64-raw
+ - arm32-raw
+ - iso9660
+@end example
+
+and by writing an @code{operating-system} file based on
+@code{pine64-barebones-os} (or @code{hurd-barebones-os}) you could
+customize your image to your preferences in a file
+(@file{my-pine-os.scm}) like this:
+
+@lisp
+(use-modules
+ (srfi srfi-9)
+ (srfi srfi-9 gnu)
+ (gnu services linux)
+ (gnu system images pine64))
+
+(define my-pine64-barebones-os
+ (set-fields pine64-barebones-os
+ ((operating-system-timezone) "America/Indiana/Indianapolis")
+ ((operating-system-user-services)
+ (cons*
+ (service earlyoom-service-type
+ (earlyoom-configuration
+ (prefer-regexp "icecat|chromium|firefox")))
+ (operating-system-user-services pine64-barebones-os)))))
+
+my-pine64-barebones-os
+@end lisp
+
+run:
+
+@example
+guix system --image-type=pine64-raw my-pine-os.scm
+@end example
+
+or,
+
+@example
+guix system image --image-type=hurd-raw my-hurd-os.scm
+@end example
+
+to get an image that can be written directly to a hard drive and booted
+from.
+
+Without changing anything to @code{my-hurd-os.scm}, calling:
+
+@example
+guix system image --image-type=hurd-qcow2 my-hurd-os.scm
+@end example
+
+will instead produce a Hurd QEMU image.
+
@node Connecting to Wireguard VPN
@section Connecting to Wireguard VPN
--
2.30.0
next prev parent reply other threads:[~2021-01-20 17:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-13 14:33 Single-board-computer approach: don't make an installer, make the install? Christopher Lemmer Webber
2021-01-13 14:51 ` Mathieu Othacehe
2021-01-13 15:53 ` Christopher Lemmer Webber
2021-01-13 19:55 ` Joshua Branson via
2021-01-14 3:42 ` Christopher Lemmer Webber
2021-01-14 8:54 ` Mathieu Othacehe
2021-01-14 18:05 ` Joshua Branson via
2021-01-17 13:10 ` [PATCH] * doc/guix-cookbook.texi (Guix System Image API): new section Joshua Branson
2021-01-18 13:29 ` Mathieu Othacehe
2021-01-18 16:08 ` Joshua Branson
2021-01-18 16:38 ` jbranso--- via
2021-01-18 17:53 ` [bug#45957] (no subject) guix-patches--- via
2021-01-20 13:06 ` Mathieu Othacehe
2021-01-20 17:12 ` guix-patches--- via [this message]
2021-01-21 11:14 ` [bug#45957] [PATCH] * doc/guix-cookbook.texi (Guix System Image API): new section Mathieu Othacehe
2021-01-21 12:22 ` [bug#45957] learning git-send-email is interesting guix-patches--- via
2021-01-21 12:22 ` [bug#45957] [PATCH] * doc/guix-cookbook.texi (Guix System Image API): new section guix-patches--- via
2021-01-21 13:41 ` bug#45957: " Mathieu Othacehe
2021-01-20 17:17 ` [bug#45957] (no subject) guix-patches--- via
2021-01-21 12:33 ` [bug#45957] thanks guix-patches--- via
2021-01-21 20:39 ` Single-board-computer approach: don't make an installer, make the install? Joshua Branson
2021-01-22 13:32 ` Mathieu Othacehe
2021-03-21 13:51 ` Joshua Branson
2021-03-29 7:39 ` Mathieu Othacehe
2021-03-31 16:40 ` Joshua Branson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210120171254.3403-1-jbranso@dismail.de \
--to=guix-patches@gnu.org \
--cc=45957@debbugs.gnu.org \
--cc=jbranso@dismail.de \
--cc=othacehe@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.