Commit | Line | Data |
---|---|---|
c1202fb1 | 1 | # GNU Guix --- Functional package management for GNU |
a8492735 | 2 | # Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
c1202fb1 LC |
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 | # | |
9d3994f7 | 20 | # Test 'guix system', mostly error reporting. |
c1202fb1 LC |
21 | # |
22 | ||
23 | set -e | |
24 | ||
25 | guix system --version | |
26 | ||
27 | tmpfile="t-guix-system-$$" | |
28 | errorfile="t-guix-system-error-$$" | |
9d3994f7 LC |
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 | |
c1202fb1 | 38 | |
116244df LC |
39 | # Reporting of syntax errors. |
40 | ||
c1202fb1 LC |
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 | |
116244df LC |
54 | |
55 | ||
2abcc97f LC |
56 | # Reporting of unbound variables. |
57 | ||
58 | cat > "$tmpfile" <<EOF | |
59 | (use-modules (gnu)) ; 1 | |
60 | (use-service-modules networking) ; 2 | |
61 | ||
62 | (operating-system ; 4 | |
63 | (host-name "antelope") ; 5 | |
64 | (timezone "Europe/Paris") ; 6 | |
65 | (locale "en_US.UTF-8") ; 7 | |
66 | ||
67 | (bootloader (GRUB-config (device "/dev/sdX"))) ; 9 | |
68 | (file-systems (cons (file-system | |
69 | (device "root") | |
70 | (title 'label) | |
71 | (mount-point "/") | |
72 | (type "ext4")) | |
73 | %base-file-systems))) | |
74 | EOF | |
75 | ||
76 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
77 | then false | |
78 | else | |
79 | grep "$tmpfile:9:.*[Uu]nbound variable.*GRUB-config" "$errorfile" | |
80 | fi | |
81 | ||
2d2651e7 | 82 | OS_BASE=' |
116244df LC |
83 | (host-name "antelope") |
84 | (timezone "Europe/Paris") | |
85 | (locale "en_US.UTF-8") | |
86 | ||
87 | (bootloader (grub-configuration (device "/dev/sdX"))) | |
88 | (file-systems (cons (file-system | |
89 | (device "root") | |
2d2651e7 | 90 | (title (string->symbol "label")) |
116244df LC |
91 | (mount-point "/") |
92 | (type "ext4")) | |
93 | %base-file-systems)) | |
2d2651e7 | 94 | ' |
116244df | 95 | |
2d2651e7 LC |
96 | # Reporting of duplicate service identifiers. |
97 | ||
98 | cat > "$tmpfile" <<EOF | |
99 | (use-modules (gnu)) | |
100 | (use-service-modules networking) | |
101 | ||
102 | (operating-system | |
103 | $OS_BASE | |
116244df LC |
104 | (services (cons* (dhcp-client-service) |
105 | (dhcp-client-service) ;twice! | |
106 | %base-services))) | |
107 | EOF | |
108 | ||
109 | if guix system vm "$tmpfile" 2> "$errorfile" | |
110 | then | |
111 | # This must not succeed. | |
112 | exit 1 | |
113 | else | |
114 | grep "service 'networking'.*more than once" "$errorfile" | |
115 | fi | |
0c09a306 | 116 | |
0190c1c0 | 117 | # Reporting unmet shepherd requirements. |
2d2651e7 LC |
118 | |
119 | cat > "$tmpfile" <<EOF | |
0190c1c0 | 120 | (use-modules (gnu) (gnu services shepherd)) |
2d2651e7 LC |
121 | (use-service-modules networking) |
122 | ||
123 | (define buggy-service-type | |
d4053c71 | 124 | (shepherd-service-type |
2d2651e7 LC |
125 | 'buggy |
126 | (lambda _ | |
d4053c71 | 127 | (shepherd-service |
2d2651e7 LC |
128 | (provision '(buggy!)) |
129 | (requirement '(does-not-exist)) | |
130 | (start #t))))) | |
131 | ||
132 | (operating-system | |
133 | $OS_BASE | |
134 | (services (cons (service buggy-service-type #t) | |
135 | %base-services))) | |
136 | EOF | |
137 | ||
138 | if guix system build "$tmpfile" 2> "$errorfile" | |
139 | then | |
140 | exit 1 | |
141 | else | |
a8492735 | 142 | grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile" |
2d2651e7 LC |
143 | fi |
144 | ||
145 | # Reporting inconsistent user accounts. | |
146 | ||
0c09a306 LC |
147 | make_user_config () |
148 | { | |
149 | cat > "$tmpfile" <<EOF | |
150 | (use-modules (gnu)) | |
151 | (use-service-modules networking) | |
152 | ||
153 | (operating-system | |
154 | (host-name "antelope") | |
155 | (timezone "Europe/Paris") | |
156 | (locale "en_US.UTF-8") | |
157 | ||
158 | (bootloader (grub-configuration (device "/dev/sdX"))) | |
159 | (file-systems (cons (file-system | |
160 | (device "root") | |
161 | (title 'label) | |
162 | (mount-point "/") | |
163 | (type "ext4")) | |
164 | %base-file-systems)) | |
165 | (users (list (user-account | |
166 | (name "dave") | |
167 | (home-directory "/home/dave") | |
168 | (group "$1") | |
169 | (supplementary-groups '("$2")))))) | |
170 | EOF | |
171 | } | |
172 | ||
173 | make_user_config "users" "wheel" | |
174 | guix system build "$tmpfile" -n # succeeds | |
175 | ||
f3f427c2 LC |
176 | guix system build "$tmpfile" -d # succeeds |
177 | guix system build "$tmpfile" -d | grep '\.drv$' | |
178 | ||
179 | guix system vm "$tmpfile" -d # succeeds | |
180 | guix system vm "$tmpfile" -d | grep '\.drv$' | |
181 | ||
0c09a306 LC |
182 | make_user_config "group-that-does-not-exist" "users" |
183 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
184 | then false | |
185 | else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi | |
186 | ||
187 | make_user_config "users" "group-that-does-not-exist" | |
188 | if guix system build "$tmpfile" -n 2> "$errorfile" | |
189 | then false | |
190 | else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi | |
9d3994f7 LC |
191 | |
192 | # Try 'local-file' and relative file name resolution. | |
193 | ||
194 | cat > "$tmpdir/config.scm"<<EOF | |
195 | (use-modules (gnu)) | |
196 | (use-service-modules networking) | |
197 | ||
198 | (operating-system | |
199 | $OS_BASE | |
200 | (services (cons (tor-service (local-file "my-torrc")) | |
201 | %base-services))) | |
202 | EOF | |
203 | ||
204 | cat > "$tmpdir/my-torrc"<<EOF | |
205 | # This is an example file. | |
206 | EOF | |
207 | ||
208 | # In both cases 'my-torrc' should be properly resolved. | |
209 | guix system build "$tmpdir/config.scm" -n | |
210 | (cd "$tmpdir"; guix system build "config.scm" -n) |