1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu image)
20 #:use-module (guix platform)
21 #:use-module (guix records)
22 #:use-module (guix diagnostics)
23 #:use-module (guix i18n)
24 #:use-module (srfi srfi-34)
25 #:use-module (srfi srfi-35)
32 partition-file-system-options
44 image-operating-system
45 image-partition-table-type
56 image-type-constructor
66 (define-record-type* <partition> partition make-partition
68 (device partition-device (default #f))
70 (offset partition-offset (default 0))
71 (file-system partition-file-system (default "ext4"))
72 (file-system-options partition-file-system-options
74 (label partition-label (default #f))
75 (uuid partition-uuid (default #f))
76 (flags partition-flags (default '()))
77 (initializer partition-initializer (default #f))) ;gexp | #f
84 (define-syntax-rule (define-set-sanitizer name field set)
85 "Define NAME as a procedure or macro that raises an error if passed a value
86 that is not in SET, mentioning FIELD in the error message."
87 (define-with-syntax-properties (name (value properties))
88 (unless (memq value 'set)
90 (make-compound-condition
93 (location (source-properties->location properties))))
94 (formatted-message (G_ "~s: invalid '~a' value") value 'field))))
97 (define-set-sanitizer validate-image-format format
98 (disk-image compressed-qcow2 docker iso9660))
99 (define-set-sanitizer validate-partition-table-type partition-table-type
102 (define-record-type* <image>
105 (name image-name ;symbol
107 (format image-format ;symbol
108 (sanitize validate-image-format))
109 (platform image-platform ;<platform>
111 (size image-size ;size in bytes as integer
113 (operating-system image-operating-system ;<operating-system>
115 (partition-table-type image-partition-table-type ; 'mbr or 'gpt
117 (sanitize validate-partition-table-type))
118 (partitions image-partitions ;list of <partition>
120 (compression? image-compression? ;boolean
122 (volatile-root? image-volatile-root? ;boolean
124 (shared-store? image-shared-store? ;boolean
126 (shared-network? image-shared-network? ;boolean
128 (substitutable? image-substitutable? ;boolean
136 (define-record-type* <image-type>
137 image-type make-image-type
139 (name image-type-name) ;symbol
140 (constructor image-type-constructor)) ;<operating-system> -> <image>
147 (define* (os->image os #:key type)
148 (let ((constructor (image-type-constructor type)))
151 (define* (os+platform->image os platform #:key type)
153 (inherit (os->image os #:type type))
154 (platform platform)))