gnu: Add emacs-exec-path-from-shell.
[jackhill/guix/guix.git] / tests / guix-system.sh
CommitLineData
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
24set -e
25
26guix system --version
27
28tmpfile="t-guix-system-$$"
29errorfile="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.)
35tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
36mkdir "$tmpdir"
37
38trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
c1202fb1 39
116244df
LC
40# Reporting of syntax errors.
41
c1202fb1
LC
42cat > "$tmpfile"<<EOF
43;; This is line 1, and the next one is line 2.
44 (operating-system)
45;; The 'T' is at column 3.
46EOF
47
48if guix system vm "$tmpfile" 2> "$errorfile"
49then
50 # This must not succeed.
51 exit 1
52else
53 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
54fi
116244df
LC
55
56
a6e22d84
LC
57cat > "$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!
61EOF
62
63if guix system vm "$tmpfile" 2> "$errorfile"
64then
65 # This must not succeed.
66 exit 1
67else
68 grep "$tmpfile:4:1: missing closing paren" "$errorfile"
69fi
70
71
c5a4a92f
LC
72# Reporting of module not found errors.
73
74cat > "$tmpfile" <<EOF
75;; Line 1.
76(use-modules (gnu))
77 (use-service-modules openssh)
78EOF
79
80if guix system build "$tmpfile" -n 2> "$errorfile"
81then false
82else
83 grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
84 grep "Try.*use-service-modules ssh" "$errorfile"
85fi
86
87cat > "$tmpfile" <<EOF
88;; Line 1.
89(use-modules (gnu))
90 (use-package-modules qemu)
91EOF
92
93if guix system build "$tmpfile" -n 2> "$errorfile"
94then false
95else
96 grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
97 grep "Try.*use-package-modules virtualization" "$errorfile"
98fi
99
2abcc97f
LC
100# Reporting of unbound variables.
101
102cat > "$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)))
118EOF
119
120if guix system build "$tmpfile" -n 2> "$errorfile"
121then false
122else
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
131fi
132
2d2651e7 133OS_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
151cat > "$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)))
160EOF
161
162if guix system vm "$tmpfile" 2> "$errorfile"
163then
164 # This must not succeed.
165 exit 1
166else
167 grep "service 'networking'.*more than once" "$errorfile"
168fi
0c09a306 169
0190c1c0 170# Reporting unmet shepherd requirements.
2d2651e7
LC
171
172cat > "$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)))
189EOF
190
191if guix system build "$tmpfile" 2> "$errorfile"
192then
193 exit 1
194else
a8492735 195 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
2d2651e7
LC
196fi
197
198# Reporting inconsistent user accounts.
199
0c09a306
LC
200make_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"))))))
225EOF
226}
227
228make_user_config "users" "wheel"
229guix system build "$tmpfile" -n # succeeds
230
f3f427c2
LC
231guix system build "$tmpfile" -d # succeeds
232guix system build "$tmpfile" -d | grep '\.drv$'
233
234guix system vm "$tmpfile" -d # succeeds
235guix system vm "$tmpfile" -d | grep '\.drv$'
236
0c09a306
LC
237make_user_config "group-that-does-not-exist" "users"
238if guix system build "$tmpfile" -n 2> "$errorfile"
239then false
240else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
241
242make_user_config "users" "group-that-does-not-exist"
243if guix system build "$tmpfile" -n 2> "$errorfile"
244then false
245else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
9d3994f7
LC
246
247# Try 'local-file' and relative file name resolution.
248
249cat > "$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)))
257EOF
258
259cat > "$tmpdir/my-torrc"<<EOF
260# This is an example file.
261EOF
262
263# In both cases 'my-torrc' should be properly resolved.
264guix system build "$tmpdir/config.scm" -n
265(cd "$tmpdir"; guix system build "config.scm" -n)
0649321d
LC
266
267# Searching.
268guix system search tor | grep "^name: tor"
269guix system search anonym network | grep "^name: tor"