Commit | Line | Data |
---|---|---|
6b779207 | 1 | ;;; GNU Guix --- Functional package management for GNU |
7046e777 | 2 | ;;; Copyright © 2016, 2018, 2022 Ludovic Courtès <ludo@gnu.org> |
fdfdecdb | 3 | ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr> |
6b779207 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 (test-system) | |
21 | #:use-module (gnu) | |
68a58775 | 22 | #:use-module ((gnu services) #:select (service-value)) |
6b779207 | 23 | #:use-module (guix store) |
7046e777 LC |
24 | #:use-module (guix monads) |
25 | #:use-module ((guix gexp) #:select (lower-object)) | |
26 | #:use-module ((guix utils) #:select (%current-system)) | |
27 | #:use-module (guix grafts) | |
6b779207 LC |
28 | #:use-module (srfi srfi-1) |
29 | #:use-module (srfi srfi-64)) | |
30 | ||
31 | ;; Test the (gnu system) module. | |
32 | ||
33 | (define %root-fs | |
34 | (file-system | |
9ceeca08 | 35 | (device (file-system-label "my-root")) |
6b779207 LC |
36 | (mount-point "/") |
37 | (type "ext4"))) | |
38 | ||
39 | (define %os | |
40 | (operating-system | |
41 | (host-name "komputilo") | |
42 | (timezone "Europe/Berlin") | |
43 | (locale "en_US.utf8") | |
fdfdecdb TGR |
44 | (bootloader (bootloader-configuration |
45 | (bootloader grub-bootloader) | |
da4e4094 | 46 | (targets '("/dev/sdX")))) |
6b779207 LC |
47 | (file-systems (cons %root-fs %base-file-systems)) |
48 | ||
49 | (users %base-user-accounts))) | |
50 | ||
2bdd7ac1 LC |
51 | (define %luks-device |
52 | (mapped-device | |
53 | (source "/dev/foo") (target "my-luks-device") | |
54 | (type luks-device-mapping))) | |
55 | ||
56 | (define %os-with-mapped-device | |
57 | (operating-system | |
58 | (host-name "komputilo") | |
59 | (timezone "Europe/Berlin") | |
60 | (locale "en_US.utf8") | |
fdfdecdb TGR |
61 | (bootloader (bootloader-configuration |
62 | (bootloader grub-bootloader) | |
da4e4094 | 63 | (targets '("/dev/sdX")))) |
2bdd7ac1 LC |
64 | (mapped-devices (list %luks-device)) |
65 | (file-systems (cons (file-system | |
66 | (inherit %root-fs) | |
67 | (dependencies (list %luks-device))) | |
68 | %base-file-systems)) | |
69 | (users %base-user-accounts))) | |
70 | ||
7046e777 LC |
71 | (%graft? #f) |
72 | ||
7b44cae5 | 73 | \f |
6b779207 LC |
74 | (test-begin "system") |
75 | ||
76 | (test-assert "operating-system-store-file-system" | |
77 | ;; %BASE-FILE-SYSTEMS defines a bind-mount for /gnu/store, but this | |
78 | ;; shouldn't be a problem. | |
79 | (eq? %root-fs | |
80 | (operating-system-store-file-system %os))) | |
81 | ||
82 | (test-assert "operating-system-store-file-system, prefix" | |
83 | (let* ((gnu (file-system | |
84 | (device "foobar") | |
85 | (mount-point (dirname (%store-prefix))) | |
86 | (type "ext5"))) | |
87 | (os (operating-system | |
88 | (inherit %os) | |
89 | (file-systems (cons* gnu %root-fs | |
90 | %base-file-systems))))) | |
91 | (eq? gnu (operating-system-store-file-system os)))) | |
92 | ||
93 | (test-assert "operating-system-store-file-system, store" | |
94 | (let* ((gnu (file-system | |
95 | (device "foobar") | |
96 | (mount-point (%store-prefix)) | |
97 | (type "ext5"))) | |
98 | (os (operating-system | |
99 | (inherit %os) | |
100 | (file-systems (cons* gnu %root-fs | |
101 | %base-file-systems))))) | |
102 | (eq? gnu (operating-system-store-file-system os)))) | |
103 | ||
2bdd7ac1 LC |
104 | (test-equal "operating-system-user-mapped-devices" |
105 | '() | |
106 | (operating-system-user-mapped-devices %os-with-mapped-device)) | |
107 | ||
108 | (test-equal "operating-system-boot-mapped-devices" | |
109 | (list %luks-device) | |
110 | (operating-system-boot-mapped-devices %os-with-mapped-device)) | |
111 | ||
112 | (test-equal "operating-system-boot-mapped-devices, implicit dependency" | |
113 | (list %luks-device) | |
114 | ||
115 | ;; Here we expect the implicit dependency between "/" and | |
116 | ;; "/dev/mapper/my-luks-device" to be found, in spite of the lack of a | |
117 | ;; 'dependencies' field in the root file system. | |
118 | (operating-system-boot-mapped-devices | |
119 | (operating-system | |
120 | (inherit %os-with-mapped-device) | |
121 | (file-systems (cons (file-system | |
122 | (device "/dev/mapper/my-luks-device") | |
2bdd7ac1 LC |
123 | (mount-point "/") |
124 | (type "ext4")) | |
125 | %base-file-systems))))) | |
126 | ||
68a58775 LC |
127 | (test-equal "non-boot-file-system-service" |
128 | '() | |
129 | ||
130 | ;; Make sure that mapped devices with at least one needed-for-boot user are | |
131 | ;; handled exclusively from the initrd. See <https://bugs.gnu.org/31889>. | |
132 | (append-map file-system-dependencies | |
133 | (service-value | |
134 | ((@@ (gnu system) non-boot-file-system-service) | |
135 | (operating-system | |
136 | (inherit %os-with-mapped-device) | |
137 | (file-systems | |
138 | (list (file-system | |
139 | (mount-point "/foo/bar") | |
140 | (device "qux:baz") | |
141 | (type "none") | |
142 | (dependencies (list %luks-device))) | |
143 | (file-system | |
144 | (device (file-system-label "my-root")) | |
145 | (mount-point "/") | |
146 | (type "ext4") | |
147 | (dependencies (list %luks-device)))))))))) | |
148 | ||
7046e777 LC |
149 | (test-assert "lower-object, %current-system sensitivity" |
150 | ;; Make sure that 'lower-object' returns the same derivation, no matter what | |
151 | ;; '%current-system' is. See <https://issues.guix.gnu.org/55951>. | |
152 | (let ((drv1 (with-store store | |
153 | (parameterize ((%current-system "x86_64-linux")) | |
154 | (run-with-store store | |
155 | (lower-object %os "aarch64-linux"))))) | |
156 | (drv2 (with-store store | |
157 | (parameterize ((%current-system "aarch64-linux")) | |
158 | (run-with-store store | |
159 | (lower-object %os "aarch64-linux")))))) | |
160 | (eq? drv1 drv2))) | |
161 | ||
6b779207 | 162 | (test-end) |