profiles: Add #:system argument to profile-derivation.
[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
6493fd04
LC
27if ! guile -c '((@@ (guix scripts environment) assert-container-features))'
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
47# Make sure that the right directories are mapped.
48mount_test_code="
49(use-modules (ice-9 rdelim)
50 (ice-9 match)
51 (srfi srfi-1))
52
53(define mappings
54 (filter-map (lambda (line)
55 (match (string-split line #\space)
56 ;; Empty line.
57 ((\"\") #f)
58 ;; Ignore these types of file systems.
59 ((_ _ (or \"tmpfs\" \"proc\" \"sysfs\" \"devtmpfs\"
60 \"devpts\" \"cgroup\" \"mqueue\") _ _ _)
61 #f)
62 ((_ mount _ _ _ _)
63 mount)))
64 (string-split (call-with-input-file \"/proc/mounts\" read-string)
65 #\newline)))
66
67(for-each (lambda (mount)
68 (display mount)
69 (newline))
70 mappings)"
71
72guix environment --container --ad-hoc --bootstrap guile-bootstrap \
73 -- guile -c "$mount_test_code" > $tmpdir/mounts
74
855038b2 75cat "$tmpdir/mounts"
f535dcbe
DT
76test `wc -l < $tmpdir/mounts` -eq 3
77
c8855b99
LC
78current_dir="`cd $PWD; pwd -P`"
79grep -e "$current_dir$" $tmpdir/mounts # current directory
f535dcbe
DT
80grep $(guix build guile-bootstrap) $tmpdir/mounts
81grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
82
83rm $tmpdir/mounts
82e64fc1
LC
84
85if guix environment --bootstrap --container \
86 --ad-hoc bootstrap-binaries -- kill -SEGV 2
87then false;
88else
89 test $? -gt 127
90fi