1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
4 # Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
6 # This file is part of GNU Guix.
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.
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.
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/>.
22 # Test 'guix system', mostly error reporting.
29 tmpfile
="t-guix-system-$$"
30 errorfile
="t-guix-system-error-$$"
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-$$"
39 trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
41 # Reporting of syntax errors.
44 ;; This is line 1, and the next one is line 2.
46 ;; The 'T' is at column 3.
49 if guix system vm
"$tmpfile" 2> "$errorfile"
51 # This must not succeed.
54 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
59 ;; This is line 1, and the next one is line 2.
61 ;; This is line 3, and there is no closing paren!
64 if guix system vm
"$tmpfile" 2> "$errorfile"
66 # This must not succeed.
69 grep "$tmpfile:4:1: missing closing paren" "$errorfile"
73 # Reporting of module not found errors.
75 cat > "$tmpfile" <<EOF
78 (use-service-modules openssh)
81 if guix system build
"$tmpfile" -n 2> "$errorfile"
84 grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
85 grep "Try.*use-service-modules ssh" "$errorfile"
88 cat > "$tmpfile" <<EOF
91 (use-package-modules qemu)
94 if guix system build
"$tmpfile" -n 2> "$errorfile"
97 grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
98 grep "Try.*use-package-modules virtualization" "$errorfile"
101 # Reporting of unbound variables.
103 cat > "$tmpfile" <<EOF
104 (use-modules (gnu)) ; 1
105 (use-service-modules networking) ; 2
107 (operating-system ; 4
108 (host-name "antelope") ; 5
109 (timezone "Europe/Paris") ; 6
110 (locale "en_US.UTF-8") ; 7
112 (bootloader (GRUB-config (target "/dev/sdX"))) ; 9
113 (file-systems (cons (file-system
114 (device (file-system-label "root"))
117 %base-file-systems)))
120 if guix system build
"$tmpfile" -n 2> "$errorfile"
123 if test "`guile -c '(display (effective-version))'`" = 2.2
125 # FIXME: With Guile 2.2.0 the error is reported on line 4.
126 # See <http://bugs.gnu.org/26107>.
127 grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
129 grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
134 (host-name "antelope")
135 (timezone "Europe/Paris")
136 (locale "en_US.UTF-8")
138 (bootloader (bootloader-configuration
139 (bootloader grub-bootloader)
140 (target "/dev/sdX")))
141 (file-systems (cons (file-system
142 (device (file-system-label "root"))
148 # Reporting of duplicate service identifiers.
150 cat > "$tmpfile" <<EOF
152 (use-service-modules networking)
156 (services (cons* (service dhcp-client-service-type)
157 (service dhcp-client-service-type) ;twice!
161 if guix system vm
"$tmpfile" 2> "$errorfile"
163 # This must not succeed.
166 grep "service 'networking'.*more than once" "$errorfile"
169 # Reporting unmet shepherd requirements.
171 cat > "$tmpfile" <<EOF
172 (use-modules (gnu) (gnu services shepherd))
173 (use-service-modules networking)
175 (define buggy-service-type
176 (shepherd-service-type
180 (provision '(buggy!))
181 (requirement '(does-not-exist))
186 (services (cons (service buggy-service-type #t)
190 if guix system build
"$tmpfile" 2> "$errorfile"
194 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
197 # Reporting inconsistent user accounts.
201 cat > "$tmpfile" <<EOF
203 (use-service-modules networking)
206 (host-name "antelope")
207 (timezone "Europe/Paris")
208 (locale "en_US.UTF-8")
210 (bootloader (bootloader-configuration
211 (bootloader grub-bootloader)
212 (target "/dev/sdX")))
213 (file-systems (cons (file-system
214 (device (file-system-label "root"))
218 (users (list (user-account
220 (home-directory "/home/dave")
222 (supplementary-groups '("$2"))))))
226 make_user_config
"users" "wheel"
227 guix system build
"$tmpfile" -n # succeeds
229 guix system build
"$tmpfile" -d # succeeds
230 guix system build
"$tmpfile" -d |
grep '\.drv$'
232 guix system vm
"$tmpfile" -d # succeeds
233 guix system vm
"$tmpfile" -d |
grep '\.drv$'
235 # Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
236 drv1
="`guix system vm "$tmpfile" -d`"
237 drv2
="`guix system vm "$tmpfile" -d`"
238 test "$drv1" = "$drv2"
239 drv1
="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
240 drv2
="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
241 test "$drv1" = "$drv2"
243 make_user_config
"group-that-does-not-exist" "users"
244 if guix system build
"$tmpfile" -n 2> "$errorfile"
246 else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
248 make_user_config
"users" "group-that-does-not-exist"
249 if guix system build
"$tmpfile" -n 2> "$errorfile"
251 else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
253 # Try 'local-file' and relative file name resolution.
255 cat > "$tmpdir/config.scm"<<EOF
257 (use-service-modules networking)
261 (services (cons (service tor-service-type
263 (config-file (local-file "my-torrc"))))
267 cat > "$tmpdir/my-torrc"<<EOF
268 # This is an example file.
271 # In both cases 'my-torrc' should be properly resolved.
272 guix system build
"$tmpdir/config.scm" -n
273 (cd "$tmpdir"; guix system build
"config.scm" -n)
276 guix system search tor |
grep "^name: tor"
277 guix system search tor |
grep "^shepherdnames: tor"
278 guix system search anonym network |
grep "^name: tor"
280 # Below, use -n (--dry-run) for the tests because if we actually tried to
281 # build these images, the commands would take hours to run in the worst case.
283 # Verify that the examples can be built.
284 for example
in gnu
/system
/examples
/*; do
285 guix system
-n disk-image
$example
288 # Verify that the disk image types can be built.
289 guix system
-n vm gnu
/system
/examples
/vm-image.tmpl
290 guix system
-n vm-image gnu
/system
/examples
/vm-image.tmpl
291 # This invocation was taken care of in the loop above:
292 # guix system -n disk-image gnu/system/examples/bare-bones.tmpl
293 guix system
-n disk-image
--file-system-type=iso9660 gnu
/system
/examples
/bare-bones.tmpl
294 guix system
-n docker-image gnu
/system
/examples
/docker-image.tmpl