doc: Document 'guix-service-type'.
[jackhill/guix/guix.git] / tests / guix-system.sh
CommitLineData
c1202fb1 1# GNU Guix --- Functional package management for GNU
6ac8b735 2# Copyright © 2014, 2015, 2016, 2017, 2018 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
112 (bootloader (GRUB-config (device "/dev/sdX"))) ; 9
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
2d2651e7 133OS_BASE='
116244df
LC
134 (host-name "antelope")
135 (timezone "Europe/Paris")
136 (locale "en_US.UTF-8")
137
fdfdecdb
TGR
138 (bootloader (bootloader-configuration
139 (bootloader grub-bootloader)
140 (device "/dev/sdX")))
116244df 141 (file-systems (cons (file-system
9ceeca08 142 (device (file-system-label "root"))
116244df
LC
143 (mount-point "/")
144 (type "ext4"))
145 %base-file-systems))
2d2651e7 146'
116244df 147
2d2651e7
LC
148# Reporting of duplicate service identifiers.
149
150cat > "$tmpfile" <<EOF
151(use-modules (gnu))
152(use-service-modules networking)
153
154(operating-system
155 $OS_BASE
116244df
LC
156 (services (cons* (dhcp-client-service)
157 (dhcp-client-service) ;twice!
158 %base-services)))
159EOF
160
161if guix system vm "$tmpfile" 2> "$errorfile"
162then
163 # This must not succeed.
164 exit 1
165else
166 grep "service 'networking'.*more than once" "$errorfile"
167fi
0c09a306 168
0190c1c0 169# Reporting unmet shepherd requirements.
2d2651e7
LC
170
171cat > "$tmpfile" <<EOF
0190c1c0 172(use-modules (gnu) (gnu services shepherd))
2d2651e7
LC
173(use-service-modules networking)
174
175(define buggy-service-type
d4053c71 176 (shepherd-service-type
2d2651e7
LC
177 'buggy
178 (lambda _
d4053c71 179 (shepherd-service
2d2651e7
LC
180 (provision '(buggy!))
181 (requirement '(does-not-exist))
182 (start #t)))))
183
184(operating-system
185 $OS_BASE
186 (services (cons (service buggy-service-type #t)
187 %base-services)))
188EOF
189
190if guix system build "$tmpfile" 2> "$errorfile"
191then
192 exit 1
193else
a8492735 194 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
2d2651e7
LC
195fi
196
197# Reporting inconsistent user accounts.
198
0c09a306
LC
199make_user_config ()
200{
201 cat > "$tmpfile" <<EOF
202(use-modules (gnu))
203(use-service-modules networking)
204
205(operating-system
206 (host-name "antelope")
207 (timezone "Europe/Paris")
208 (locale "en_US.UTF-8")
209
fdfdecdb
TGR
210 (bootloader (bootloader-configuration
211 (bootloader grub-bootloader)
212 (device "/dev/sdX")))
0c09a306 213 (file-systems (cons (file-system
9ceeca08 214 (device (file-system-label "root"))
0c09a306
LC
215 (mount-point "/")
216 (type "ext4"))
217 %base-file-systems))
218 (users (list (user-account
219 (name "dave")
220 (home-directory "/home/dave")
221 (group "$1")
222 (supplementary-groups '("$2"))))))
223EOF
224}
225
226make_user_config "users" "wheel"
227guix system build "$tmpfile" -n # succeeds
228
f3f427c2
LC
229guix system build "$tmpfile" -d # succeeds
230guix system build "$tmpfile" -d | grep '\.drv$'
231
232guix system vm "$tmpfile" -d # succeeds
233guix system vm "$tmpfile" -d | grep '\.drv$'
234
1540075c
LC
235# Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
236drv1="`guix system vm "$tmpfile" -d`"
237drv2="`guix system vm "$tmpfile" -d`"
238test "$drv1" = "$drv2"
239drv1="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
240drv2="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
241test "$drv1" = "$drv2"
242
0c09a306
LC
243make_user_config "group-that-does-not-exist" "users"
244if guix system build "$tmpfile" -n 2> "$errorfile"
245then false
246else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
247
248make_user_config "users" "group-that-does-not-exist"
249if guix system build "$tmpfile" -n 2> "$errorfile"
250then false
251else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
9d3994f7
LC
252
253# Try 'local-file' and relative file name resolution.
254
255cat > "$tmpdir/config.scm"<<EOF
256(use-modules (gnu))
257(use-service-modules networking)
258
259(operating-system
260 $OS_BASE
261 (services (cons (tor-service (local-file "my-torrc"))
262 %base-services)))
263EOF
264
265cat > "$tmpdir/my-torrc"<<EOF
266# This is an example file.
267EOF
268
269# In both cases 'my-torrc' should be properly resolved.
270guix system build "$tmpdir/config.scm" -n
271(cd "$tmpdir"; guix system build "config.scm" -n)
0649321d
LC
272
273# Searching.
274guix system search tor | grep "^name: tor"
6ac8b735 275guix system search tor | grep "^shepherdnames: tor"
0649321d 276guix system search anonym network | grep "^name: tor"
8e88f6fa
CM
277
278# Below, use -n (--dry-run) for the tests because if we actually tried to
279# build these images, the commands would take hours to run in the worst case.
280
281# Verify that the examples can be built.
282for example in gnu/system/examples/*; do
283 guix system -n disk-image $example
284done
285
286# Verify that the disk image types can be built.
287guix system -n vm gnu/system/examples/vm-image.tmpl
288guix system -n vm-image gnu/system/examples/vm-image.tmpl
289# This invocation was taken care of in the loop above:
290# guix system -n disk-image gnu/system/examples/bare-bones.tmpl
291guix system -n disk-image --file-system-type=iso9660 gnu/system/examples/bare-bones.tmpl
292guix system -n docker-image gnu/system/examples/docker-image.tmpl