Commit | Line | Data |
---|---|---|
f19cf27c MO |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
19 | (define-module (gnu image) | |
dab819d5 | 20 | #:use-module (guix platform) |
f19cf27c | 21 | #:use-module (guix records) |
0dab106a LC |
22 | #:use-module (guix diagnostics) |
23 | #:use-module (guix i18n) | |
24 | #:use-module (srfi srfi-34) | |
25 | #:use-module (srfi srfi-35) | |
f19cf27c MO |
26 | #:export (partition |
27 | partition? | |
28 | partition-device | |
29 | partition-size | |
1b4fa785 | 30 | partition-offset |
f19cf27c | 31 | partition-file-system |
bd3716f6 | 32 | partition-file-system-options |
f19cf27c MO |
33 | partition-label |
34 | partition-uuid | |
35 | partition-flags | |
36 | partition-initializer | |
37 | ||
38 | image | |
4cce7610 | 39 | image? |
f19cf27c MO |
40 | image-name |
41 | image-format | |
d5073fd1 | 42 | image-platform |
f19cf27c MO |
43 | image-size |
44 | image-operating-system | |
096a2bf8 | 45 | image-partition-table-type |
f19cf27c MO |
46 | image-partitions |
47 | image-compression? | |
48 | image-volatile-root? | |
594e9428 | 49 | image-shared-store? |
dcc843a7 | 50 | image-shared-network? |
99d036ce MO |
51 | image-substitutable? |
52 | ||
53 | image-type | |
54 | image-type? | |
55 | image-type-name | |
56 | image-type-constructor | |
57 | ||
d5073fd1 MO |
58 | os->image |
59 | os+platform->image)) | |
f19cf27c MO |
60 | |
61 | \f | |
62 | ;;; | |
63 | ;;; Partition record. | |
64 | ;;; | |
65 | ||
66 | (define-record-type* <partition> partition make-partition | |
67 | partition? | |
bd3716f6 MO |
68 | (device partition-device (default #f)) |
69 | (size partition-size) | |
70 | (offset partition-offset (default 0)) | |
71 | (file-system partition-file-system (default "ext4")) | |
72 | (file-system-options partition-file-system-options | |
73 | (default '())) | |
74 | (label partition-label (default #f)) | |
75 | (uuid partition-uuid (default #f)) | |
76 | (flags partition-flags (default '())) | |
9f530ef3 | 77 | (initializer partition-initializer (default #f))) ;gexp | #f |
f19cf27c MO |
78 | |
79 | \f | |
80 | ;;; | |
81 | ;;; Image record. | |
82 | ;;; | |
83 | ||
0dab106a LC |
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) | |
89 | (raise | |
90 | (make-compound-condition | |
91 | (condition | |
92 | (&error-location | |
93 | (location (source-properties->location properties)))) | |
94 | (formatted-message (G_ "~s: invalid '~a' value") value 'field)))) | |
95 | value)) | |
96 | ||
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 | |
100 | (mbr gpt)) | |
101 | ||
f19cf27c MO |
102 | (define-record-type* <image> |
103 | image make-image | |
104 | image? | |
b904b59c MO |
105 | (name image-name ;symbol |
106 | (default #f)) | |
0dab106a LC |
107 | (format image-format ;symbol |
108 | (sanitize validate-image-format)) | |
d5073fd1 | 109 | (platform image-platform ;<platform> |
f292d471 | 110 | (default #f)) |
f19cf27c MO |
111 | (size image-size ;size in bytes as integer |
112 | (default 'guess)) | |
113 | (operating-system image-operating-system ;<operating-system> | |
114 | (default #f)) | |
096a2bf8 | 115 | (partition-table-type image-partition-table-type ; 'mbr or 'gpt |
0dab106a LC |
116 | (default 'mbr) |
117 | (sanitize validate-partition-table-type)) | |
f19cf27c MO |
118 | (partitions image-partitions ;list of <partition> |
119 | (default '())) | |
120 | (compression? image-compression? ;boolean | |
121 | (default #t)) | |
122 | (volatile-root? image-volatile-root? ;boolean | |
123 | (default #t)) | |
594e9428 MO |
124 | (shared-store? image-shared-store? ;boolean |
125 | (default #f)) | |
dcc843a7 MO |
126 | (shared-network? image-shared-network? ;boolean |
127 | (default #f)) | |
f19cf27c MO |
128 | (substitutable? image-substitutable? ;boolean |
129 | (default #t))) | |
99d036ce MO |
130 | |
131 | \f | |
132 | ;;; | |
133 | ;;; Image type. | |
134 | ;;; | |
135 | ||
136 | (define-record-type* <image-type> | |
137 | image-type make-image-type | |
138 | image-type? | |
139 | (name image-type-name) ;symbol | |
140 | (constructor image-type-constructor)) ;<operating-system> -> <image> | |
141 | ||
142 | \f | |
143 | ;;; | |
144 | ;;; Image creation. | |
145 | ;;; | |
146 | ||
147 | (define* (os->image os #:key type) | |
148 | (let ((constructor (image-type-constructor type))) | |
149 | (constructor os))) | |
d5073fd1 MO |
150 | |
151 | (define* (os+platform->image os platform #:key type) | |
152 | (image | |
153 | (inherit (os->image os #:type type)) | |
154 | (platform platform))) |