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