summaryrefslogtreecommitdiff
path: root/gnu/system
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/system')
-rw-r--r--gnu/system/image.scm37
1 files changed, 34 insertions, 3 deletions
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index d60649b6e35..2eec6fcbab2 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -39,12 +39,14 @@
39 #:use-module (gnu services) 39 #:use-module (gnu services)
40 #:use-module (gnu services base) 40 #:use-module (gnu services base)
41 #:use-module (gnu system) 41 #:use-module (gnu system)
42 #:use-module (gnu system accounts)
42 #:use-module (gnu system file-systems) 43 #:use-module (gnu system file-systems)
43 #:use-module (gnu system linux-container) 44 #:use-module (gnu system linux-container)
44 #:use-module (gnu system uuid) 45 #:use-module (gnu system uuid)
45 #:use-module (gnu system vm) 46 #:use-module (gnu system vm)
46 #:use-module (guix packages) 47 #:use-module (guix packages)
47 #:use-module (gnu packages base) 48 #:use-module (gnu packages base)
49 #:use-module (gnu packages bash)
48 #:use-module (gnu packages bootloaders) 50 #:use-module (gnu packages bootloaders)
49 #:use-module (gnu packages cdrom) 51 #:use-module (gnu packages cdrom)
50 #:use-module (gnu packages compression) 52 #:use-module (gnu packages compression)
@@ -77,6 +79,7 @@
77 iso9660-image 79 iso9660-image
78 docker-image 80 docker-image
79 tarball-image 81 tarball-image
82 wsl2-image
80 raw-with-offset-disk-image 83 raw-with-offset-disk-image
81 84
82 image-with-os 85 image-with-os
@@ -87,6 +90,7 @@
87 uncompressed-iso-image-type 90 uncompressed-iso-image-type
88 docker-image-type 91 docker-image-type
89 tarball-image-type 92 tarball-image-type
93 wsl2-image-type
90 raw-with-offset-image-type 94 raw-with-offset-image-type
91 95
92 image-with-label 96 image-with-label
@@ -164,6 +168,10 @@ parent image record."
164 (image-without-os 168 (image-without-os
165 (format 'tarball))) 169 (format 'tarball)))
166 170
171(define wsl2-image
172 (image-without-os
173 (format 'wsl2)))
174
167(define* (raw-with-offset-disk-image #:optional (offset root-offset)) 175(define* (raw-with-offset-disk-image #:optional (offset root-offset))
168 (image-without-os 176 (image-without-os
169 (format 'disk-image) 177 (format 'disk-image)
@@ -231,6 +239,11 @@ set to the given OS."
231 (name 'tarball) 239 (name 'tarball)
232 (constructor (cut image-with-os tarball-image <>)))) 240 (constructor (cut image-with-os tarball-image <>))))
233 241
242(define wsl2-image-type
243 (image-type
244 (name 'wsl2)
245 (constructor (cut image-with-os wsl2-image <>))))
246
234(define raw-with-offset-image-type 247(define raw-with-offset-image-type
235 (image-type 248 (image-type
236 (name 'raw-with-offset) 249 (name 'raw-with-offset)
@@ -709,7 +722,8 @@ output file."
709(define* (system-tarball-image image 722(define* (system-tarball-image image
710 #:key 723 #:key
711 (name "image") 724 (name "image")
712 (compressor (srfi-1:first %compressors))) 725 (compressor (srfi-1:first %compressors))
726 (wsl? #f))
713 "Build a tarball of IMAGE. NAME is the base name to use for the 727 "Build a tarball of IMAGE. NAME is the base name to use for the
714output file." 728output file."
715 (let* ((os (image-operating-system image)) 729 (let* ((os (image-operating-system image))
@@ -717,7 +731,12 @@ output file."
717 (schema (local-file (search-path %load-path 731 (schema (local-file (search-path %load-path
718 "guix/store/schema.sql"))) 732 "guix/store/schema.sql")))
719 (name (string-append name ".tar" (compressor-extension compressor))) 733 (name (string-append name ".tar" (compressor-extension compressor)))
720 (graph "system-graph")) 734 (graph "system-graph")
735 (root (srfi-1:find (lambda (user)
736 (and=> (user-account-uid user) zero?))
737 (operating-system-users os)))
738 (root-shell (or (and=> root user-account-shell)
739 (file-append bash "/bin/bash"))))
721 (define builder 740 (define builder
722 (with-extensions gcrypt-sqlite3&co ;for (guix store database) 741 (with-extensions gcrypt-sqlite3&co ;for (guix store database)
723 (with-imported-modules `(,@(source-module-closure 742 (with-imported-modules `(,@(source-module-closure
@@ -753,6 +772,16 @@ output file."
753 #:system-directory #$os) 772 #:system-directory #$os)
754 773
755 (with-directory-excursion image-root 774 (with-directory-excursion image-root
775 #$@(if wsl?
776 #~(;; WSL requires /bin/sh. Will be overwritten by
777 ;; system activation.
778 (symlink #$root-shell "./bin/sh")
779
780 ;; WSL requires /bin/mount to access the host fs.
781 (symlink #$(file-append util-linux "/bin/mount")
782 "./bin/mount"))
783 #~())
784
756 (apply invoke tar "-cvf" #$output "." 785 (apply invoke tar "-cvf" #$output "."
757 (tar-base-options 786 (tar-base-options
758 #:tar tar 787 #:tar tar
@@ -775,7 +804,7 @@ output file."
775 "Return the IMAGE root partition file-system type." 804 "Return the IMAGE root partition file-system type."
776 (case (image-format image) 805 (case (image-format image)
777 ((iso9660) "iso9660") 806 ((iso9660) "iso9660")
778 ((docker tarball) "dummy") 807 ((docker tarball wsl2) "dummy")
779 (else 808 (else
780 (partition-file-system (find-root-partition image))))) 809 (partition-file-system (find-root-partition image)))))
781 810
@@ -914,6 +943,8 @@ image, depending on IMAGE format."
914 (system-docker-image image*)) 943 (system-docker-image image*))
915 ((memq image-format '(tarball)) 944 ((memq image-format '(tarball))
916 (system-tarball-image image*)) 945 (system-tarball-image image*))
946 ((memq image-format '(wsl2))
947 (system-tarball-image image* #:wsl? #t))
917 ((memq image-format '(iso9660)) 948 ((memq image-format '(iso9660))
918 (system-iso9660-image 949 (system-iso9660-image
919 image* 950 image*