tests: 'run-basic-test' can enter a root password.
[jackhill/guix/guix.git] / gnu / tests / install.scm
CommitLineData
94b4274d 1;;; GNU Guix --- Functional package management for GNU
3adf320e 2;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
4f51fdba 3;;; Copyright © 2017, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
94b4274d
LC
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
20(define-module (gnu tests install)
21 #:use-module (gnu)
a48a20fb 22 #:use-module (gnu bootloader extlinux)
94b4274d
LC
23 #:use-module (gnu tests)
24 #:use-module (gnu tests base)
25 #:use-module (gnu system)
26 #:use-module (gnu system install)
27 #:use-module (gnu system vm)
28 #:use-module ((gnu build vm) #:select (qemu-command))
a48a20fb 29 #:use-module (gnu packages bootloaders)
f7f292d3 30 #:use-module (gnu packages ocr)
94b4274d 31 #:use-module (gnu packages package-management)
59132b80 32 #:use-module (gnu packages virtualization)
94b4274d
LC
33 #:use-module (guix store)
34 #:use-module (guix monads)
35 #:use-module (guix packages)
36 #:use-module (guix grafts)
37 #:use-module (guix gexp)
38 #:use-module (guix utils)
b1bf155f 39 #:export (%test-installed-os
a48a20fb 40 %test-installed-extlinux-os
fbc7b1f1 41 %test-iso-image-installer
5479aa2b 42 %test-separate-store-os
ae763b5b 43 %test-separate-home-os
245cc5f5 44 %test-raid-root-os
4f83afd2 45 %test-encrypted-root-os
4f51fdba
TGR
46 %test-btrfs-root-os
47 %test-jfs-root-os))
94b4274d
LC
48
49;;; Commentary:
50;;;
59e80445 51;;; Test the installation of Guix using the documented approach at the
94b4274d
LC
52;;; command line.
53;;;
54;;; Code:
55
56(define-os-with-source (%minimal-os %minimal-os-source)
57 ;; The OS we want to install.
58 (use-modules (gnu) (gnu tests) (srfi srfi-1))
59
60 (operating-system
61 (host-name "liberigilo")
62 (timezone "Europe/Paris")
63 (locale "en_US.UTF-8")
64
fdfdecdb
TGR
65 (bootloader (bootloader-configuration
66 (bootloader grub-bootloader)
67 (target "/dev/vdb")))
94b4274d
LC
68 (kernel-arguments '("console=ttyS0"))
69 (file-systems (cons (file-system
9ceeca08 70 (device (file-system-label "my-root"))
94b4274d
LC
71 (mount-point "/")
72 (type "ext4"))
73 %base-file-systems))
74 (users (cons (user-account
75 (name "alice")
76 (comment "Bob's sister")
77 (group "users")
cf848cc0 78 (supplementary-groups '("wheel" "audio" "video")))
94b4274d
LC
79 %base-user-accounts))
80 (services (cons (service marionette-service-type
a4bbf41b
LC
81 (marionette-configuration
82 (imported-modules '((gnu services herd)
f9d55c49 83 (guix build utils)
a4bbf41b 84 (guix combinators)))))
94b4274d
LC
85 %base-services))))
86
a48a20fb
MO
87(define (operating-system-add-packages os packages)
88 "Append PACKAGES to OS packages list."
89 (operating-system
90 (inherit os)
91 (packages (append packages (operating-system-packages os)))))
92
93(define-os-with-source (%minimal-extlinux-os
94 %minimal-extlinux-os-source)
95 (use-modules (gnu) (gnu tests) (gnu bootloader extlinux)
96 (srfi srfi-1))
97
98 (operating-system
99 (host-name "liberigilo")
100 (timezone "Europe/Paris")
101 (locale "en_US.UTF-8")
102
103 (bootloader (bootloader-configuration
104 (bootloader extlinux-bootloader-gpt)
045ebb3e 105 (target "/dev/vdb")))
a48a20fb
MO
106 (kernel-arguments '("console=ttyS0"))
107 (file-systems (cons (file-system
9ceeca08 108 (device (file-system-label "my-root"))
a48a20fb
MO
109 (mount-point "/")
110 (type "ext4"))
111 %base-file-systems))
112 (services (cons (service marionette-service-type
113 (marionette-configuration
114 (imported-modules '((gnu services herd)
115 (guix combinators)))))
116 %base-services))))
117
94b4274d
LC
118(define (operating-system-with-current-guix os)
119 "Return a variant of OS that uses the current Guix."
120 (operating-system
121 (inherit os)
122 (services (modify-services (operating-system-user-services os)
123 (guix-service-type config =>
124 (guix-configuration
125 (inherit config)
126 (guix (current-guix))))))))
127
94b4274d
LC
128\f
129(define MiB (expt 2 20))
130
b1bf155f
LC
131(define %simple-installation-script
132 ;; Shell script of a simple installation.
133 "\
134. /etc/profile
135set -e -x
136guix --version
137
138export GUIX_BUILD_OPTIONS=--no-grafts
139guix build isc-dhcp
140parted --script /dev/vdb mklabel gpt \\
141 mkpart primary ext2 1M 3M \\
198a7ac0 142 mkpart primary ext2 3M 1.4G \\
b1bf155f
LC
143 set 1 boot on \\
144 set 1 bios_grub on
145mkfs.ext4 -L my-root /dev/vdb2
146mount /dev/vdb2 /mnt
147df -h /mnt
148herd start cow-store /mnt
149mkdir /mnt/etc
150cp /etc/target-config.scm /mnt/etc/config.scm
151guix system init /mnt/etc/config.scm /mnt --no-substitutes
152sync
153reboot\n")
154
a48a20fb
MO
155(define %extlinux-gpt-installation-script
156 ;; Shell script of a simple installation.
157 ;; As syslinux 6.0.3 does not handle 64bits ext4 partitions,
158 ;; we make sure to pass -O '^64bit' to mkfs.
159 "\
160. /etc/profile
161set -e -x
162guix --version
163
164export GUIX_BUILD_OPTIONS=--no-grafts
165guix build isc-dhcp
166parted --script /dev/vdb mklabel gpt \\
198a7ac0 167 mkpart ext2 1M 1.4G \\
a48a20fb
MO
168 set 1 legacy_boot on
169mkfs.ext4 -L my-root -O '^64bit' /dev/vdb1
170mount /dev/vdb1 /mnt
171df -h /mnt
172herd start cow-store /mnt
173mkdir /mnt/etc
174cp /etc/target-config.scm /mnt/etc/config.scm
175guix system init /mnt/etc/config.scm /mnt --no-substitutes
176sync
177reboot\n")
178
b1bf155f
LC
179(define* (run-install target-os target-os-source
180 #:key
181 (script %simple-installation-script)
a48a20fb 182 (packages '())
94b4274d 183 (os (marionette-operating-system
94b4274d 184 (operating-system
a48a20fb
MO
185 ;; Since the image has no network access, use the
186 ;; current Guix so the store items we need are in
187 ;; the image and add packages provided.
188 (inherit (operating-system-add-packages
189 (operating-system-with-current-guix
190 installation-os)
191 packages))
94b4274d
LC
192 (kernel-arguments '("console=ttyS0")))
193 #:imported-modules '((gnu services herd)
194 (guix combinators))))
fbc7b1f1 195 (installation-disk-image-file-system-type "ext4")
5724a14e 196 (target-size (* 2200 MiB)))
59e80445 197 "Run SCRIPT (a shell script following the system installation procedure) in
b1bf155f 198OS to install TARGET-OS. Return a VM image of TARGET-SIZE bytes containing
a48a20fb
MO
199the installed system. The packages specified in PACKAGES will be appended to
200packages defined in installation-os."
94b4274d
LC
201
202 (mlet* %store-monad ((_ (set-grafting #f))
203 (system (current-system))
b1bf155f 204 (target (operating-system-derivation target-os))
94b4274d
LC
205
206 ;; Since the installation system has no network access,
207 ;; we cheat a little bit by adding TARGET to its GC
208 ;; roots. This way, we know 'guix system init' will
209 ;; succeed.
210 (image (system-disk-image
211 (operating-system-with-gc-roots
212 os (list target))
91496dfc 213 #:disk-image-size 'guess
fbc7b1f1
CB
214 #:file-system-type
215 installation-disk-image-file-system-type)))
94b4274d 216 (define install
4ee96a79
LC
217 (with-imported-modules '((guix build utils)
218 (gnu build marionette))
219 #~(begin
220 (use-modules (guix build utils)
221 (gnu build marionette))
222
223 (set-path-environment-variable "PATH" '("bin")
224 (list #$qemu-minimal))
225
226 (system* "qemu-img" "create" "-f" "qcow2"
227 #$output #$(number->string target-size))
228
229 (define marionette
230 (make-marionette
fbc7b1f1
CB
231 `(,(which #$(qemu-command system))
232 "-no-reboot"
233 "-m" "800"
234 #$@(cond
235 ((string=? "ext4" installation-disk-image-file-system-type)
4e396041
LC
236 #~("-drive"
237 ,(string-append "file=" #$image
238 ",if=virtio,readonly")))
fbc7b1f1 239 ((string=? "iso9660" installation-disk-image-file-system-type)
4e396041 240 #~("-cdrom" #$image))
fbc7b1f1
CB
241 (else
242 (error
243 "unsupported installation-disk-image-file-system-type:"
244 installation-disk-image-file-system-type)))
245 "-drive"
246 ,(string-append "file=" #$output ",if=virtio")
247 ,@(if (file-exists? "/dev/kvm")
248 '("-enable-kvm")
249 '()))))
4ee96a79
LC
250
251 (pk 'uname (marionette-eval '(uname) marionette))
252
253 ;; Wait for tty1.
254 (marionette-eval '(begin
255 (use-modules (gnu services herd))
256 (start 'term-tty1))
257 marionette)
258
b1bf155f 259 (marionette-eval '(call-with-output-file "/etc/target-config.scm"
4ee96a79 260 (lambda (port)
b1bf155f 261 (write '#$target-os-source port)))
4ee96a79
LC
262 marionette)
263
b1bf155f
LC
264 (exit (marionette-eval '(zero? (system #$script))
265 marionette)))))
266
267 (gexp->derivation "installation" install)))
268
b800b8da 269(define* (qemu-command/writable-image image #:key (memory-size 256))
b1bf155f 270 "Return as a monadic value the command to run QEMU on a writable copy of
1a034f04 271IMAGE, a disk image. The QEMU VM has access to MEMORY-SIZE MiB of RAM."
b1bf155f
LC
272 (mlet %store-monad ((system (current-system)))
273 (return #~(let ((image #$image))
274 ;; First we need a writable copy of the image.
130079ae
LC
275 (format #t "creating writable image from '~a'...~%" image)
276 (unless (zero? (system* #+(file-append qemu-minimal
277 "/bin/qemu-img")
278 "create" "-f" "qcow2"
279 "-o"
280 (string-append "backing_file=" image)
281 "disk.img"))
282 (error "failed to create writable QEMU image" image))
283
b1bf155f
LC
284 (chmod "disk.img" #o644)
285 `(,(string-append #$qemu-minimal "/bin/"
286 #$(qemu-command system))
287 ,@(if (file-exists? "/dev/kvm")
288 '("-enable-kvm")
289 '())
b800b8da 290 "-no-reboot" "-m" #$(number->string memory-size)
b1bf155f
LC
291 "-drive" "file=disk.img,if=virtio")))))
292
b1bf155f
LC
293(define %test-installed-os
294 (system-test
295 (name "installed-os")
296 (description
297 "Test basic functionality of an OS installed like one would do by hand.
298This test is expensive in terms of CPU and storage usage since we need to
299build (current-guix) and then store a couple of full system images.")
300 (value
301 (mlet* %store-monad ((image (run-install %minimal-os %minimal-os-source))
302 (command (qemu-command/writable-image image)))
303 (run-basic-test %minimal-os command
304 "installed-os")))))
305
a48a20fb
MO
306(define %test-installed-extlinux-os
307 (system-test
308 (name "installed-extlinux-os")
309 (description
310 "Test basic functionality of an OS booted with an extlinux bootloader. As
311per %test-installed-os, this test is expensive in terms of CPU and storage.")
312 (value
313 (mlet* %store-monad ((image (run-install %minimal-extlinux-os
314 %minimal-extlinux-os-source
315 #:packages
316 (list syslinux)
317 #:script
318 %extlinux-gpt-installation-script))
319 (command (qemu-command/writable-image image)))
320 (run-basic-test %minimal-extlinux-os command
321 "installed-extlinux-os")))))
322
b1bf155f 323\f
fbc7b1f1
CB
324;;;
325;;; Installation through an ISO image.
326;;;
327
328(define-os-with-source (%minimal-os-on-vda %minimal-os-on-vda-source)
329 ;; The OS we want to install.
330 (use-modules (gnu) (gnu tests) (srfi srfi-1))
331
332 (operating-system
333 (host-name "liberigilo")
334 (timezone "Europe/Paris")
335 (locale "en_US.UTF-8")
336
fdfdecdb
TGR
337 (bootloader (bootloader-configuration
338 (bootloader grub-bootloader)
339 (target "/dev/vda")))
fbc7b1f1
CB
340 (kernel-arguments '("console=ttyS0"))
341 (file-systems (cons (file-system
9ceeca08 342 (device (file-system-label "my-root"))
fbc7b1f1
CB
343 (mount-point "/")
344 (type "ext4"))
345 %base-file-systems))
346 (users (cons (user-account
347 (name "alice")
348 (comment "Bob's sister")
349 (group "users")
cf848cc0 350 (supplementary-groups '("wheel" "audio" "video")))
fbc7b1f1
CB
351 %base-user-accounts))
352 (services (cons (service marionette-service-type
353 (marionette-configuration
354 (imported-modules '((gnu services herd)
355 (guix combinators)))))
356 %base-services))))
357
358(define %simple-installation-script-for-/dev/vda
359 ;; Shell script of a simple installation.
360 "\
361. /etc/profile
362set -e -x
363guix --version
364
365export GUIX_BUILD_OPTIONS=--no-grafts
366guix build isc-dhcp
367parted --script /dev/vda mklabel gpt \\
368 mkpart primary ext2 1M 3M \\
198a7ac0 369 mkpart primary ext2 3M 1.4G \\
fbc7b1f1
CB
370 set 1 boot on \\
371 set 1 bios_grub on
372mkfs.ext4 -L my-root /dev/vda2
373mount /dev/vda2 /mnt
374df -h /mnt
375herd start cow-store /mnt
376mkdir /mnt/etc
377cp /etc/target-config.scm /mnt/etc/config.scm
378guix system init /mnt/etc/config.scm /mnt --no-substitutes
379sync
380reboot\n")
381
382(define %test-iso-image-installer
383 (system-test
384 (name "iso-image-installer")
385 (description
386 "")
387 (value
388 (mlet* %store-monad ((image (run-install
389 %minimal-os-on-vda
390 %minimal-os-on-vda-source
391 #:script
392 %simple-installation-script-for-/dev/vda
393 #:installation-disk-image-file-system-type
394 "iso9660"))
395 (command (qemu-command/writable-image image)))
396 (run-basic-test %minimal-os-on-vda command name)))))
397
398\f
ae763b5b
LC
399;;;
400;;; Separate /home.
401;;;
402
403(define-os-with-source (%separate-home-os %separate-home-os-source)
404 ;; The OS we want to install.
405 (use-modules (gnu) (gnu tests) (srfi srfi-1))
406
407 (operating-system
408 (host-name "liberigilo")
409 (timezone "Europe/Paris")
410 (locale "en_US.utf8")
411
fdfdecdb
TGR
412 (bootloader (bootloader-configuration
413 (bootloader grub-bootloader)
414 (target "/dev/vdb")))
ae763b5b
LC
415 (kernel-arguments '("console=ttyS0"))
416 (file-systems (cons* (file-system
9ceeca08 417 (device (file-system-label "my-root"))
ae763b5b
LC
418 (mount-point "/")
419 (type "ext4"))
420 (file-system
421 (device "none")
ae763b5b
LC
422 (mount-point "/home")
423 (type "tmpfs"))
424 %base-file-systems))
425 (users (cons* (user-account
426 (name "alice")
cf848cc0 427 (group "users"))
ae763b5b
LC
428 (user-account
429 (name "charlie")
cf848cc0 430 (group "users"))
ae763b5b
LC
431 %base-user-accounts))
432 (services (cons (service marionette-service-type
433 (marionette-configuration
434 (imported-modules '((gnu services herd)
435 (guix combinators)))))
436 %base-services))))
437
438(define %test-separate-home-os
439 (system-test
440 (name "separate-home-os")
441 (description
442 "Test basic functionality of an installed OS with a separate /home
443partition. In particular, home directories must be correctly created (see
444<https://bugs.gnu.org/21108>).")
445 (value
446 (mlet* %store-monad ((image (run-install %separate-home-os
447 %separate-home-os-source
448 #:script
449 %simple-installation-script))
450 (command (qemu-command/writable-image image)))
451 (run-basic-test %separate-home-os command "separate-home-os")))))
452
453\f
5479aa2b
LC
454;;;
455;;; Separate /gnu/store partition.
456;;;
457
458(define-os-with-source (%separate-store-os %separate-store-os-source)
459 ;; The OS we want to install.
460 (use-modules (gnu) (gnu tests) (srfi srfi-1))
461
462 (operating-system
463 (host-name "liberigilo")
464 (timezone "Europe/Paris")
465 (locale "en_US.UTF-8")
466
fdfdecdb
TGR
467 (bootloader (bootloader-configuration
468 (bootloader grub-bootloader)
469 (target "/dev/vdb")))
5479aa2b
LC
470 (kernel-arguments '("console=ttyS0"))
471 (file-systems (cons* (file-system
9ceeca08 472 (device (file-system-label "root-fs"))
5479aa2b
LC
473 (mount-point "/")
474 (type "ext4"))
475 (file-system
9ceeca08 476 (device (file-system-label "store-fs"))
5479aa2b 477 (mount-point "/gnu")
38434419 478 (type "ext4"))
5479aa2b
LC
479 %base-file-systems))
480 (users %base-user-accounts)
481 (services (cons (service marionette-service-type
482 (marionette-configuration
483 (imported-modules '((gnu services herd)
484 (guix combinators)))))
485 %base-services))))
486
487(define %separate-store-installation-script
488 ;; Installation with a separate /gnu partition.
489 "\
490. /etc/profile
491set -e -x
492guix --version
493
494export GUIX_BUILD_OPTIONS=--no-grafts
495guix build isc-dhcp
496parted --script /dev/vdb mklabel gpt \\
497 mkpart primary ext2 1M 3M \\
307ec732
LC
498 mkpart primary ext2 3M 400M \\
499 mkpart primary ext2 400M 2.1G \\
5479aa2b
LC
500 set 1 boot on \\
501 set 1 bios_grub on
502mkfs.ext4 -L root-fs /dev/vdb2
503mkfs.ext4 -L store-fs /dev/vdb3
504mount /dev/vdb2 /mnt
505mkdir /mnt/gnu
506mount /dev/vdb3 /mnt/gnu
507df -h /mnt
307ec732 508df -h /mnt/gnu
5479aa2b
LC
509herd start cow-store /mnt
510mkdir /mnt/etc
511cp /etc/target-config.scm /mnt/etc/config.scm
512guix system init /mnt/etc/config.scm /mnt --no-substitutes
513sync
514reboot\n")
515
516(define %test-separate-store-os
517 (system-test
518 (name "separate-store-os")
519 (description
520 "Test basic functionality of an OS installed like one would do by hand,
521where /gnu lives on a separate partition.")
522 (value
523 (mlet* %store-monad ((image (run-install %separate-store-os
524 %separate-store-os-source
525 #:script
526 %separate-store-installation-script))
527 (command (qemu-command/writable-image image)))
528 (run-basic-test %separate-store-os command "separate-store-os")))))
529
530\f
245cc5f5
LC
531;;;
532;;; RAID root device.
533;;;
534
535(define-os-with-source (%raid-root-os %raid-root-os-source)
536 ;; An OS whose root partition is a RAID partition.
537 (use-modules (gnu) (gnu tests))
538
539 (operating-system
540 (host-name "raidified")
541 (timezone "Europe/Paris")
542 (locale "en_US.utf8")
543
fdfdecdb
TGR
544 (bootloader (bootloader-configuration
545 (bootloader grub-bootloader)
546 (target "/dev/vdb")))
245cc5f5 547 (kernel-arguments '("console=ttyS0"))
bc499b11 548
3adf320e
LC
549 ;; Add a kernel module for RAID-1 (aka. "mirror").
550 (initrd-modules (cons "raid1" %base-initrd-modules))
bc499b11 551
245cc5f5
LC
552 (mapped-devices (list (mapped-device
553 (source (list "/dev/vda2" "/dev/vda3"))
554 (target "/dev/md0")
555 (type raid-device-mapping))))
556 (file-systems (cons (file-system
9ceeca08 557 (device (file-system-label "root-fs"))
245cc5f5
LC
558 (mount-point "/")
559 (type "ext4")
560 (dependencies mapped-devices))
561 %base-file-systems))
562 (users %base-user-accounts)
563 (services (cons (service marionette-service-type
564 (marionette-configuration
565 (imported-modules '((gnu services herd)
566 (guix combinators)))))
567 %base-services))))
568
569(define %raid-root-installation-script
570 ;; Installation with a separate /gnu partition. See
571 ;; <https://raid.wiki.kernel.org/index.php/RAID_setup> for more on RAID and
572 ;; mdadm.
573 "\
574. /etc/profile
575set -e -x
576guix --version
577
578export GUIX_BUILD_OPTIONS=--no-grafts
579parted --script /dev/vdb mklabel gpt \\
580 mkpart primary ext2 1M 3M \\
3adf320e
LC
581 mkpart primary ext2 3M 1.4G \\
582 mkpart primary ext2 1.4G 2.8G \\
245cc5f5
LC
583 set 1 boot on \\
584 set 1 bios_grub on
3adf320e 585yes | mdadm --create /dev/md0 --verbose --level=mirror --raid-devices=2 \\
245cc5f5
LC
586 /dev/vdb2 /dev/vdb3
587mkfs.ext4 -L root-fs /dev/md0
588mount /dev/md0 /mnt
589df -h /mnt
590herd start cow-store /mnt
591mkdir /mnt/etc
592cp /etc/target-config.scm /mnt/etc/config.scm
593guix system init /mnt/etc/config.scm /mnt --no-substitutes
594sync
595reboot\n")
596
597(define %test-raid-root-os
598 (system-test
599 (name "raid-root-os")
600 (description
601 "Test functionality of an OS installed with a RAID root partition managed
602by 'mdadm'.")
603 (value
604 (mlet* %store-monad ((image (run-install %raid-root-os
605 %raid-root-os-source
606 #:script
607 %raid-root-installation-script
3adf320e 608 #:target-size (* 2800 MiB)))
245cc5f5
LC
609 (command (qemu-command/writable-image image)))
610 (run-basic-test %raid-root-os
611 `(,@command) "raid-root-os")))))
612
613\f
5479aa2b
LC
614;;;
615;;; LUKS-encrypted root file system.
616;;;
617
b1bf155f
LC
618(define-os-with-source (%encrypted-root-os %encrypted-root-os-source)
619 ;; The OS we want to install.
620 (use-modules (gnu) (gnu tests) (srfi srfi-1))
621
622 (operating-system
623 (host-name "liberigilo")
624 (timezone "Europe/Paris")
625 (locale "en_US.UTF-8")
626
fdfdecdb
TGR
627 (bootloader (bootloader-configuration
628 (bootloader grub-bootloader)
629 (target "/dev/vdb")))
f7f292d3
LC
630
631 ;; Note: Do not pass "console=ttyS0" so we can use our passphrase prompt
632 ;; detection logic in 'enter-luks-passphrase'.
633
634 (mapped-devices (list (mapped-device
635 (source (uuid "12345678-1234-1234-1234-123456789abc"))
636 (target "the-root-device")
637 (type luks-device-mapping))))
b1bf155f
LC
638 (file-systems (cons (file-system
639 (device "/dev/mapper/the-root-device")
b1bf155f
LC
640 (mount-point "/")
641 (type "ext4"))
642 %base-file-systems))
b1bf155f
LC
643 (users (cons (user-account
644 (name "charlie")
645 (group "users")
b1bf155f
LC
646 (supplementary-groups '("wheel" "audio" "video")))
647 %base-user-accounts))
648 (services (cons (service marionette-service-type
649 (marionette-configuration
650 (imported-modules '((gnu services herd)
651 (guix combinators)))))
652 %base-services))))
653
43e282ac
LC
654(define %luks-passphrase
655 ;; LUKS encryption passphrase used in tests.
656 "thepassphrase")
657
b1bf155f
LC
658(define %encrypted-root-installation-script
659 ;; Shell script of a simple installation.
43e282ac 660 (string-append "\
94b4274d 661. /etc/profile
b1bf155f 662set -e -x
94b4274d 663guix --version
94b4274d
LC
664
665export GUIX_BUILD_OPTIONS=--no-grafts
b1bf155f 666ls -l /run/current-system/gc-roots
94b4274d
LC
667parted --script /dev/vdb mklabel gpt \\
668 mkpart primary ext2 1M 3M \\
8dfb0c96 669 mkpart primary ext2 3M 1.4G \\
94b4274d
LC
670 set 1 boot on \\
671 set 1 bios_grub on
43e282ac 672echo -n " %luks-passphrase " | \\
f7f292d3 673 cryptsetup luksFormat --uuid=12345678-1234-1234-1234-123456789abc -q /dev/vdb2 -
43e282ac 674echo -n " %luks-passphrase " | \\
b1bf155f
LC
675 cryptsetup open --type luks --key-file - /dev/vdb2 the-root-device
676mkfs.ext4 -L my-root /dev/mapper/the-root-device
677mount LABEL=my-root /mnt
94b4274d
LC
678herd start cow-store /mnt
679mkdir /mnt/etc
b1bf155f 680cp /etc/target-config.scm /mnt/etc/config.scm
b1bf155f 681guix system build /mnt/etc/config.scm
94b4274d
LC
682guix system init /mnt/etc/config.scm /mnt --no-substitutes
683sync
43e282ac 684reboot\n"))
94b4274d 685
f7f292d3
LC
686(define (enter-luks-passphrase marionette)
687 "Return a gexp to be inserted in the basic system test running on MARIONETTE
688to enter the LUKS passphrase."
689 (let ((ocrad (file-append ocrad "/bin/ocrad")))
690 #~(begin
691 (define (passphrase-prompt? text)
692 (string-contains (pk 'screen-text text) "Enter pass"))
693
694 (define (bios-boot-screen? text)
695 ;; Return true if TEXT corresponds to the boot screen, before GRUB's
696 ;; menu.
697 (string-prefix? "SeaBIOS" text))
698
699 (test-assert "enter LUKS passphrase for GRUB"
700 (begin
701 ;; At this point we have no choice but to use OCR to determine
702 ;; when the passphrase should be entered.
703 (wait-for-screen-text #$marionette passphrase-prompt?
704 #:ocrad #$ocrad)
43e282ac
LC
705 (marionette-type #$(string-append %luks-passphrase "\n")
706 #$marionette)
f7f292d3
LC
707
708 ;; Now wait until we leave the boot screen. This is necessary so
709 ;; we can then be sure we match the "Enter passphrase" prompt from
710 ;; 'cryptsetup', in the initrd.
711 (wait-for-screen-text #$marionette (negate bios-boot-screen?)
712 #:ocrad #$ocrad
713 #:timeout 20)))
714
715 (test-assert "enter LUKS passphrase for the initrd"
716 (begin
717 ;; XXX: Here we use OCR as well but we could instead use QEMU
718 ;; '-serial stdio' and run it in an input pipe,
719 (wait-for-screen-text #$marionette passphrase-prompt?
720 #:ocrad #$ocrad
721 #:timeout 60)
43e282ac
LC
722 (marionette-type #$(string-append %luks-passphrase "\n")
723 #$marionette)
f7f292d3
LC
724
725 ;; Take a screenshot for debugging purposes.
726 (marionette-control (string-append "screendump " #$output
727 "/post-initrd-passphrase.ppm")
728 #$marionette))))))
729
4f83afd2 730(define %test-encrypted-root-os
98b65b5f 731 (system-test
b1bf155f 732 (name "encrypted-root-os")
98b65b5f
LC
733 (description
734 "Test basic functionality of an OS installed like one would do by hand.
735This test is expensive in terms of CPU and storage usage since we need to
736build (current-guix) and then store a couple of full system images.")
737 (value
b1bf155f
LC
738 (mlet* %store-monad ((image (run-install %encrypted-root-os
739 %encrypted-root-os-source
740 #:script
741 %encrypted-root-installation-script))
742 (command (qemu-command/writable-image image)))
f7f292d3
LC
743 (run-basic-test %encrypted-root-os command "encrypted-root-os"
744 #:initialization enter-luks-passphrase)))))
94b4274d 745
b1a505ba
DC
746\f
747;;;
748;;; Btrfs root file system.
749;;;
750
751(define-os-with-source (%btrfs-root-os %btrfs-root-os-source)
752 ;; The OS we want to install.
753 (use-modules (gnu) (gnu tests) (srfi srfi-1))
754
755 (operating-system
756 (host-name "liberigilo")
757 (timezone "Europe/Paris")
758 (locale "en_US.UTF-8")
759
fdfdecdb
TGR
760 (bootloader (bootloader-configuration
761 (bootloader grub-bootloader)
762 (target "/dev/vdb")))
b1a505ba
DC
763 (kernel-arguments '("console=ttyS0"))
764 (file-systems (cons (file-system
9ceeca08 765 (device (file-system-label "my-root"))
b1a505ba
DC
766 (mount-point "/")
767 (type "btrfs"))
768 %base-file-systems))
769 (users (cons (user-account
770 (name "charlie")
771 (group "users")
b1a505ba
DC
772 (supplementary-groups '("wheel" "audio" "video")))
773 %base-user-accounts))
774 (services (cons (service marionette-service-type
775 (marionette-configuration
776 (imported-modules '((gnu services herd)
777 (guix combinators)))))
778 %base-services))))
779
780(define %btrfs-root-installation-script
781 ;; Shell script of a simple installation.
782 "\
783. /etc/profile
784set -e -x
785guix --version
786
787export GUIX_BUILD_OPTIONS=--no-grafts
788ls -l /run/current-system/gc-roots
789parted --script /dev/vdb mklabel gpt \\
790 mkpart primary ext2 1M 3M \\
5724a14e 791 mkpart primary ext2 3M 2G \\
b1a505ba
DC
792 set 1 boot on \\
793 set 1 bios_grub on
794mkfs.btrfs -L my-root /dev/vdb2
795mount /dev/vdb2 /mnt
796btrfs subvolume create /mnt/home
797herd start cow-store /mnt
798mkdir /mnt/etc
799cp /etc/target-config.scm /mnt/etc/config.scm
800guix system build /mnt/etc/config.scm
801guix system init /mnt/etc/config.scm /mnt --no-substitutes
802sync
803reboot\n")
804
805(define %test-btrfs-root-os
806 (system-test
807 (name "btrfs-root-os")
808 (description
809 "Test basic functionality of an OS installed like one would do by hand.
810This test is expensive in terms of CPU and storage usage since we need to
811build (current-guix) and then store a couple of full system images.")
812 (value
813 (mlet* %store-monad ((image (run-install %btrfs-root-os
814 %btrfs-root-os-source
815 #:script
816 %btrfs-root-installation-script))
817 (command (qemu-command/writable-image image)))
818 (run-basic-test %btrfs-root-os command "btrfs-root-os")))))
819
4f51fdba
TGR
820\f
821;;;
822;;; JFS root file system.
823;;;
824
825(define-os-with-source (%jfs-root-os %jfs-root-os-source)
826 ;; The OS we want to install.
827 (use-modules (gnu) (gnu tests) (srfi srfi-1))
828
829 (operating-system
830 (host-name "liberigilo")
831 (timezone "Europe/Paris")
832 (locale "en_US.UTF-8")
833
834 (bootloader (bootloader-configuration
835 (bootloader grub-bootloader)
836 (target "/dev/vdb")))
837 (kernel-arguments '("console=ttyS0"))
838 (file-systems (cons (file-system
839 (device (file-system-label "my-root"))
840 (mount-point "/")
841 (type "jfs"))
842 %base-file-systems))
843 (users (cons (user-account
844 (name "charlie")
845 (group "users")
846 (supplementary-groups '("wheel" "audio" "video")))
847 %base-user-accounts))
848 (services (cons (service marionette-service-type
849 (marionette-configuration
850 (imported-modules '((gnu services herd)
851 (guix combinators)))))
852 %base-services))))
853
854(define %jfs-root-installation-script
855 ;; Shell script of a simple installation.
856 "\
857. /etc/profile
858set -e -x
859guix --version
860
861export GUIX_BUILD_OPTIONS=--no-grafts
862ls -l /run/current-system/gc-roots
863parted --script /dev/vdb mklabel gpt \\
864 mkpart primary ext2 1M 3M \\
865 mkpart primary ext2 3M 2G \\
866 set 1 boot on \\
867 set 1 bios_grub on
868jfs_mkfs -L my-root -q /dev/vdb2
869mount /dev/vdb2 /mnt
870herd start cow-store /mnt
871mkdir /mnt/etc
872cp /etc/target-config.scm /mnt/etc/config.scm
873guix system build /mnt/etc/config.scm
874guix system init /mnt/etc/config.scm /mnt --no-substitutes
875sync
876reboot\n")
877
878(define %test-jfs-root-os
879 (system-test
880 (name "jfs-root-os")
881 (description
882 "Test basic functionality of an OS installed like one would do by hand.
883This test is expensive in terms of CPU and storage usage since we need to
884build (current-guix) and then store a couple of full system images.")
885 (value
886 (mlet* %store-monad ((image (run-install %jfs-root-os
887 %jfs-root-os-source
888 #:script
889 %jfs-root-installation-script))
890 (command (qemu-command/writable-image image)))
891 (run-basic-test %jfs-root-os command "jfs-root-os")))))
892
94b4274d 893;;; install.scm ends here