Commit | Line | Data |
---|---|---|
c1202fb1 | 1 | # GNU Guix --- Functional package management for GNU |
0d22fc8d | 2 | # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> |
fdfdecdb | 3 | # Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr> |
8e88f6fa | 4 | # Copyright © 2018 Chris Marusich <cmmarusich@gmail.com> |
c1202fb1 LC |
5 | # |
6 | # This file is part of GNU Guix. | |
7 | # | |
8 | # GNU Guix is free software; you can redistribute it and/or modify it | |
9 | # under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 3 of the License, or (at | |
11 | # your option) any later version. | |
12 | # | |
13 | # GNU Guix is distributed in the hope that it will be useful, but | |
14 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
20 | ||
21 | # | |
9d3994f7 | 22 | # Test 'guix system', mostly error reporting. |
c1202fb1 LC |
23 | # |
24 | ||
25 | set -e | |
26 | ||
27 | guix system --version | |
28 | ||
29 | tmpfile="t-guix-system-$$" | |
30 | errorfile="t-guix-system-error-$$" | |
9d3994f7 LC |
31 | |
32 | # Note: This directory is chosen outside $builddir so that relative file name | |
33 | # canonicalization doesn't mess up with 'current-source-directory', used by | |
34 | # 'local-file' ('load' forces 'relative' for | |
35 | # %FILE-PORT-NAME-CANONICALIZATION.) | |
36 | tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$" | |
37 | mkdir "$tmpdir" | |
38 | ||
39 | trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT | |
c1202fb1 | 40 | |
116244df LC |
41 | # Reporting of syntax errors. |
42 | ||
c1202fb1 LC |
43 | cat > "$tmpfile"<<EOF |
44 | ;; This is line 1, and the next one is line 2. | |
45 | (operating-system) | |
46 | ;; The 'T' is at column 3. | |
47 | EOF | |
48 | ||
49 | if guix system vm "$tmpfile" 2> "$errorfile" | |
50 | then | |
51 | # This must not succeed. | |
52 | exit 1 | |
53 | else | |
54 | grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile" | |
55 | fi | |
116244df LC |
56 | |
57 | ||
a6e22d84 LC |
58 | cat > "$tmpfile"<<EOF |
59 | ;; This is line 1, and the next one is line 2. | |
60 | (operating-system | |
61 | ;; This is line 3, and there is no closing paren! | |
62 | EOF | |
63 | ||
64 | if guix system vm "$tmpfile" 2> "$errorfile" | |
65 | then | |
66 | # This must not succeed. | |
67 | exit 1 | |
68 | else | |
69 | grep "$tmpfile:4:1: missing closing paren" "$errorfile" | |
70 | fi | |
71 | ||
72 | ||
c5a4a92f LC |
73 | # Reporting of module not found errors. |
74 | ||
75 | cat > "$tmpfile" <<EOF | |
76 | ;; Line 1. | |
77 | (use-modules (gnu)) | |
78 | (use-service-modules openssh) | |
79 | EOF | |
80 | ||
81 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
82 | then false | |
83 | else | |
84 | grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile" | |
85 | grep "Try.*use-service-modules ssh" "$errorfile" | |
86 | fi | |
87 | ||
88 | cat > "$tmpfile" <<EOF | |
89 | ;; Line 1. | |
90 | (use-modules (gnu)) | |
91 | (use-package-modules qemu) | |
92 | EOF | |
93 | ||
94 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
95 | then false | |
96 | else | |
97 | grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile" | |
98 | grep "Try.*use-package-modules virtualization" "$errorfile" | |
99 | fi | |
100 | ||
2abcc97f LC |
101 | # Reporting of unbound variables. |
102 | ||
103 | cat > "$tmpfile" <<EOF | |
104 | (use-modules (gnu)) ; 1 | |
105 | (use-service-modules networking) ; 2 | |
106 | ||
107 | (operating-system ; 4 | |
108 | (host-name "antelope") ; 5 | |
109 | (timezone "Europe/Paris") ; 6 | |
110 | (locale "en_US.UTF-8") ; 7 | |
111 | ||
f61e6e52 | 112 | (bootloader (GRUB-config (target "/dev/sdX"))) ; 9 |
2abcc97f | 113 | (file-systems (cons (file-system |
9ceeca08 | 114 | (device (file-system-label "root")) |
2abcc97f LC |
115 | (mount-point "/") |
116 | (type "ext4")) | |
117 | %base-file-systems))) | |
118 | EOF | |
119 | ||
120 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
121 | then false | |
122 | else | |
1bb30aa3 LC |
123 | if test "`guile -c '(display (effective-version))'`" = 3.0 |
124 | then | |
125 | # FIXME: With Guile 3.3.0 the error is reported on line 11. | |
126 | # See <https://bugs.gnu.org/38388>. | |
127 | grep "$tmpfile:[0-9]\+:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile" | |
128 | elif test "`guile -c '(display (effective-version))'`" = 2.2 | |
13159c68 LC |
129 | then |
130 | # FIXME: With Guile 2.2.0 the error is reported on line 4. | |
131 | # See <http://bugs.gnu.org/26107>. | |
7acdecec | 132 | grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile" |
13159c68 | 133 | else |
7acdecec | 134 | grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile" |
13159c68 | 135 | fi |
2abcc97f LC |
136 | fi |
137 | ||
47212fc7 LC |
138 | cat > "$tmpfile" <<EOF |
139 | (use-modules (gnu)) ; 1 | |
140 | ||
141 | (operating-system ; 3 | |
142 | (file-systems (cons (file-system ; 4 | |
143 | (device (file-system-label "root")) | |
144 | (mount-point "/") ; 6 | |
145 | (type "ext4")))) ; 7 (!!) | |
146 | %base-file-systems) | |
147 | EOF | |
148 | ||
149 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
150 | then false | |
151 | else | |
152 | # Here '%base-file-systems' appears as if it were a field specified of the | |
153 | # enclosing 'operating-system' form due to parenthesis mismatch. | |
154 | grep "$tmpfile:3:[0-9]\+:.*%base-file-system.*invalid field specifier" \ | |
155 | "$errorfile" | |
156 | fi | |
157 | ||
2d2651e7 | 158 | OS_BASE=' |
116244df LC |
159 | (host-name "antelope") |
160 | (timezone "Europe/Paris") | |
161 | (locale "en_US.UTF-8") | |
162 | ||
fdfdecdb TGR |
163 | (bootloader (bootloader-configuration |
164 | (bootloader grub-bootloader) | |
f61e6e52 | 165 | (target "/dev/sdX"))) |
116244df | 166 | (file-systems (cons (file-system |
9ceeca08 | 167 | (device (file-system-label "root")) |
116244df LC |
168 | (mount-point "/") |
169 | (type "ext4")) | |
170 | %base-file-systems)) | |
2d2651e7 | 171 | ' |
116244df | 172 | |
2d2651e7 LC |
173 | # Reporting of duplicate service identifiers. |
174 | ||
175 | cat > "$tmpfile" <<EOF | |
176 | (use-modules (gnu)) | |
177 | (use-service-modules networking) | |
178 | ||
179 | (operating-system | |
180 | $OS_BASE | |
39d7fdce LC |
181 | (services (cons* (service dhcp-client-service-type) |
182 | (service dhcp-client-service-type) ;twice! | |
116244df LC |
183 | %base-services))) |
184 | EOF | |
185 | ||
186 | if guix system vm "$tmpfile" 2> "$errorfile" | |
187 | then | |
188 | # This must not succeed. | |
189 | exit 1 | |
190 | else | |
191 | grep "service 'networking'.*more than once" "$errorfile" | |
192 | fi | |
0c09a306 | 193 | |
0190c1c0 | 194 | # Reporting unmet shepherd requirements. |
2d2651e7 LC |
195 | |
196 | cat > "$tmpfile" <<EOF | |
0190c1c0 | 197 | (use-modules (gnu) (gnu services shepherd)) |
2d2651e7 LC |
198 | (use-service-modules networking) |
199 | ||
200 | (define buggy-service-type | |
d4053c71 | 201 | (shepherd-service-type |
2d2651e7 LC |
202 | 'buggy |
203 | (lambda _ | |
d4053c71 | 204 | (shepherd-service |
2d2651e7 LC |
205 | (provision '(buggy!)) |
206 | (requirement '(does-not-exist)) | |
0d22fc8d LC |
207 | (start #t))) |
208 | (description "Buggy."))) | |
2d2651e7 LC |
209 | |
210 | (operating-system | |
211 | $OS_BASE | |
212 | (services (cons (service buggy-service-type #t) | |
213 | %base-services))) | |
214 | EOF | |
215 | ||
216 | if guix system build "$tmpfile" 2> "$errorfile" | |
217 | then | |
218 | exit 1 | |
219 | else | |
a8492735 | 220 | grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile" |
2d2651e7 LC |
221 | fi |
222 | ||
223 | # Reporting inconsistent user accounts. | |
224 | ||
0c09a306 LC |
225 | make_user_config () |
226 | { | |
227 | cat > "$tmpfile" <<EOF | |
228 | (use-modules (gnu)) | |
229 | (use-service-modules networking) | |
230 | ||
231 | (operating-system | |
232 | (host-name "antelope") | |
233 | (timezone "Europe/Paris") | |
234 | (locale "en_US.UTF-8") | |
235 | ||
fdfdecdb TGR |
236 | (bootloader (bootloader-configuration |
237 | (bootloader grub-bootloader) | |
f61e6e52 | 238 | (target "/dev/sdX"))) |
0c09a306 | 239 | (file-systems (cons (file-system |
9ceeca08 | 240 | (device (file-system-label "root")) |
0c09a306 LC |
241 | (mount-point "/") |
242 | (type "ext4")) | |
243 | %base-file-systems)) | |
244 | (users (list (user-account | |
245 | (name "dave") | |
246 | (home-directory "/home/dave") | |
247 | (group "$1") | |
248 | (supplementary-groups '("$2")))))) | |
249 | EOF | |
250 | } | |
251 | ||
252 | make_user_config "users" "wheel" | |
253 | guix system build "$tmpfile" -n # succeeds | |
254 | ||
f3f427c2 LC |
255 | guix system build "$tmpfile" -d # succeeds |
256 | guix system build "$tmpfile" -d | grep '\.drv$' | |
257 | ||
258 | guix system vm "$tmpfile" -d # succeeds | |
259 | guix system vm "$tmpfile" -d | grep '\.drv$' | |
260 | ||
1540075c LC |
261 | # Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>). |
262 | drv1="`guix system vm "$tmpfile" -d`" | |
263 | drv2="`guix system vm "$tmpfile" -d`" | |
264 | test "$drv1" = "$drv2" | |
e74baa12 MO |
265 | drv1="`guix system image -t iso9660 "$tmpfile" -d`" |
266 | drv2="`guix system image -t iso9660 "$tmpfile" -d`" | |
1540075c LC |
267 | test "$drv1" = "$drv2" |
268 | ||
b8415243 LC |
269 | # Check whether the graph commands work as expected. |
270 | guix system extension-graph "$tmpfile" | grep 'label = "file-systems"' | |
271 | guix system shepherd-graph "$tmpfile" | grep 'label = "guix-daemon"' | |
272 | ||
0c09a306 LC |
273 | make_user_config "group-that-does-not-exist" "users" |
274 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
275 | then false | |
276 | else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi | |
277 | ||
278 | make_user_config "users" "group-that-does-not-exist" | |
279 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
280 | then false | |
281 | else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi | |
9d3994f7 LC |
282 | |
283 | # Try 'local-file' and relative file name resolution. | |
284 | ||
285 | cat > "$tmpdir/config.scm"<<EOF | |
286 | (use-modules (gnu)) | |
287 | (use-service-modules networking) | |
288 | ||
289 | (operating-system | |
290 | $OS_BASE | |
84a2de36 LC |
291 | (services (cons (service tor-service-type |
292 | (tor-configuration | |
293 | (config-file (local-file "my-torrc")))) | |
9d3994f7 LC |
294 | %base-services))) |
295 | EOF | |
296 | ||
297 | cat > "$tmpdir/my-torrc"<<EOF | |
298 | # This is an example file. | |
299 | EOF | |
300 | ||
301 | # In both cases 'my-torrc' should be properly resolved. | |
302 | guix system build "$tmpdir/config.scm" -n | |
303 | (cd "$tmpdir"; guix system build "config.scm" -n) | |
0649321d | 304 | |
f43ffee9 LC |
305 | # Check that we get a warning when passing 'local-file' a non-literal relative |
306 | # file name. | |
307 | cat > "$tmpdir/config.scm" <<EOF | |
308 | (use-modules (guix)) | |
309 | ||
310 | (define (bad-local-file file) | |
311 | (local-file file)) | |
312 | ||
313 | (bad-local-file "whatever.scm") | |
314 | EOF | |
315 | ! guix system build "$tmpdir/config.scm" -n | |
316 | guix system build "$tmpdir/config.scm" -n 2>&1 | \ | |
317 | grep "config\.scm:4:2: warning:.*whatever.*relative to current directory" | |
318 | ||
0649321d LC |
319 | # Searching. |
320 | guix system search tor | grep "^name: tor" | |
6ac8b735 | 321 | guix system search tor | grep "^shepherdnames: tor" |
0649321d | 322 | guix system search anonym network | grep "^name: tor" |
9e2523c2 LC |
323 | guix system search . > "$tmpdir/search" |
324 | test $(wc -l < "$tmpdir/search") -gt 500 | |
325 | rm "$tmpdir/search" | |
8e88f6fa CM |
326 | |
327 | # Below, use -n (--dry-run) for the tests because if we actually tried to | |
328 | # build these images, the commands would take hours to run in the worst case. | |
329 | ||
330 | # Verify that the examples can be built. | |
09a9f109 | 331 | for example in gnu/system/examples/*.tmpl; do |
59bcffa3 JN |
332 | if echo "$example" | grep hurd; then |
333 | target="--target=i586-pc-gnu" | |
334 | else | |
335 | target= | |
336 | fi | |
337 | guix system -n disk-image $target "$example" | |
8e88f6fa CM |
338 | done |
339 | ||
340 | # Verify that the disk image types can be built. | |
341 | guix system -n vm gnu/system/examples/vm-image.tmpl | |
ee2a5da8 | 342 | guix system -n image -t qcow2 gnu/system/examples/vm-image.tmpl |
8e88f6fa CM |
343 | # This invocation was taken care of in the loop above: |
344 | # guix system -n disk-image gnu/system/examples/bare-bones.tmpl | |
313f4926 | 345 | guix system -n disk-image -t iso9660 gnu/system/examples/bare-bones.tmpl |
8e88f6fa | 346 | guix system -n docker-image gnu/system/examples/docker-image.tmpl |
313f4926 MO |
347 | |
348 | # Verify that at least the raw image type is available. | |
349 | guix system --list-image-types | grep "raw" |