ui: Ignore 'raise-exception' frames when reporting exceptions.
[jackhill/guix/guix.git] / tests / guix-system.sh
CommitLineData
c1202fb1 1# GNU Guix --- Functional package management for GNU
47212fc7 2# Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 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
25set -e
26
27guix system --version
28
29tmpfile="t-guix-system-$$"
30errorfile="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.)
36tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
37mkdir "$tmpdir"
38
39trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
c1202fb1 40
116244df
LC
41# Reporting of syntax errors.
42
c1202fb1
LC
43cat > "$tmpfile"<<EOF
44;; This is line 1, and the next one is line 2.
45 (operating-system)
46;; The 'T' is at column 3.
47EOF
48
49if guix system vm "$tmpfile" 2> "$errorfile"
50then
51 # This must not succeed.
52 exit 1
53else
54 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
55fi
116244df
LC
56
57
a6e22d84
LC
58cat > "$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!
62EOF
63
64if guix system vm "$tmpfile" 2> "$errorfile"
65then
66 # This must not succeed.
67 exit 1
68else
69 grep "$tmpfile:4:1: missing closing paren" "$errorfile"
70fi
71
72
c5a4a92f
LC
73# Reporting of module not found errors.
74
75cat > "$tmpfile" <<EOF
76;; Line 1.
77(use-modules (gnu))
78 (use-service-modules openssh)
79EOF
80
81if guix system build "$tmpfile" -n 2> "$errorfile"
82then false
83else
84 grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
85 grep "Try.*use-service-modules ssh" "$errorfile"
86fi
87
88cat > "$tmpfile" <<EOF
89;; Line 1.
90(use-modules (gnu))
91 (use-package-modules qemu)
92EOF
93
94if guix system build "$tmpfile" -n 2> "$errorfile"
95then false
96else
97 grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
98 grep "Try.*use-package-modules virtualization" "$errorfile"
99fi
100
2abcc97f
LC
101# Reporting of unbound variables.
102
103cat > "$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)))
118EOF
119
120if guix system build "$tmpfile" -n 2> "$errorfile"
121then false
122else
13159c68
LC
123 if test "`guile -c '(display (effective-version))'`" = 2.2
124 then
125 # FIXME: With Guile 2.2.0 the error is reported on line 4.
126 # See <http://bugs.gnu.org/26107>.
7acdecec 127 grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
13159c68 128 else
7acdecec 129 grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
13159c68 130 fi
2abcc97f
LC
131fi
132
47212fc7
LC
133cat > "$tmpfile" <<EOF
134(use-modules (gnu)) ; 1
135
136(operating-system ; 3
137 (file-systems (cons (file-system ; 4
138 (device (file-system-label "root"))
139 (mount-point "/") ; 6
140 (type "ext4")))) ; 7 (!!)
141 %base-file-systems)
142EOF
143
144if guix system build "$tmpfile" -n 2> "$errorfile"
145then false
146else
147 # Here '%base-file-systems' appears as if it were a field specified of the
148 # enclosing 'operating-system' form due to parenthesis mismatch.
149 grep "$tmpfile:3:[0-9]\+:.*%base-file-system.*invalid field specifier" \
150 "$errorfile"
151fi
152
2d2651e7 153OS_BASE='
116244df
LC
154 (host-name "antelope")
155 (timezone "Europe/Paris")
156 (locale "en_US.UTF-8")
157
fdfdecdb
TGR
158 (bootloader (bootloader-configuration
159 (bootloader grub-bootloader)
f61e6e52 160 (target "/dev/sdX")))
116244df 161 (file-systems (cons (file-system
9ceeca08 162 (device (file-system-label "root"))
116244df
LC
163 (mount-point "/")
164 (type "ext4"))
165 %base-file-systems))
2d2651e7 166'
116244df 167
2d2651e7
LC
168# Reporting of duplicate service identifiers.
169
170cat > "$tmpfile" <<EOF
171(use-modules (gnu))
172(use-service-modules networking)
173
174(operating-system
175 $OS_BASE
39d7fdce
LC
176 (services (cons* (service dhcp-client-service-type)
177 (service dhcp-client-service-type) ;twice!
116244df
LC
178 %base-services)))
179EOF
180
181if guix system vm "$tmpfile" 2> "$errorfile"
182then
183 # This must not succeed.
184 exit 1
185else
186 grep "service 'networking'.*more than once" "$errorfile"
187fi
0c09a306 188
0190c1c0 189# Reporting unmet shepherd requirements.
2d2651e7
LC
190
191cat > "$tmpfile" <<EOF
0190c1c0 192(use-modules (gnu) (gnu services shepherd))
2d2651e7
LC
193(use-service-modules networking)
194
195(define buggy-service-type
d4053c71 196 (shepherd-service-type
2d2651e7
LC
197 'buggy
198 (lambda _
d4053c71 199 (shepherd-service
2d2651e7
LC
200 (provision '(buggy!))
201 (requirement '(does-not-exist))
202 (start #t)))))
203
204(operating-system
205 $OS_BASE
206 (services (cons (service buggy-service-type #t)
207 %base-services)))
208EOF
209
210if guix system build "$tmpfile" 2> "$errorfile"
211then
212 exit 1
213else
a8492735 214 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
2d2651e7
LC
215fi
216
217# Reporting inconsistent user accounts.
218
0c09a306
LC
219make_user_config ()
220{
221 cat > "$tmpfile" <<EOF
222(use-modules (gnu))
223(use-service-modules networking)
224
225(operating-system
226 (host-name "antelope")
227 (timezone "Europe/Paris")
228 (locale "en_US.UTF-8")
229
fdfdecdb
TGR
230 (bootloader (bootloader-configuration
231 (bootloader grub-bootloader)
f61e6e52 232 (target "/dev/sdX")))
0c09a306 233 (file-systems (cons (file-system
9ceeca08 234 (device (file-system-label "root"))
0c09a306
LC
235 (mount-point "/")
236 (type "ext4"))
237 %base-file-systems))
238 (users (list (user-account
239 (name "dave")
240 (home-directory "/home/dave")
241 (group "$1")
242 (supplementary-groups '("$2"))))))
243EOF
244}
245
246make_user_config "users" "wheel"
247guix system build "$tmpfile" -n # succeeds
248
f3f427c2
LC
249guix system build "$tmpfile" -d # succeeds
250guix system build "$tmpfile" -d | grep '\.drv$'
251
252guix system vm "$tmpfile" -d # succeeds
253guix system vm "$tmpfile" -d | grep '\.drv$'
254
1540075c
LC
255# Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
256drv1="`guix system vm "$tmpfile" -d`"
257drv2="`guix system vm "$tmpfile" -d`"
258test "$drv1" = "$drv2"
259drv1="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
260drv2="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
261test "$drv1" = "$drv2"
262
0c09a306
LC
263make_user_config "group-that-does-not-exist" "users"
264if guix system build "$tmpfile" -n 2> "$errorfile"
265then false
266else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
267
268make_user_config "users" "group-that-does-not-exist"
269if guix system build "$tmpfile" -n 2> "$errorfile"
270then false
271else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
9d3994f7
LC
272
273# Try 'local-file' and relative file name resolution.
274
275cat > "$tmpdir/config.scm"<<EOF
276(use-modules (gnu))
277(use-service-modules networking)
278
279(operating-system
280 $OS_BASE
84a2de36
LC
281 (services (cons (service tor-service-type
282 (tor-configuration
283 (config-file (local-file "my-torrc"))))
9d3994f7
LC
284 %base-services)))
285EOF
286
287cat > "$tmpdir/my-torrc"<<EOF
288# This is an example file.
289EOF
290
291# In both cases 'my-torrc' should be properly resolved.
292guix system build "$tmpdir/config.scm" -n
293(cd "$tmpdir"; guix system build "config.scm" -n)
0649321d
LC
294
295# Searching.
296guix system search tor | grep "^name: tor"
6ac8b735 297guix system search tor | grep "^shepherdnames: tor"
0649321d 298guix system search anonym network | grep "^name: tor"
8e88f6fa
CM
299
300# Below, use -n (--dry-run) for the tests because if we actually tried to
301# build these images, the commands would take hours to run in the worst case.
302
303# Verify that the examples can be built.
09a9f109
LC
304for example in gnu/system/examples/*.tmpl; do
305 guix system -n disk-image "$example"
8e88f6fa
CM
306done
307
308# Verify that the disk image types can be built.
309guix system -n vm gnu/system/examples/vm-image.tmpl
310guix system -n vm-image gnu/system/examples/vm-image.tmpl
311# This invocation was taken care of in the loop above:
312# guix system -n disk-image gnu/system/examples/bare-bones.tmpl
313guix system -n disk-image --file-system-type=iso9660 gnu/system/examples/bare-bones.tmpl
314guix system -n docker-image gnu/system/examples/docker-image.tmpl