image.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu system image)
  20. #:use-module (guix diagnostics)
  21. #:use-module (guix discovery)
  22. #:use-module (guix gexp)
  23. #:use-module (guix modules)
  24. #:use-module (guix monads)
  25. #:use-module (guix records)
  26. #:use-module (guix store)
  27. #:use-module (guix ui)
  28. #:use-module (guix utils)
  29. #:use-module ((guix self) #:select (make-config.scm))
  30. #:use-module (gnu bootloader)
  31. #:use-module (gnu bootloader grub)
  32. #:use-module (gnu image)
  33. #:use-module (gnu platform)
  34. #:use-module (gnu services)
  35. #:use-module (gnu services base)
  36. #:use-module (gnu system)
  37. #:use-module (gnu system file-systems)
  38. #:use-module (gnu system uuid)
  39. #:use-module (gnu system vm)
  40. #:use-module (guix packages)
  41. #:use-module (gnu packages base)
  42. #:use-module (gnu packages bootloaders)
  43. #:use-module (gnu packages cdrom)
  44. #:use-module (gnu packages disk)
  45. #:use-module (gnu packages gawk)
  46. #:use-module (gnu packages genimage)
  47. #:use-module (gnu packages guile)
  48. #:autoload (gnu packages gnupg) (guile-gcrypt)
  49. #:use-module (gnu packages hurd)
  50. #:use-module (gnu packages linux)
  51. #:use-module (gnu packages mtools)
  52. #:use-module (gnu packages virtualization)
  53. #:use-module ((srfi srfi-1) #:prefix srfi-1:)
  54. #:use-module (srfi srfi-11)
  55. #:use-module (srfi srfi-26)
  56. #:use-module (srfi srfi-34)
  57. #:use-module (srfi srfi-35)
  58. #:use-module (rnrs bytevectors)
  59. #:use-module (ice-9 format)
  60. #:use-module (ice-9 match)
  61. #:export (root-offset
  62. root-label
  63. esp-partition
  64. root-partition
  65. efi-disk-image
  66. iso9660-image
  67. raw-with-offset-disk-image
  68. image-with-os
  69. efi-raw-image-type
  70. qcow2-image-type
  71. iso-image-type
  72. uncompressed-iso-image-type
  73. raw-with-offset-image-type
  74. image-with-label
  75. system-image
  76. %image-types
  77. lookup-image-type-by-name))
  78. ;;;
  79. ;;; Images definitions.
  80. ;;;
  81. ;; This is the offset before the first partition. GRUB will install itself in
  82. ;; this post-MBR gap.
  83. (define root-offset (* 512 2048))
  84. ;; Generic root partition label.
  85. (define root-label "Guix_image")
  86. (define esp-partition
  87. (partition
  88. (size (* 40 (expt 2 20)))
  89. (offset root-offset)
  90. (label "GNU-ESP") ;cosmetic only
  91. ;; Use "vfat" here since this property is used when mounting. The actual
  92. ;; FAT-ness is based on file system size (16 in this case).
  93. (file-system "vfat")
  94. (flags '(esp))
  95. (initializer (gexp initialize-efi-partition))))
  96. (define root-partition
  97. (partition
  98. (size 'guess)
  99. (label root-label)
  100. (file-system "ext4")
  101. (flags '(boot))
  102. (initializer (gexp initialize-root-partition))))
  103. (define efi-disk-image
  104. (image
  105. (format 'disk-image)
  106. (partitions (list esp-partition root-partition))))
  107. (define iso9660-image
  108. (image
  109. (format 'iso9660)
  110. (partitions
  111. (list (partition
  112. (size 'guess)
  113. (label "GUIX_IMAGE")
  114. (flags '(boot)))))))
  115. (define* (raw-with-offset-disk-image #:optional (offset root-offset))
  116. (image
  117. (format 'disk-image)
  118. (partitions
  119. (list (partition
  120. (inherit root-partition)
  121. (offset offset))))
  122. ;; FIXME: Deleting and creating "/var/run" and "/tmp" on the overlayfs
  123. ;; fails.
  124. (volatile-root? #f)))
  125. ;;;
  126. ;;; Images types.
  127. ;;;
  128. (define-syntax-rule (image-with-os base-image os)
  129. "Return an image inheriting from BASE-IMAGE, with the operating-system field
  130. set to the given OS."
  131. (image
  132. (inherit base-image)
  133. (operating-system os)))
  134. (define efi-raw-image-type
  135. (image-type
  136. (name 'efi-raw)
  137. (constructor (cut image-with-os efi-disk-image <>))))
  138. (define qcow2-image-type
  139. (image-type
  140. (name 'qcow2)
  141. (constructor (cut image-with-os
  142. (image
  143. (inherit efi-disk-image)
  144. (name 'image.qcow2)
  145. (format 'compressed-qcow2))
  146. <>))))
  147. (define iso-image-type
  148. (image-type
  149. (name 'iso9660)
  150. (constructor (cut image-with-os iso9660-image <>))))
  151. (define uncompressed-iso-image-type
  152. (image-type
  153. (name 'uncompressed-iso9660)
  154. (constructor (cut image-with-os
  155. (image
  156. (inherit iso9660-image)
  157. (compression? #f))
  158. <>))))
  159. (define raw-with-offset-image-type
  160. (image-type
  161. (name 'raw-with-offset)
  162. (constructor (cut image-with-os (raw-with-offset-disk-image) <>))))
  163. ;;
  164. ;; Helpers.
  165. ;;
  166. (define not-config?
  167. ;; Select (guix …) and (gnu …) modules, except (guix config).
  168. (match-lambda
  169. (('guix 'config) #f)
  170. (('guix rest ...) #t)
  171. (('gnu rest ...) #t)
  172. (rest #f)))
  173. (define (partition->gexp partition)
  174. "Turn PARTITION, a <partition> object, into a list-valued gexp suitable for
  175. 'make-partition-image'."
  176. #~'(#$@(list (partition-size partition))
  177. #$(partition-file-system partition)
  178. #$(partition-file-system-options partition)
  179. #$(partition-label partition)
  180. #$(and=> (partition-uuid partition)
  181. uuid-bytevector)))
  182. (define gcrypt-sqlite3&co
  183. ;; Guile-Gcrypt, Guile-SQLite3, and their propagated inputs.
  184. (srfi-1:append-map
  185. (lambda (package)
  186. (cons package
  187. (match (package-transitive-propagated-inputs package)
  188. (((labels packages) ...)
  189. packages))))
  190. (list guile-gcrypt guile-sqlite3)))
  191. (define-syntax-rule (with-imported-modules* gexp* ...)
  192. (with-extensions gcrypt-sqlite3&co
  193. (with-imported-modules `(,@(source-module-closure
  194. '((gnu build vm)
  195. (gnu build image)
  196. (gnu build bootloader)
  197. (gnu build hurd-boot)
  198. (gnu build linux-boot)
  199. (guix store database))
  200. #:select? not-config?)
  201. ((guix config) => ,(make-config.scm)))
  202. #~(begin
  203. (use-modules (gnu build vm)
  204. (gnu build image)
  205. (gnu build bootloader)
  206. (gnu build hurd-boot)
  207. (gnu build linux-boot)
  208. (guix store database)
  209. (guix build utils))
  210. gexp* ...))))
  211. (define (root-partition? partition)
  212. "Return true if PARTITION is the root partition, false otherwise."
  213. (member 'boot (partition-flags partition)))
  214. (define (find-root-partition image)
  215. "Return the root partition of the given IMAGE."
  216. (srfi-1:find root-partition? (image-partitions image)))
  217. (define (root-partition-index image)
  218. "Return the index of the root partition of the given IMAGE."
  219. (1+ (srfi-1:list-index root-partition? (image-partitions image))))
  220. ;;
  221. ;; Disk image.
  222. ;;
  223. (define* (system-disk-image image
  224. #:key
  225. (name "disk-image")
  226. bootcfg
  227. bootloader
  228. register-closures?
  229. (inputs '()))
  230. "Return as a file-like object, the disk-image described by IMAGE. Said
  231. image can be copied on a USB stick as is. BOOTLOADER is the bootloader that
  232. will be installed and configured according to BOOTCFG parameter.
  233. Raw images of the IMAGE partitions are first created. Then, genimage is used
  234. to assemble the partition images into a disk-image without resorting to a
  235. virtual machine.
  236. INPUTS is a list of inputs (as for packages). When REGISTER-CLOSURES? is
  237. true, register INPUTS in the store database of the image so that Guix can be
  238. used in the image."
  239. (define genimage-name "image")
  240. (define (image->genimage-cfg image)
  241. ;; Return as a file-like object, the genimage configuration file
  242. ;; describing the given IMAGE.
  243. (define (format->image-type format)
  244. ;; Return the genimage format corresponding to FORMAT. For now, only
  245. ;; the hdimage format (raw disk-image) is supported.
  246. (cond
  247. ((memq format '(disk-image compressed-qcow2)) "hdimage")
  248. (else
  249. (raise (condition
  250. (&message
  251. (message
  252. (format #f (G_ "Unsupported image type ~a~%.") format))))))))
  253. (define (partition->dos-type partition)
  254. ;; Return the MBR partition type corresponding to the given PARTITION.
  255. ;; See: https://en.wikipedia.org/wiki/Partition_type.
  256. (let ((flags (partition-flags partition)))
  257. (cond
  258. ((member 'esp flags) "0xEF")
  259. (else "0x83"))))
  260. (define (partition-image partition)
  261. ;; Return as a file-like object, an image of the given PARTITION. A
  262. ;; directory, filled by calling the PARTITION initializer procedure, is
  263. ;; first created within the store. Then, an image of this directory is
  264. ;; created using tools such as 'mke2fs' or 'mkdosfs', depending on the
  265. ;; partition file-system type.
  266. (let* ((os (image-operating-system image))
  267. (schema (local-file (search-path %load-path
  268. "guix/store/schema.sql")))
  269. (graph (match inputs
  270. (((names . _) ...)
  271. names)))
  272. (type (partition-file-system partition))
  273. (image-builder
  274. (with-imported-modules*
  275. (let ((initializer #$(partition-initializer partition))
  276. (inputs '#+(list e2fsprogs fakeroot dosfstools mtools))
  277. (image-root "tmp-root"))
  278. (sql-schema #$schema)
  279. (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
  280. ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be
  281. ;; decoded.
  282. (setenv "GUIX_LOCPATH"
  283. #+(file-append glibc-utf8-locales "/lib/locale"))
  284. (setlocale LC_ALL "en_US.utf8")
  285. (initializer image-root
  286. #:references-graphs '#$graph
  287. #:deduplicate? #f
  288. #:system-directory #$os
  289. #:grub-efi #+grub-efi
  290. #:bootloader-package
  291. #+(bootloader-package bootloader)
  292. #:bootloader-installer
  293. #+(bootloader-installer bootloader)
  294. #:bootcfg #$bootcfg
  295. #:bootcfg-location
  296. #$(bootloader-configuration-file bootloader))
  297. (make-partition-image #$(partition->gexp partition)
  298. #$output
  299. image-root)))))
  300. (computed-file "partition.img" image-builder
  301. ;; Allow offloading so that this I/O-intensive process
  302. ;; doesn't run on the build farm's head node.
  303. #:local-build? #f
  304. #:options `(#:references-graphs ,inputs))))
  305. (define (partition->config partition)
  306. ;; Return the genimage partition configuration for PARTITION.
  307. (let ((label (partition-label partition))
  308. (dos-type (partition->dos-type partition))
  309. (image (partition-image partition))
  310. (offset (partition-offset partition)))
  311. #~(format #f "~/partition ~a {
  312. ~/~/partition-type = ~a
  313. ~/~/image = \"~a\"
  314. ~/~/offset = \"~a\"
  315. ~/}"
  316. #$label
  317. #$dos-type
  318. #$image
  319. #$offset)))
  320. (let* ((format (image-format image))
  321. (image-type (format->image-type format))
  322. (partitions (image-partitions image))
  323. (partitions-config (map partition->config partitions))
  324. (builder
  325. #~(begin
  326. (let ((format (@ (ice-9 format) format)))
  327. (call-with-output-file #$output
  328. (lambda (port)
  329. (format port
  330. "\
  331. image ~a {
  332. ~/~a {}
  333. ~{~a~^~%~}
  334. }~%" #$genimage-name #$image-type (list #$@partitions-config))))))))
  335. (computed-file "genimage.cfg" builder)))
  336. (let* ((image-name (image-name image))
  337. (name (if image-name
  338. (symbol->string image-name)
  339. name))
  340. (format (image-format image))
  341. (substitutable? (image-substitutable? image))
  342. (builder
  343. (with-imported-modules*
  344. (let ((inputs '#+(list genimage coreutils findutils qemu-minimal))
  345. (bootloader-installer
  346. #+(bootloader-disk-image-installer bootloader))
  347. (out-image (string-append "images/" #$genimage-name)))
  348. (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
  349. (genimage #$(image->genimage-cfg image))
  350. ;; Install the bootloader directly on the disk-image.
  351. (when bootloader-installer
  352. (bootloader-installer
  353. #+(bootloader-package bootloader)
  354. #$(root-partition-index image)
  355. out-image))
  356. (convert-disk-image out-image '#$format #$output)))))
  357. (computed-file name builder
  358. #:local-build? #f ;too I/O-intensive
  359. #:options `(#:substitutable? ,substitutable?))))
  360. ;;
  361. ;; ISO9660 image.
  362. ;;
  363. (define (has-guix-service-type? os)
  364. "Return true if OS contains a service of the type GUIX-SERVICE-TYPE."
  365. (not (not (srfi-1:find (lambda (service)
  366. (eq? (service-kind service) guix-service-type))
  367. (operating-system-services os)))))
  368. (define* (system-iso9660-image image
  369. #:key
  370. (name "image.iso")
  371. bootcfg
  372. bootloader
  373. register-closures?
  374. (inputs '())
  375. (grub-mkrescue-environment '()))
  376. "Return as a file-like object a bootable, stand-alone iso9660 image.
  377. INPUTS is a list of inputs (as for packages). When REGISTER-CLOSURES? is
  378. true, register INPUTS in the store database of the image so that Guix can be
  379. used in the image. "
  380. (define root-label
  381. (match (image-partitions image)
  382. ((partition)
  383. (partition-label partition))))
  384. (define root-uuid
  385. (match (image-partitions image)
  386. ((partition)
  387. (uuid-bytevector (partition-uuid partition)))))
  388. (let* ((os (image-operating-system image))
  389. (bootloader (bootloader-package bootloader))
  390. (compression? (image-compression? image))
  391. (substitutable? (image-substitutable? image))
  392. (schema (local-file (search-path %load-path
  393. "guix/store/schema.sql")))
  394. (graph (match inputs
  395. (((names . _) ...)
  396. names)))
  397. (builder
  398. (with-imported-modules*
  399. (let* ((inputs '#$(list parted e2fsprogs dosfstools xorriso
  400. sed grep coreutils findutils gawk))
  401. (image-root "tmp-root"))
  402. (sql-schema #$schema)
  403. ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be decoded.
  404. (setenv "GUIX_LOCPATH"
  405. #+(file-append glibc-utf8-locales "/lib/locale"))
  406. (setlocale LC_ALL "en_US.utf8")
  407. (set-path-environment-variable "PATH" '("bin" "sbin") inputs)
  408. (initialize-root-partition image-root
  409. #:references-graphs '#$graph
  410. #:deduplicate? #f
  411. #:system-directory #$os)
  412. (make-iso9660-image #$xorriso
  413. '#$grub-mkrescue-environment
  414. #$bootloader
  415. #$bootcfg
  416. #$os
  417. image-root
  418. #$output
  419. #:references-graphs '#$graph
  420. #:register-closures? #$register-closures?
  421. #:compression? #$compression?
  422. #:volume-id #$root-label
  423. #:volume-uuid #$root-uuid)))))
  424. (computed-file name builder
  425. ;; Allow offloading so that this I/O-intensive process
  426. ;; doesn't run on the build farm's head node.
  427. #:local-build? #f
  428. #:options `(#:references-graphs ,inputs
  429. #:substitutable? ,substitutable?))))
  430. (define (image-with-label base-image label)
  431. "The volume ID of an ISO is the label of the first partition. This procedure
  432. returns an image record where the first partition's label is set to <label>."
  433. (image
  434. (inherit base-image)
  435. (partitions
  436. (match (image-partitions base-image)
  437. ((boot others ...)
  438. (cons
  439. (partition
  440. (inherit boot)
  441. (label label))
  442. others))))))
  443. ;;
  444. ;; Image creation.
  445. ;;
  446. (define (image->root-file-system image)
  447. "Return the IMAGE root partition file-system type."
  448. (let ((format (image-format image)))
  449. (if (eq? format 'iso9660)
  450. "iso9660"
  451. (partition-file-system (find-root-partition image)))))
  452. (define (root-size image)
  453. "Return the root partition size of IMAGE."
  454. (let* ((image-size (image-size image))
  455. (root-partition (find-root-partition image))
  456. (root-size (partition-size root-partition)))
  457. (cond
  458. ((and (eq? root-size 'guess) image-size)
  459. image-size)
  460. (else root-size))))
  461. (define* (image-with-os* base-image os)
  462. "Return an image based on BASE-IMAGE but with the operating-system field set
  463. to OS. Also set the UUID and the size of the root partition."
  464. (define root-file-system
  465. (srfi-1:find
  466. (lambda (fs)
  467. (string=? (file-system-mount-point fs) "/"))
  468. (operating-system-file-systems os)))
  469. (image
  470. (inherit base-image)
  471. (operating-system os)
  472. (partitions
  473. (map (lambda (p)
  474. (if (root-partition? p)
  475. (partition
  476. (inherit p)
  477. (uuid (file-system-device root-file-system))
  478. (size (root-size base-image)))
  479. p))
  480. (image-partitions base-image)))))
  481. (define (operating-system-for-image image)
  482. "Return an operating-system based on the one specified in IMAGE, but
  483. suitable for image creation. Assign an UUID to the root file-system, so that
  484. it can be used for bootloading."
  485. (define volatile-root? (if (eq? (image-format image) 'iso9660)
  486. #t
  487. (image-volatile-root? image)))
  488. (define (root-uuid os)
  489. ;; UUID of the root file system, computed in a deterministic fashion.
  490. ;; This is what we use to locate the root file system so it has to be
  491. ;; different from the user's own file system UUIDs.
  492. (let ((type (if (eq? (image-format image) 'iso9660)
  493. 'iso9660
  494. 'dce)))
  495. (operating-system-uuid os type)))
  496. (let* ((root-file-system-type (image->root-file-system image))
  497. (base-os (image-operating-system image))
  498. (file-systems-to-keep
  499. (srfi-1:remove
  500. (lambda (fs)
  501. (let ((mount-point (file-system-mount-point fs)))
  502. (or (string=? mount-point "/")
  503. (string=? mount-point "/boot/efi"))))
  504. (operating-system-file-systems base-os)))
  505. (format (image-format image))
  506. (os
  507. (operating-system
  508. (inherit base-os)
  509. (initrd (lambda (file-systems . rest)
  510. (apply (operating-system-initrd base-os)
  511. file-systems
  512. #:volatile-root? volatile-root?
  513. rest)))
  514. (bootloader (if (eq? format 'iso9660)
  515. (bootloader-configuration
  516. (inherit
  517. (operating-system-bootloader base-os))
  518. (bootloader grub-mkrescue-bootloader))
  519. (operating-system-bootloader base-os)))
  520. (file-systems (cons (file-system
  521. (mount-point "/")
  522. (device "/dev/placeholder")
  523. (type root-file-system-type))
  524. file-systems-to-keep))))
  525. (uuid (root-uuid os)))
  526. (operating-system
  527. (inherit os)
  528. (file-systems (cons (file-system
  529. (mount-point "/")
  530. (device uuid)
  531. (type root-file-system-type))
  532. file-systems-to-keep)))))
  533. (define* (system-image image)
  534. "Return the derivation of IMAGE. It can be a raw disk-image or an ISO9660
  535. image, depending on IMAGE format."
  536. (define substitutable? (image-substitutable? image))
  537. (define platform (image-platform image))
  538. ;; The image platform definition may provide the appropriate "system"
  539. ;; architecture for the image. If we are already running on this system,
  540. ;; the image can be built natively. If we are running on a different
  541. ;; system, then we need to cross-compile, using the "target" provided by the
  542. ;; image definition.
  543. (define system (and=> platform platform-system))
  544. (define target (cond
  545. ;; No defined platform, let's use the user defined
  546. ;; system/target parameters.
  547. ((not platform)
  548. (%current-target-system))
  549. ;; The current system is the same as the platform system, no
  550. ;; need to cross-compile.
  551. ((and system
  552. (string=? system (%current-system)))
  553. #f)
  554. ;; If there is a user defined target let's override the
  555. ;; platform target. Otherwise, we can cross-compile to the
  556. ;; platform target.
  557. (else
  558. (or (%current-target-system)
  559. (and=> platform platform-target)))))
  560. (with-parameters ((%current-target-system target))
  561. (let* ((os (operating-system-for-image image))
  562. (image* (image-with-os* image os))
  563. (image-format (image-format image))
  564. (register-closures? (has-guix-service-type? os))
  565. (bootcfg (operating-system-bootcfg os))
  566. (bootloader (bootloader-configuration-bootloader
  567. (operating-system-bootloader os))))
  568. (cond
  569. ((memq image-format '(disk-image compressed-qcow2))
  570. (system-disk-image image*
  571. #:bootcfg bootcfg
  572. #:bootloader bootloader
  573. #:register-closures? register-closures?
  574. #:inputs `(("system" ,os)
  575. ("bootcfg" ,bootcfg))))
  576. ((memq image-format '(iso9660))
  577. (system-iso9660-image
  578. image*
  579. #:bootcfg bootcfg
  580. #:bootloader bootloader
  581. #:register-closures? register-closures?
  582. #:inputs `(("system" ,os)
  583. ("bootcfg" ,bootcfg))
  584. ;; Make sure to use a mode that does no imply
  585. ;; HFS+ tree creation that may fail with:
  586. ;;
  587. ;; "libisofs: FAILURE : Too much files to mangle,
  588. ;; cannot guarantee unique file names"
  589. ;;
  590. ;; This happens if some limits are exceeded, see:
  591. ;; https://lists.gnu.org/archive/html/grub-devel/2020-06/msg00048.html
  592. #:grub-mkrescue-environment
  593. '(("MKRESCUE_SED_MODE" . "mbr_only"))))))))
  594. ;;
  595. ;; Image detection.
  596. ;;
  597. (define (image-modules)
  598. "Return the list of image modules."
  599. (cons (resolve-interface '(gnu system image))
  600. (all-modules (map (lambda (entry)
  601. `(,entry . "gnu/system/images/"))
  602. %load-path)
  603. #:warn warn-about-load-error)))
  604. (define %image-types
  605. ;; The list of publically-known image types.
  606. (delay (fold-module-public-variables (lambda (obj result)
  607. (if (image-type? obj)
  608. (cons obj result)
  609. result))
  610. '()
  611. (image-modules))))
  612. (define (lookup-image-type-by-name name)
  613. "Return the image type called NAME."
  614. (or (srfi-1:find (lambda (image-type)
  615. (eq? name (image-type-name image-type)))
  616. (force %image-types))
  617. (raise
  618. (formatted-message (G_ "~a: no such image type") name))))
  619. ;;; image.scm ends here