doc: Mention 'sync' after 'dd'.
[guix.git] / tests / guix-system.sh
blobde6db0928ca8f50dcc149a7d72509dbcfdbaeefb
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 # This file is part of GNU Guix.
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.
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.
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/>.
20 # Test 'guix system', mostly error reporting.
23 set -e
25 guix system --version
27 tmpfile="t-guix-system-$$"
28 errorfile="t-guix-system-error-$$"
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"
37 trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
39 # Reporting of syntax errors.
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
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"
56 # Reporting of unbound variables.
58 cat > "$tmpfile" <<EOF
59 (use-modules (gnu)) ; 1
60 (use-service-modules networking) ; 2
62 (operating-system ; 4
63 (host-name "antelope") ; 5
64 (timezone "Europe/Paris") ; 6
65 (locale "en_US.UTF-8") ; 7
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
76 if guix system build "$tmpfile" -n 2> "$errorfile"
77 then false
78 else
79 if test "`guile -c '(display (effective-version))'`" = 2.2
80 then
81 # FIXME: With Guile 2.2.0 the error is reported on line 4.
82 # See <http://bugs.gnu.org/26107>.
83 grep "$tmpfile:[49]:.*[Uu]nbound variable.*GRUB-config" "$errorfile"
84 else
85 grep "$tmpfile:9:.*[Uu]nbound variable.*GRUB-config" "$errorfile"
89 OS_BASE='
90 (host-name "antelope")
91 (timezone "Europe/Paris")
92 (locale "en_US.UTF-8")
94 (bootloader (grub-configuration (device "/dev/sdX")))
95 (file-systems (cons (file-system
96 (device "root")
97 (title (string->symbol "label"))
98 (mount-point "/")
99 (type "ext4"))
100 %base-file-systems))
103 # Reporting of duplicate service identifiers.
105 cat > "$tmpfile" <<EOF
106 (use-modules (gnu))
107 (use-service-modules networking)
109 (operating-system
110 $OS_BASE
111 (services (cons* (dhcp-client-service)
112 (dhcp-client-service) ;twice!
113 %base-services)))
116 if guix system vm "$tmpfile" 2> "$errorfile"
117 then
118 # This must not succeed.
119 exit 1
120 else
121 grep "service 'networking'.*more than once" "$errorfile"
124 # Reporting unmet shepherd requirements.
126 cat > "$tmpfile" <<EOF
127 (use-modules (gnu) (gnu services shepherd))
128 (use-service-modules networking)
130 (define buggy-service-type
131 (shepherd-service-type
132 'buggy
133 (lambda _
134 (shepherd-service
135 (provision '(buggy!))
136 (requirement '(does-not-exist))
137 (start #t)))))
139 (operating-system
140 $OS_BASE
141 (services (cons (service buggy-service-type #t)
142 %base-services)))
145 if guix system build "$tmpfile" 2> "$errorfile"
146 then
147 exit 1
148 else
149 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
152 # Reporting inconsistent user accounts.
154 make_user_config ()
156 cat > "$tmpfile" <<EOF
157 (use-modules (gnu))
158 (use-service-modules networking)
160 (operating-system
161 (host-name "antelope")
162 (timezone "Europe/Paris")
163 (locale "en_US.UTF-8")
165 (bootloader (grub-configuration (device "/dev/sdX")))
166 (file-systems (cons (file-system
167 (device "root")
168 (title 'label)
169 (mount-point "/")
170 (type "ext4"))
171 %base-file-systems))
172 (users (list (user-account
173 (name "dave")
174 (home-directory "/home/dave")
175 (group "$1")
176 (supplementary-groups '("$2"))))))
180 make_user_config "users" "wheel"
181 guix system build "$tmpfile" -n # succeeds
183 guix system build "$tmpfile" -d # succeeds
184 guix system build "$tmpfile" -d | grep '\.drv$'
186 guix system vm "$tmpfile" -d # succeeds
187 guix system vm "$tmpfile" -d | grep '\.drv$'
189 make_user_config "group-that-does-not-exist" "users"
190 if guix system build "$tmpfile" -n 2> "$errorfile"
191 then false
192 else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
194 make_user_config "users" "group-that-does-not-exist"
195 if guix system build "$tmpfile" -n 2> "$errorfile"
196 then false
197 else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
199 # Try 'local-file' and relative file name resolution.
201 cat > "$tmpdir/config.scm"<<EOF
202 (use-modules (gnu))
203 (use-service-modules networking)
205 (operating-system
206 $OS_BASE
207 (services (cons (tor-service (local-file "my-torrc"))
208 %base-services)))
211 cat > "$tmpdir/my-torrc"<<EOF
212 # This is an example file.
215 # In both cases 'my-torrc' should be properly resolved.
216 guix system build "$tmpdir/config.scm" -n
217 (cd "$tmpdir"; guix system build "config.scm" -n)