1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 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.
55 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
60 ;; This is line 1, and the next one is line 2.
62 ;; This is line 3, and there is no closing paren!
65 if guix system vm
"$tmpfile" 2> "$errorfile"
67 # This must not succeed.
72 # Guile 3.0.6 gets line/column numbers for 'read-error' wrong
73 # (zero-indexed): <https://bugs.gnu.org/48089>.
74 grep "$tmpfile:4:1: missing closing paren" "$errorfile" || \
75 grep "$tmpfile:3:0: missing closing paren" "$errorfile"
79 # Reporting of module not found errors.
81 cat > "$tmpfile" <<EOF
84 (use-service-modules openssh)
87 if guix system build
"$tmpfile" -n 2> "$errorfile"
90 grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
91 grep "Try.*use-service-modules ssh" "$errorfile"
94 cat > "$tmpfile" <<EOF
97 (use-package-modules qemu)
100 if guix system build
"$tmpfile" -n 2> "$errorfile"
103 grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
104 grep "Try.*use-package-modules virtualization" "$errorfile"
107 # Reporting of unbound variables.
109 cat > "$tmpfile" <<EOF
110 (use-modules (gnu)) ; 1
111 (use-service-modules networking) ; 2
113 (operating-system ; 4
114 (host-name "antelope") ; 5
115 (timezone "Europe/Paris") ; 6
116 (locale "en_US.UTF-8") ; 7
118 (bootloader (GRUB-config (targets (list "/dev/sdX")))) ; 9
119 (file-systems (cons (file-system
120 (device (file-system-label "root"))
123 %base-file-systems)))
126 if guix system build
"$tmpfile" -n 2> "$errorfile"
129 if test "`guile -c '(display (effective-version))'`" = 3.0
131 # FIXME: With Guile 3.3.0 the error is reported on line 11.
132 # See <https://bugs.gnu.org/38388>.
133 grep "$tmpfile:[0-9]\+:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
134 elif test "`guile -c '(display (effective-version))'`" = 2.2
136 # FIXME: With Guile 2.2.0 the error is reported on line 4.
137 # See <http://bugs.gnu.org/26107>.
138 grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
140 grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
144 cat > "$tmpfile" <<EOF
145 (use-modules (gnu)) ; 1
147 (operating-system ; 3
148 (file-systems (cons (file-system ; 4
149 (device (file-system-label "root"))
150 (mount-point "/") ; 6
151 (type "ext4")))) ; 7 (!!)
155 if guix system build
"$tmpfile" -n 2> "$errorfile"
158 # Here '%base-file-systems' appears as if it were a field specified of the
159 # enclosing 'operating-system' form due to parenthesis mismatch.
160 grep "$tmpfile:3:[0-9]\+:.*%base-file-system.*invalid field specifier" \
165 (host-name "antelope")
166 (timezone "Europe/Paris")
167 (locale "en_US.UTF-8")
169 (bootloader (bootloader-configuration
170 (bootloader grub-bootloader)
171 (targets (list "/dev/sdX"))))
172 (file-systems (cons (file-system
173 (device (file-system-label "root"))
179 # Reporting of duplicate service identifiers.
181 cat > "$tmpfile" <<EOF
183 (use-service-modules networking)
187 (services (cons* (service dhcp-client-service-type)
188 (service dhcp-client-service-type) ;twice!
192 if guix system vm
"$tmpfile" 2> "$errorfile"
194 # This must not succeed.
197 grep "service 'networking'.*more than once" "$errorfile"
200 # Reporting unmet shepherd requirements.
202 cat > "$tmpfile" <<EOF
203 (use-modules (gnu) (gnu services shepherd))
204 (use-service-modules networking)
206 (define buggy-service-type
207 (shepherd-service-type
211 (provision '(buggy!))
212 (requirement '(does-not-exist))
214 (description "Buggy.")))
218 (services (cons (service buggy-service-type #t)
222 if guix system build
"$tmpfile" 2> "$errorfile"
226 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
229 # Reporting inconsistent user accounts.
233 cat > "$tmpfile" <<EOF
235 (use-service-modules networking)
238 (host-name "antelope")
239 (timezone "Europe/Paris")
240 (locale "en_US.UTF-8")
242 (bootloader (bootloader-configuration
243 (bootloader grub-bootloader)
244 (targets (list "/dev/sdX"))))
245 (file-systems (cons (file-system
246 (device (file-system-label "root"))
250 (users (list (user-account
252 (home-directory "/home/dave")
254 (supplementary-groups '("$2"))))))
258 make_user_config
"users" "wheel"
259 guix system build
"$tmpfile" -n # succeeds
261 guix system build
"$tmpfile" -d # succeeds
262 guix system build
"$tmpfile" -d |
grep '\.drv$'
264 guix system vm
"$tmpfile" -d # succeeds
265 guix system vm
"$tmpfile" -d |
grep '\.drv$'
267 # Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
268 drv1
="`guix system vm "$tmpfile" -d`"
269 drv2
="`guix system vm "$tmpfile" -d`"
270 test "$drv1" = "$drv2"
271 drv1
="`guix system image -t iso9660 "$tmpfile" -d`"
272 drv2
="`guix system image -t iso9660 "$tmpfile" -d`"
273 test "$drv1" = "$drv2"
275 # Check whether the graph commands work as expected.
276 guix system extension-graph
"$tmpfile" |
grep 'label = "file-systems"'
277 guix system shepherd-graph
"$tmpfile" |
grep 'label = "guix-daemon"'
279 make_user_config
"group-that-does-not-exist" "users"
280 if guix system build
"$tmpfile" -n 2> "$errorfile"
282 else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
284 make_user_config
"users" "group-that-does-not-exist"
285 if guix system build
"$tmpfile" -n 2> "$errorfile"
287 else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
289 # Try 'local-file' and relative file name resolution.
291 cat > "$tmpdir/config.scm"<<EOF
293 (use-service-modules networking)
297 (services (cons (service tor-service-type
299 (config-file (local-file "my-torrc"))))
303 cat > "$tmpdir/my-torrc"<<EOF
304 # This is an example file.
307 # In both cases 'my-torrc' should be properly resolved.
308 guix system build
"$tmpdir/config.scm" -n
309 (cd "$tmpdir"; guix system build
"config.scm" -n)
311 # Check that we get a warning when passing 'local-file' a non-literal relative
313 cat > "$tmpdir/config.scm" <<EOF
316 (define (bad-local-file file)
319 (bad-local-file "whatever.scm")
321 ! guix system build
"$tmpdir/config.scm" -n
322 guix system build
"$tmpdir/config.scm" -n 2>&1 | \
323 grep "config\.scm:4:2: warning:.*whatever.*relative to current directory"
326 guix system search tor |
grep "^name: tor"
327 guix system search tor |
grep "^shepherdnames: tor"
328 guix system search anonym network |
grep "^name: tor"
329 guix system search .
> "$tmpdir/search"
330 test $
(wc -l < "$tmpdir/search") -gt 500
333 # Below, use -n (--dry-run) for the tests because if we actually tried to
334 # build these images, the commands would take hours to run in the worst case.
336 # Verify that the examples can be built.
337 for example
in gnu
/system
/examples
/*.tmpl
; do
338 if echo "$example" |
grep hurd
; then
339 target
="--target=i586-pc-gnu"
343 guix system
-n disk-image
$target "$example"
346 # Verify that the images can be built.
347 guix system
-n vm gnu
/system
/examples
/vm-image.tmpl
348 guix system
-n image gnu
/system
/images
/pinebook-pro.scm
349 guix system
-n image
-t qcow2 gnu
/system
/examples
/vm-image.tmpl
350 guix system
-n image
-t iso9660 gnu
/system
/examples
/bare-bones.tmpl
351 guix system
-n docker-image gnu
/system
/examples
/docker-image.tmpl
353 # Verify that at least the raw image type is available.
354 guix system
--list-image-types |
grep "raw"