epiphany w/ gtk4 and webkitgtk 2.38
[jackhill/guix/guix.git] / tests / guix-environment-container.sh
CommitLineData
f535dcbe
DT
1# GNU Guix --- Functional package management for GNU
2# Copyright © 2015 David Thompson <davet@gnu.org>
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#
20# Test 'guix environment'.
21#
22
23set -e
24
25guix environment --version
26
90f496be 27if ! guile -c '((@ (guix scripts environment) assert-container-features))'
6493fd04
LC
28then
29 # User containers are not supported; skip this test.
30 exit 77
31fi
32
f535dcbe
DT
33tmpdir="t-guix-environment-$$"
34trap 'rm -r "$tmpdir"' EXIT
35
36mkdir "$tmpdir"
37
38# Make sure the exit value is preserved.
39if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
40 -- guile -c '(exit 42)'
41then
42 false
43else
44 test $? = 42
45fi
46
10208952
LC
47# Try '--root' and '--profile'.
48root="$tmpdir/root"
49guix environment -C --ad-hoc --bootstrap guile-bootstrap -r "$root" -- guile --version
50guix environment -C -p "$root" --bootstrap -- guile --version
51path1=$(guix environment -C -p "$root" --bootstrap -- guile -c '(display (getenv "PATH"))')
52path2=$(guix environment -C --ad-hoc --bootstrap guile-bootstrap -- guile -c '(display (getenv "PATH"))')
53test "$path1" = "$path2"
54
0f53c801
LC
55# Make sure "localhost" resolves.
56guix environment --container --ad-hoc --bootstrap guile-bootstrap \
57 -- guile -c '(exit (pair? (getaddrinfo "localhost" "80")))'
58
b68d4106
LC
59# We should get ECONNREFUSED, not ENETUNREACH, which would indicate that "lo"
60# is down.
61guix environment --container --ad-hoc --bootstrap guile-bootstrap \
62 -- guile -c "(exit (= ECONNREFUSED
63 (catch 'system-error
64 (lambda ()
65 (let ((sock (socket AF_INET SOCK_STREAM 0)))
66 (connect sock AF_INET INADDR_LOOPBACK 12345)))
67 (lambda args
68 (pk 'errno (system-error-errno args))))))"
69
5a02f8e3
LC
70# Make sure '--preserve' is honored.
71result="`FOOBAR=42; export FOOBAR; guix environment -C --ad-hoc --bootstrap \
72 guile-bootstrap -E ^FOO -- guile -c '(display (getenv \"FOOBAR\"))'`"
73test "$result" = "42"
74
1ccc0f80
LC
75# By default, the UID inside the container should be the same as outside.
76uid="`id -u`"
77inner_uid="`guix environment -C --ad-hoc --bootstrap guile-bootstrap \
78 -- guile -c '(display (getuid))'`"
79test $inner_uid = $uid
80
81# When '--user' is passed, the UID should be 1000. (Note: Use a separate HOME
82# so that we don't run into problems when the test directory is under /home.)
83export tmpdir
84inner_uid="`HOME=$tmpdir guix environment -C --ad-hoc --bootstrap guile-bootstrap \
85 --user=gnu-guix -- guile -c '(display (getuid))'`"
86test $inner_uid = 1000
87
8a9922bd
LC
88if test "x$USER" = "x"; then USER="`id -un`"; fi
89
952afb6f 90# Check whether /etc/passwd and /etc/group are valid.
8a9922bd
LC
91guix environment -C --ad-hoc --bootstrap guile-bootstrap \
92 -- guile -c "(exit (string=? \"$USER\" (passwd:name (getpwuid (getuid)))))"
952afb6f
LC
93guix environment -C --ad-hoc --bootstrap guile-bootstrap \
94 -- guile -c '(exit (string? (group:name (getgrgid (getgid)))))'
95guix environment -C --ad-hoc --bootstrap guile-bootstrap \
96 -- guile -c '(use-modules (srfi srfi-1))
97 (exit (every group:name
98 (map getgrgid (vector->list (getgroups)))))'
8a9922bd 99
c06f6db7
LC
100# Make sure file-not-found errors in mounts are reported.
101if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
102 --expose=/does-not-exist -- guile -c 1 2> "$tmpdir/error"
103then
104 false
105else
106 grep "/does-not-exist" "$tmpdir/error"
107 grep "[Nn]o such file" "$tmpdir/error"
108fi
109
f535dcbe
DT
110# Make sure that the right directories are mapped.
111mount_test_code="
112(use-modules (ice-9 rdelim)
113 (ice-9 match)
114 (srfi srfi-1))
115
116(define mappings
117 (filter-map (lambda (line)
118 (match (string-split line #\space)
119 ;; Empty line.
120 ((\"\") #f)
1250034d
LC
121 ;; Ignore the root file system.
122 ((_ \"/\" _ _ _ _)
f535dcbe 123 #f)
1250034d
LC
124 ;; Ignore these types of file systems, except if they
125 ;; correspond to a parent file system.
126 ((_ mount (or \"tmpfs\" \"proc\" \"sysfs\" \"devtmpfs\"
127 \"devpts\" \"cgroup\" \"mqueue\") _ _ _)
7cdec6a9 128 (and (string-prefix? (getcwd) mount)
1250034d 129 mount))
f535dcbe
DT
130 ((_ mount _ _ _ _)
131 mount)))
132 (string-split (call-with-input-file \"/proc/mounts\" read-string)
133 #\newline)))
134
135(for-each (lambda (mount)
136 (display mount)
137 (newline))
138 mappings)"
139
140guix environment --container --ad-hoc --bootstrap guile-bootstrap \
141 -- guile -c "$mount_test_code" > $tmpdir/mounts
142
855038b2 143cat "$tmpdir/mounts"
779aa003 144test `wc -l < $tmpdir/mounts` -eq 4
f535dcbe 145
c8855b99
LC
146current_dir="`cd $PWD; pwd -P`"
147grep -e "$current_dir$" $tmpdir/mounts # current directory
f535dcbe
DT
148grep $(guix build guile-bootstrap) $tmpdir/mounts
149grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
150
151rm $tmpdir/mounts
82e64fc1 152
9b65281d 153# Make sure 'GUIX_ENVIRONMENT' is set to '~/.guix-profile' when requested
07ec3492
MG
154# within a container.
155(
9b65281d
LC
156 linktest='
157(exit (and (string=? (getenv "GUIX_ENVIRONMENT")
158 (string-append (getenv "HOME") "/.guix-profile"))
159 (string-prefix? "'"$NIX_STORE_DIR"'"
160 (readlink (string-append (getenv "HOME")
161 "/.guix-profile")))))'
07ec3492
MG
162
163 cd "$tmpdir" \
164 && guix environment --bootstrap --container --link-profile \
165 --ad-hoc guile-bootstrap --pure \
166 -- guile -c "$linktest"
167)
168
e37944d8
MG
169# Test that user can be mocked.
170usertest='(exit (and (string=? (getenv "HOME") "/home/foognu")
1ccc0f80 171 (string=? (passwd:name (getpwuid 1000)) "foognu")
e37944d8
MG
172 (file-exists? "/home/foognu/umock")))'
173touch "$tmpdir/umock"
174HOME="$tmpdir" guix environment --bootstrap --container --user=foognu \
175 --ad-hoc guile-bootstrap --pure \
176 --share="$tmpdir/umock" \
177 -- guile -c "$usertest"
178
75a6f668
LC
179# if not sharing CWD, chdir home
180(
181 cd "$tmpdir" \
182 && guix environment --bootstrap --container --no-cwd --user=foo \
183 --ad-hoc guile-bootstrap --pure \
184 -- /bin/sh -c 'test $(pwd) == "/home/foo" -a ! -d '"$tmpdir"
185)
e37944d8 186
07ec3492
MG
187# Check the exit code.
188
13bc8d5e
DT
189abnormal_exit_code="
190(use-modules (system foreign))
191;; Purposely make Guile crash with a segfault. :)
192(pointer->string (make-pointer 123) 123)"
193
82e64fc1 194if guix environment --bootstrap --container \
13bc8d5e 195 --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code"
82e64fc1
LC
196then false;
197else
198 test $? -gt 127
199fi
c7ba5f38
JK
200
201# Test the Filesystem Hierarchy Standard (FHS) container option, --emulate-fhs (-F)
202
203# As this option requires a glibc package (glibc-for-fhs), try to run these
204# tests with the user's global store to make it easier to build or download a
205# substitute.
206storedir="`guile -c '(use-modules (guix config))(display %storedir)'`"
207localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
208NIX_STORE_DIR="$storedir"
209GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
210export NIX_STORE_DIR GUIX_DAEMON_SOCKET
211
212if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
213then
214 exit 77
215fi
216
217# Test that the container has FHS specific files/directories. Note that /bin
218# exists in a non-FHS container as it will contain sh, a symlink to the bash
219# package, so we don't test for it.
8b192c55 220guix shell -C --emulate-fhs --bootstrap guile-bootstrap \
c7ba5f38
JK
221 -- guile -c '(exit (and (file-exists? "/etc/ld.so.cache")
222 (file-exists? "/lib")
223 (file-exists? "/sbin")
224 (file-exists? "/usr/bin")
225 (file-exists? "/usr/include")
226 (file-exists? "/usr/lib")
227 (file-exists? "/usr/libexec")
228 (file-exists? "/usr/sbin")
229 (file-exists? "/usr/share")))'
230
231# Test that the ld cache was generated and can be successfully read.
8b192c55 232guix shell -CF --bootstrap guile-bootstrap \
c7ba5f38 233 -- guile -c '(execlp "ldconfig" "ldconfig" "-p")'