gnu: roffit: Adjust install phase.
[jackhill/guix/guix.git] / tests / guix-system.sh
... / ...
CommitLineData
1# GNU Guix --- Functional package management for GNU
2# Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3# Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
4# Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
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#
22# Test 'guix system', mostly error reporting.
23#
24
25set -e
26
27guix system --version
28
29tmpfile="t-guix-system-$$"
30errorfile="t-guix-system-error-$$"
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
40
41# Reporting of syntax errors.
42
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
56
57
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
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
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
112 (bootloader (GRUB-config (target "/dev/sdX"))) ; 9
113 (file-systems (cons (file-system
114 (device (file-system-label "root"))
115 (mount-point "/")
116 (type "ext4"))
117 %base-file-systems)))
118EOF
119
120if guix system build "$tmpfile" -n 2> "$errorfile"
121then false
122else
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
129 then
130 # FIXME: With Guile 2.2.0 the error is reported on line 4.
131 # See <http://bugs.gnu.org/26107>.
132 grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
133 else
134 grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
135 fi
136fi
137
138cat > "$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)
147EOF
148
149if guix system build "$tmpfile" -n 2> "$errorfile"
150then false
151else
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"
156fi
157
158OS_BASE='
159 (host-name "antelope")
160 (timezone "Europe/Paris")
161 (locale "en_US.UTF-8")
162
163 (bootloader (bootloader-configuration
164 (bootloader grub-bootloader)
165 (target "/dev/sdX")))
166 (file-systems (cons (file-system
167 (device (file-system-label "root"))
168 (mount-point "/")
169 (type "ext4"))
170 %base-file-systems))
171'
172
173# Reporting of duplicate service identifiers.
174
175cat > "$tmpfile" <<EOF
176(use-modules (gnu))
177(use-service-modules networking)
178
179(operating-system
180 $OS_BASE
181 (services (cons* (service dhcp-client-service-type)
182 (service dhcp-client-service-type) ;twice!
183 %base-services)))
184EOF
185
186if guix system vm "$tmpfile" 2> "$errorfile"
187then
188 # This must not succeed.
189 exit 1
190else
191 grep "service 'networking'.*more than once" "$errorfile"
192fi
193
194# Reporting unmet shepherd requirements.
195
196cat > "$tmpfile" <<EOF
197(use-modules (gnu) (gnu services shepherd))
198(use-service-modules networking)
199
200(define buggy-service-type
201 (shepherd-service-type
202 'buggy
203 (lambda _
204 (shepherd-service
205 (provision '(buggy!))
206 (requirement '(does-not-exist))
207 (start #t)))))
208
209(operating-system
210 $OS_BASE
211 (services (cons (service buggy-service-type #t)
212 %base-services)))
213EOF
214
215if guix system build "$tmpfile" 2> "$errorfile"
216then
217 exit 1
218else
219 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
220fi
221
222# Reporting inconsistent user accounts.
223
224make_user_config ()
225{
226 cat > "$tmpfile" <<EOF
227(use-modules (gnu))
228(use-service-modules networking)
229
230(operating-system
231 (host-name "antelope")
232 (timezone "Europe/Paris")
233 (locale "en_US.UTF-8")
234
235 (bootloader (bootloader-configuration
236 (bootloader grub-bootloader)
237 (target "/dev/sdX")))
238 (file-systems (cons (file-system
239 (device (file-system-label "root"))
240 (mount-point "/")
241 (type "ext4"))
242 %base-file-systems))
243 (users (list (user-account
244 (name "dave")
245 (home-directory "/home/dave")
246 (group "$1")
247 (supplementary-groups '("$2"))))))
248EOF
249}
250
251make_user_config "users" "wheel"
252guix system build "$tmpfile" -n # succeeds
253
254guix system build "$tmpfile" -d # succeeds
255guix system build "$tmpfile" -d | grep '\.drv$'
256
257guix system vm "$tmpfile" -d # succeeds
258guix system vm "$tmpfile" -d | grep '\.drv$'
259
260# Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
261drv1="`guix system vm "$tmpfile" -d`"
262drv2="`guix system vm "$tmpfile" -d`"
263test "$drv1" = "$drv2"
264drv1="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
265drv2="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
266test "$drv1" = "$drv2"
267
268make_user_config "group-that-does-not-exist" "users"
269if guix system build "$tmpfile" -n 2> "$errorfile"
270then false
271else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
272
273make_user_config "users" "group-that-does-not-exist"
274if guix system build "$tmpfile" -n 2> "$errorfile"
275then false
276else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
277
278# Try 'local-file' and relative file name resolution.
279
280cat > "$tmpdir/config.scm"<<EOF
281(use-modules (gnu))
282(use-service-modules networking)
283
284(operating-system
285 $OS_BASE
286 (services (cons (service tor-service-type
287 (tor-configuration
288 (config-file (local-file "my-torrc"))))
289 %base-services)))
290EOF
291
292cat > "$tmpdir/my-torrc"<<EOF
293# This is an example file.
294EOF
295
296# In both cases 'my-torrc' should be properly resolved.
297guix system build "$tmpdir/config.scm" -n
298(cd "$tmpdir"; guix system build "config.scm" -n)
299
300# Searching.
301guix system search tor | grep "^name: tor"
302guix system search tor | grep "^shepherdnames: tor"
303guix system search anonym network | grep "^name: tor"
304
305# Below, use -n (--dry-run) for the tests because if we actually tried to
306# build these images, the commands would take hours to run in the worst case.
307
308# Verify that the examples can be built.
309for example in gnu/system/examples/*.tmpl; do
310 if echo "$example" | grep hurd; then
311 target="--target=i586-pc-gnu"
312 else
313 target=
314 fi
315 guix system -n disk-image $target "$example"
316done
317
318# Verify that the disk image types can be built.
319guix system -n vm gnu/system/examples/vm-image.tmpl
320guix system -n vm-image gnu/system/examples/vm-image.tmpl
321# This invocation was taken care of in the loop above:
322# guix system -n disk-image gnu/system/examples/bare-bones.tmpl
323guix system -n disk-image --file-system-type=iso9660 gnu/system/examples/bare-bones.tmpl
324guix system -n docker-image gnu/system/examples/docker-image.tmpl