Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / tests / guix-system.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 #
4 # This file is part of GNU Guix.
5 #
6 # GNU Guix is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or (at
9 # your option) any later version.
10 #
11 # GNU Guix is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 #
20 # Test 'guix system', mostly error reporting.
21 #
22
23 set -e
24
25 guix system --version
26
27 tmpfile="t-guix-system-$$"
28 errorfile="t-guix-system-error-$$"
29
30 # Note: This directory is chosen outside $builddir so that relative file name
31 # canonicalization doesn't mess up with 'current-source-directory', used by
32 # 'local-file' ('load' forces 'relative' for
33 # %FILE-PORT-NAME-CANONICALIZATION.)
34 tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
35 mkdir "$tmpdir"
36
37 trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
38
39 # Reporting of syntax errors.
40
41 cat > "$tmpfile"<<EOF
42 ;; This is line 1, and the next one is line 2.
43 (operating-system)
44 ;; The 'T' is at column 3.
45 EOF
46
47 if guix system vm "$tmpfile" 2> "$errorfile"
48 then
49 # This must not succeed.
50 exit 1
51 else
52 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
53 fi
54
55
56 cat > "$tmpfile"<<EOF
57 ;; This is line 1, and the next one is line 2.
58 (operating-system
59 ;; This is line 3, and there is no closing paren!
60 EOF
61
62 if guix system vm "$tmpfile" 2> "$errorfile"
63 then
64 # This must not succeed.
65 exit 1
66 else
67 grep "$tmpfile:4:1: missing closing paren" "$errorfile"
68 fi
69
70
71 # Reporting of module not found errors.
72
73 cat > "$tmpfile" <<EOF
74 ;; Line 1.
75 (use-modules (gnu))
76 (use-service-modules openssh)
77 EOF
78
79 if guix system build "$tmpfile" -n 2> "$errorfile"
80 then false
81 else
82 grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
83 grep "Try.*use-service-modules ssh" "$errorfile"
84 fi
85
86 cat > "$tmpfile" <<EOF
87 ;; Line 1.
88 (use-modules (gnu))
89 (use-package-modules qemu)
90 EOF
91
92 if guix system build "$tmpfile" -n 2> "$errorfile"
93 then false
94 else
95 grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
96 grep "Try.*use-package-modules virtualization" "$errorfile"
97 fi
98
99 # Reporting of unbound variables.
100
101 cat > "$tmpfile" <<EOF
102 (use-modules (gnu)) ; 1
103 (use-service-modules networking) ; 2
104
105 (operating-system ; 4
106 (host-name "antelope") ; 5
107 (timezone "Europe/Paris") ; 6
108 (locale "en_US.UTF-8") ; 7
109
110 (bootloader (GRUB-config (device "/dev/sdX"))) ; 9
111 (file-systems (cons (file-system
112 (device "root")
113 (title 'label)
114 (mount-point "/")
115 (type "ext4"))
116 %base-file-systems)))
117 EOF
118
119 if guix system build "$tmpfile" -n 2> "$errorfile"
120 then false
121 else
122 if test "`guile -c '(display (effective-version))'`" = 2.2
123 then
124 # FIXME: With Guile 2.2.0 the error is reported on line 4.
125 # See <http://bugs.gnu.org/26107>.
126 grep "$tmpfile:[49]:[0-9]: GRUB-config.*[Uu]nbound variable" "$errorfile"
127 else
128 grep "$tmpfile:9:[0-9]: GRUB-config.*[Uu]nbound variable" "$errorfile"
129 fi
130 fi
131
132 OS_BASE='
133 (host-name "antelope")
134 (timezone "Europe/Paris")
135 (locale "en_US.UTF-8")
136
137 (bootloader (grub-configuration (device "/dev/sdX")))
138 (file-systems (cons (file-system
139 (device "root")
140 (title (string->symbol "label"))
141 (mount-point "/")
142 (type "ext4"))
143 %base-file-systems))
144 '
145
146 # Reporting of duplicate service identifiers.
147
148 cat > "$tmpfile" <<EOF
149 (use-modules (gnu))
150 (use-service-modules networking)
151
152 (operating-system
153 $OS_BASE
154 (services (cons* (dhcp-client-service)
155 (dhcp-client-service) ;twice!
156 %base-services)))
157 EOF
158
159 if guix system vm "$tmpfile" 2> "$errorfile"
160 then
161 # This must not succeed.
162 exit 1
163 else
164 grep "service 'networking'.*more than once" "$errorfile"
165 fi
166
167 # Reporting unmet shepherd requirements.
168
169 cat > "$tmpfile" <<EOF
170 (use-modules (gnu) (gnu services shepherd))
171 (use-service-modules networking)
172
173 (define buggy-service-type
174 (shepherd-service-type
175 'buggy
176 (lambda _
177 (shepherd-service
178 (provision '(buggy!))
179 (requirement '(does-not-exist))
180 (start #t)))))
181
182 (operating-system
183 $OS_BASE
184 (services (cons (service buggy-service-type #t)
185 %base-services)))
186 EOF
187
188 if guix system build "$tmpfile" 2> "$errorfile"
189 then
190 exit 1
191 else
192 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
193 fi
194
195 # Reporting inconsistent user accounts.
196
197 make_user_config ()
198 {
199 cat > "$tmpfile" <<EOF
200 (use-modules (gnu))
201 (use-service-modules networking)
202
203 (operating-system
204 (host-name "antelope")
205 (timezone "Europe/Paris")
206 (locale "en_US.UTF-8")
207
208 (bootloader (grub-configuration (device "/dev/sdX")))
209 (file-systems (cons (file-system
210 (device "root")
211 (title 'label)
212 (mount-point "/")
213 (type "ext4"))
214 %base-file-systems))
215 (users (list (user-account
216 (name "dave")
217 (home-directory "/home/dave")
218 (group "$1")
219 (supplementary-groups '("$2"))))))
220 EOF
221 }
222
223 make_user_config "users" "wheel"
224 guix system build "$tmpfile" -n # succeeds
225
226 guix system build "$tmpfile" -d # succeeds
227 guix system build "$tmpfile" -d | grep '\.drv$'
228
229 guix system vm "$tmpfile" -d # succeeds
230 guix system vm "$tmpfile" -d | grep '\.drv$'
231
232 make_user_config "group-that-does-not-exist" "users"
233 if guix system build "$tmpfile" -n 2> "$errorfile"
234 then false
235 else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
236
237 make_user_config "users" "group-that-does-not-exist"
238 if guix system build "$tmpfile" -n 2> "$errorfile"
239 then false
240 else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
241
242 # Try 'local-file' and relative file name resolution.
243
244 cat > "$tmpdir/config.scm"<<EOF
245 (use-modules (gnu))
246 (use-service-modules networking)
247
248 (operating-system
249 $OS_BASE
250 (services (cons (tor-service (local-file "my-torrc"))
251 %base-services)))
252 EOF
253
254 cat > "$tmpdir/my-torrc"<<EOF
255 # This is an example file.
256 EOF
257
258 # In both cases 'my-torrc' should be properly resolved.
259 guix system build "$tmpdir/config.scm" -n
260 (cd "$tmpdir"; guix system build "config.scm" -n)
261
262 # Searching.
263 guix system search tor | grep "^name: tor"
264 guix system search anonym network | grep "^name: tor"