2020-04-28 12:15:28 +00:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
|
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu image)
|
2022-05-23 20:37:26 +00:00
|
|
|
|
#:use-module (guix platform)
|
2020-04-28 12:15:28 +00:00
|
|
|
|
#:use-module (guix records)
|
2022-07-01 10:06:39 +00:00
|
|
|
|
#:use-module (guix diagnostics)
|
|
|
|
|
#:use-module (guix i18n)
|
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
|
#:use-module (srfi srfi-35)
|
2020-04-28 12:15:28 +00:00
|
|
|
|
#:export (partition
|
|
|
|
|
partition?
|
|
|
|
|
partition-device
|
|
|
|
|
partition-size
|
2020-05-20 14:09:53 +00:00
|
|
|
|
partition-offset
|
2020-04-28 12:15:28 +00:00
|
|
|
|
partition-file-system
|
2020-05-26 14:25:25 +00:00
|
|
|
|
partition-file-system-options
|
2020-04-28 12:15:28 +00:00
|
|
|
|
partition-label
|
|
|
|
|
partition-uuid
|
|
|
|
|
partition-flags
|
|
|
|
|
partition-initializer
|
|
|
|
|
|
|
|
|
|
image
|
2021-01-20 11:06:56 +00:00
|
|
|
|
image?
|
2020-04-28 12:15:28 +00:00
|
|
|
|
image-name
|
|
|
|
|
image-format
|
2021-08-30 16:24:27 +00:00
|
|
|
|
image-platform
|
2020-04-28 12:15:28 +00:00
|
|
|
|
image-size
|
|
|
|
|
image-operating-system
|
2021-11-04 08:35:11 +00:00
|
|
|
|
image-partition-table-type
|
2020-04-28 12:15:28 +00:00
|
|
|
|
image-partitions
|
|
|
|
|
image-compression?
|
|
|
|
|
image-volatile-root?
|
2021-12-16 07:45:01 +00:00
|
|
|
|
image-shared-store?
|
2021-12-16 08:25:49 +00:00
|
|
|
|
image-shared-network?
|
2020-07-31 14:49:27 +00:00
|
|
|
|
image-substitutable?
|
|
|
|
|
|
|
|
|
|
image-type
|
|
|
|
|
image-type?
|
|
|
|
|
image-type-name
|
|
|
|
|
image-type-constructor
|
|
|
|
|
|
2021-08-30 16:24:27 +00:00
|
|
|
|
os->image
|
|
|
|
|
os+platform->image))
|
2020-04-28 12:15:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Partition record.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define-record-type* <partition> partition make-partition
|
|
|
|
|
partition?
|
2020-05-26 14:25:25 +00:00
|
|
|
|
(device partition-device (default #f))
|
|
|
|
|
(size partition-size)
|
|
|
|
|
(offset partition-offset (default 0))
|
|
|
|
|
(file-system partition-file-system (default "ext4"))
|
|
|
|
|
(file-system-options partition-file-system-options
|
|
|
|
|
(default '()))
|
|
|
|
|
(label partition-label (default #f))
|
|
|
|
|
(uuid partition-uuid (default #f))
|
|
|
|
|
(flags partition-flags (default '()))
|
2022-07-01 08:26:17 +00:00
|
|
|
|
(initializer partition-initializer (default #f))) ;gexp | #f
|
2020-04-28 12:15:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Image record.
|
|
|
|
|
;;;
|
|
|
|
|
|
2022-07-01 10:06:39 +00:00
|
|
|
|
(define-syntax-rule (define-set-sanitizer name field set)
|
|
|
|
|
"Define NAME as a procedure or macro that raises an error if passed a value
|
|
|
|
|
that is not in SET, mentioning FIELD in the error message."
|
|
|
|
|
(define-with-syntax-properties (name (value properties))
|
|
|
|
|
(unless (memq value 'set)
|
|
|
|
|
(raise
|
|
|
|
|
(make-compound-condition
|
|
|
|
|
(condition
|
|
|
|
|
(&error-location
|
|
|
|
|
(location (source-properties->location properties))))
|
|
|
|
|
(formatted-message (G_ "~s: invalid '~a' value") value 'field))))
|
|
|
|
|
value))
|
|
|
|
|
|
|
|
|
|
(define-set-sanitizer validate-image-format format
|
|
|
|
|
(disk-image compressed-qcow2 docker iso9660))
|
|
|
|
|
(define-set-sanitizer validate-partition-table-type partition-table-type
|
|
|
|
|
(mbr gpt))
|
|
|
|
|
|
2020-04-28 12:15:28 +00:00
|
|
|
|
(define-record-type* <image>
|
|
|
|
|
image make-image
|
|
|
|
|
image?
|
2020-06-13 15:33:10 +00:00
|
|
|
|
(name image-name ;symbol
|
|
|
|
|
(default #f))
|
2022-07-01 10:06:39 +00:00
|
|
|
|
(format image-format ;symbol
|
|
|
|
|
(sanitize validate-image-format))
|
2021-08-30 16:24:27 +00:00
|
|
|
|
(platform image-platform ;<platform>
|
2020-06-13 12:01:18 +00:00
|
|
|
|
(default #f))
|
2020-04-28 12:15:28 +00:00
|
|
|
|
(size image-size ;size in bytes as integer
|
|
|
|
|
(default 'guess))
|
|
|
|
|
(operating-system image-operating-system ;<operating-system>
|
|
|
|
|
(default #f))
|
2021-11-04 08:35:11 +00:00
|
|
|
|
(partition-table-type image-partition-table-type ; 'mbr or 'gpt
|
2022-07-01 10:06:39 +00:00
|
|
|
|
(default 'mbr)
|
|
|
|
|
(sanitize validate-partition-table-type))
|
2020-04-28 12:15:28 +00:00
|
|
|
|
(partitions image-partitions ;list of <partition>
|
|
|
|
|
(default '()))
|
|
|
|
|
(compression? image-compression? ;boolean
|
|
|
|
|
(default #t))
|
|
|
|
|
(volatile-root? image-volatile-root? ;boolean
|
|
|
|
|
(default #t))
|
2021-12-16 07:45:01 +00:00
|
|
|
|
(shared-store? image-shared-store? ;boolean
|
|
|
|
|
(default #f))
|
2021-12-16 08:25:49 +00:00
|
|
|
|
(shared-network? image-shared-network? ;boolean
|
|
|
|
|
(default #f))
|
2020-04-28 12:15:28 +00:00
|
|
|
|
(substitutable? image-substitutable? ;boolean
|
|
|
|
|
(default #t)))
|
2020-07-31 14:49:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Image type.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define-record-type* <image-type>
|
|
|
|
|
image-type make-image-type
|
|
|
|
|
image-type?
|
|
|
|
|
(name image-type-name) ;symbol
|
|
|
|
|
(constructor image-type-constructor)) ;<operating-system> -> <image>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Image creation.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define* (os->image os #:key type)
|
|
|
|
|
(let ((constructor (image-type-constructor type)))
|
|
|
|
|
(constructor os)))
|
2021-08-30 16:24:27 +00:00
|
|
|
|
|
|
|
|
|
(define* (os+platform->image os platform #:key type)
|
|
|
|
|
(image
|
|
|
|
|
(inherit (os->image os #:type type))
|
|
|
|
|
(platform platform)))
|