image.scm 24 KB

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