gtk and wayland update
[jackhill/guix/guix.git] / tests / guix-system.sh
CommitLineData
c1202fb1 1# GNU Guix --- Functional package management for GNU
5a573139 2# Copyright © 2014-2022 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
524c9800 54 cat "$errorfile"
c1202fb1
LC
55 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
56fi
116244df
LC
57
58
a6e22d84
LC
59cat > "$tmpfile"<<EOF
60;; This is line 1, and the next one is line 2.
61 (operating-system
62;; This is line 3, and there is no closing paren!
63EOF
64
65if guix system vm "$tmpfile" 2> "$errorfile"
66then
67 # This must not succeed.
68 exit 1
69else
524c9800
LC
70 cat "$errorfile"
71
72 # Guile 3.0.6 gets line/column numbers for 'read-error' wrong
73 # (zero-indexed): <https://bugs.gnu.org/48089>.
74 grep "$tmpfile:4:1: missing closing paren" "$errorfile" || \
75 grep "$tmpfile:3:0: missing closing paren" "$errorfile"
a6e22d84
LC
76fi
77
78
c5a4a92f
LC
79# Reporting of module not found errors.
80
81cat > "$tmpfile" <<EOF
82;; Line 1.
83(use-modules (gnu))
84 (use-service-modules openssh)
85EOF
86
87if guix system build "$tmpfile" -n 2> "$errorfile"
88then false
89else
90 grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
91 grep "Try.*use-service-modules ssh" "$errorfile"
92fi
93
94cat > "$tmpfile" <<EOF
95;; Line 1.
96(use-modules (gnu))
97 (use-package-modules qemu)
98EOF
99
100if guix system build "$tmpfile" -n 2> "$errorfile"
101then false
102else
103 grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
104 grep "Try.*use-package-modules virtualization" "$errorfile"
105fi
106
2abcc97f
LC
107# Reporting of unbound variables.
108
109cat > "$tmpfile" <<EOF
110(use-modules (gnu)) ; 1
111(use-service-modules networking) ; 2
112
113(operating-system ; 4
114 (host-name "antelope") ; 5
115 (timezone "Europe/Paris") ; 6
116 (locale "en_US.UTF-8") ; 7
117
2ca982ff 118 (bootloader (GRUB-config (targets (list "/dev/sdX")))) ; 9
2abcc97f 119 (file-systems (cons (file-system
9ceeca08 120 (device (file-system-label "root"))
2abcc97f
LC
121 (mount-point "/")
122 (type "ext4"))
123 %base-file-systems)))
124EOF
125
126if guix system build "$tmpfile" -n 2> "$errorfile"
127then false
128else
1bb30aa3
LC
129 if test "`guile -c '(display (effective-version))'`" = 3.0
130 then
131 # FIXME: With Guile 3.3.0 the error is reported on line 11.
132 # See <https://bugs.gnu.org/38388>.
133 grep "$tmpfile:[0-9]\+:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
134 elif test "`guile -c '(display (effective-version))'`" = 2.2
13159c68
LC
135 then
136 # FIXME: With Guile 2.2.0 the error is reported on line 4.
137 # See <http://bugs.gnu.org/26107>.
7acdecec 138 grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
13159c68 139 else
7acdecec 140 grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
13159c68 141 fi
2abcc97f
LC
142fi
143
47212fc7
LC
144cat > "$tmpfile" <<EOF
145(use-modules (gnu)) ; 1
146
147(operating-system ; 3
148 (file-systems (cons (file-system ; 4
149 (device (file-system-label "root"))
150 (mount-point "/") ; 6
151 (type "ext4")))) ; 7 (!!)
152 %base-file-systems)
153EOF
154
155if guix system build "$tmpfile" -n 2> "$errorfile"
156then false
157else
158 # Here '%base-file-systems' appears as if it were a field specified of the
159 # enclosing 'operating-system' form due to parenthesis mismatch.
160 grep "$tmpfile:3:[0-9]\+:.*%base-file-system.*invalid field specifier" \
161 "$errorfile"
162fi
163
2d2651e7 164OS_BASE='
116244df
LC
165 (host-name "antelope")
166 (timezone "Europe/Paris")
167 (locale "en_US.UTF-8")
168
fdfdecdb
TGR
169 (bootloader (bootloader-configuration
170 (bootloader grub-bootloader)
2ca982ff 171 (targets (list "/dev/sdX"))))
116244df 172 (file-systems (cons (file-system
9ceeca08 173 (device (file-system-label "root"))
116244df
LC
174 (mount-point "/")
175 (type "ext4"))
176 %base-file-systems))
2d2651e7 177'
116244df 178
2d2651e7
LC
179# Reporting of duplicate service identifiers.
180
181cat > "$tmpfile" <<EOF
182(use-modules (gnu))
183(use-service-modules networking)
184
185(operating-system
186 $OS_BASE
39d7fdce
LC
187 (services (cons* (service dhcp-client-service-type)
188 (service dhcp-client-service-type) ;twice!
116244df
LC
189 %base-services)))
190EOF
191
192if guix system vm "$tmpfile" 2> "$errorfile"
193then
194 # This must not succeed.
195 exit 1
196else
197 grep "service 'networking'.*more than once" "$errorfile"
198fi
0c09a306 199
0190c1c0 200# Reporting unmet shepherd requirements.
2d2651e7
LC
201
202cat > "$tmpfile" <<EOF
0190c1c0 203(use-modules (gnu) (gnu services shepherd))
2d2651e7
LC
204(use-service-modules networking)
205
206(define buggy-service-type
d4053c71 207 (shepherd-service-type
2d2651e7
LC
208 'buggy
209 (lambda _
d4053c71 210 (shepherd-service
2d2651e7
LC
211 (provision '(buggy!))
212 (requirement '(does-not-exist))
0d22fc8d
LC
213 (start #t)))
214 (description "Buggy.")))
2d2651e7
LC
215
216(operating-system
217 $OS_BASE
218 (services (cons (service buggy-service-type #t)
219 %base-services)))
220EOF
221
222if guix system build "$tmpfile" 2> "$errorfile"
223then
224 exit 1
225else
a8492735 226 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
2d2651e7
LC
227fi
228
229# Reporting inconsistent user accounts.
230
0c09a306
LC
231make_user_config ()
232{
233 cat > "$tmpfile" <<EOF
234(use-modules (gnu))
235(use-service-modules networking)
236
237(operating-system
238 (host-name "antelope")
239 (timezone "Europe/Paris")
240 (locale "en_US.UTF-8")
241
fdfdecdb
TGR
242 (bootloader (bootloader-configuration
243 (bootloader grub-bootloader)
2ca982ff 244 (targets (list "/dev/sdX"))))
0c09a306 245 (file-systems (cons (file-system
9ceeca08 246 (device (file-system-label "root"))
0c09a306
LC
247 (mount-point "/")
248 (type "ext4"))
249 %base-file-systems))
250 (users (list (user-account
251 (name "dave")
252 (home-directory "/home/dave")
253 (group "$1")
254 (supplementary-groups '("$2"))))))
255EOF
256}
257
258make_user_config "users" "wheel"
259guix system build "$tmpfile" -n # succeeds
260
f3f427c2
LC
261guix system build "$tmpfile" -d # succeeds
262guix system build "$tmpfile" -d | grep '\.drv$'
263
264guix system vm "$tmpfile" -d # succeeds
265guix system vm "$tmpfile" -d | grep '\.drv$'
266
1540075c
LC
267# Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
268drv1="`guix system vm "$tmpfile" -d`"
269drv2="`guix system vm "$tmpfile" -d`"
270test "$drv1" = "$drv2"
e74baa12
MO
271drv1="`guix system image -t iso9660 "$tmpfile" -d`"
272drv2="`guix system image -t iso9660 "$tmpfile" -d`"
1540075c
LC
273test "$drv1" = "$drv2"
274
b8415243
LC
275# Check whether the graph commands work as expected.
276guix system extension-graph "$tmpfile" | grep 'label = "file-systems"'
277guix system shepherd-graph "$tmpfile" | grep 'label = "guix-daemon"'
278
0c09a306
LC
279make_user_config "group-that-does-not-exist" "users"
280if guix system build "$tmpfile" -n 2> "$errorfile"
281then false
282else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
283
284make_user_config "users" "group-that-does-not-exist"
285if guix system build "$tmpfile" -n 2> "$errorfile"
286then false
287else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
9d3994f7
LC
288
289# Try 'local-file' and relative file name resolution.
290
291cat > "$tmpdir/config.scm"<<EOF
292(use-modules (gnu))
293(use-service-modules networking)
294
295(operating-system
296 $OS_BASE
84a2de36
LC
297 (services (cons (service tor-service-type
298 (tor-configuration
299 (config-file (local-file "my-torrc"))))
9d3994f7
LC
300 %base-services)))
301EOF
302
303cat > "$tmpdir/my-torrc"<<EOF
304# This is an example file.
305EOF
306
307# In both cases 'my-torrc' should be properly resolved.
308guix system build "$tmpdir/config.scm" -n
309(cd "$tmpdir"; guix system build "config.scm" -n)
0649321d 310
f43ffee9
LC
311# Check that we get a warning when passing 'local-file' a non-literal relative
312# file name.
313cat > "$tmpdir/config.scm" <<EOF
314(use-modules (guix))
315
316(define (bad-local-file file)
317 (local-file file))
318
319(bad-local-file "whatever.scm")
320EOF
321! guix system build "$tmpdir/config.scm" -n
322guix system build "$tmpdir/config.scm" -n 2>&1 | \
323 grep "config\.scm:4:2: warning:.*whatever.*relative to current directory"
324
0649321d
LC
325# Searching.
326guix system search tor | grep "^name: tor"
6ac8b735 327guix system search tor | grep "^shepherdnames: tor"
0649321d 328guix system search anonym network | grep "^name: tor"
9e2523c2
LC
329guix system search . > "$tmpdir/search"
330test $(wc -l < "$tmpdir/search") -gt 500
331rm "$tmpdir/search"
8e88f6fa
CM
332
333# Below, use -n (--dry-run) for the tests because if we actually tried to
334# build these images, the commands would take hours to run in the worst case.
335
336# Verify that the examples can be built.
09a9f109 337for example in gnu/system/examples/*.tmpl; do
f1bbb06d
LC
338 case "$example" in
339 *hurd*)
340 options="--target=i586-pc-gnu";;
341 *asus*)
342 # 'asus-c201.tmpl' uses 'linux-libre-arm-generic', which is an
343 # ARM-only package.
344 options="--system=armhf-linux";;
93309efd
MC
345 *raspberry*)
346 # The Raspberry Pi templates 'linux-libre-arm64-generic', which is
347 # an ARM-only package.
348 options="--system=aarch64-linux";;
f1bbb06d
LC
349 *vm-image*)
350 # The VM image tries to build 'current-guix' as per 'guix pull'.
351 # Skip it.
352 continue
353 ;;
354 *)
355 options=""
356 ;;
357 esac
5a573139 358 guix system -n disk-image $options "$example"
8e88f6fa
CM
359done
360
31708431
LC
361# Make sure the desktop image can be built on major architectures.
362for system in x86_64-linux i686-linux aarch64-linux
363do
364 guix system -n image -s "$system" gnu/system/examples/desktop.tmpl
365done
366
6e8cdf1d 367# Verify that the images can be built.
f1bbb06d 368guix system -n vm gnu/system/examples/bare-bones.tmpl
6e8cdf1d 369guix system -n image gnu/system/images/pinebook-pro.scm
f1bbb06d 370guix system -n image -t qcow2 gnu/system/examples/bare-bones.tmpl
6e8cdf1d 371guix system -n image -t iso9660 gnu/system/examples/bare-bones.tmpl
8e88f6fa 372guix system -n docker-image gnu/system/examples/docker-image.tmpl
313f4926
MO
373
374# Verify that at least the raw image type is available.
375guix system --list-image-types | grep "raw"