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