projects/guix·blob master · refs

166 lines · 5.7 KiB

1# GNU Guix --- Functional package management for GNU
2# Copyright © 2021-2023 Ludovic Courtès <[email protected]>
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 the 'guix shell' alias.
21#
22
23guix shell --version
24
25configdir="t-guix-shell-config-$$"
26tmpdir="t-guix-shell-$$"
27trap 'rm -r "$tmpdir" "$configdir"' EXIT
28mkdir "$tmpdir" "$configdir" "$configdir/guix"
29
30XDG_CONFIG_HOME="$(realpath $configdir)"
31export XDG_CONFIG_HOME
32
33guix shell --bootstrap --pure guile-bootstrap -- guile --version
34
35# '--symlink' can only be used with --container.
36guix shell --bootstrap guile-bootstrap -S /dummy=bin/guile && false
37
38# '--cwd' can only be used with --container.
39guix shell --cwd=/tmp -n hello && false
40
41# '--ad-hoc' is a thing of the past.
42guix shell --ad-hoc guile-bootstrap && false
43
44# Rejecting unsupported packages.
45guix shell -s armhf-linux intelmetool -n && false
46
47# Test approximately that the child process does not inherit extra file
48# descriptors. Ideally we'd check there's nothing more than 0, 1, and 2, but
49# we cannot do that because (1) we might be inheriting additional FDs, for
50# example due to <https://issues.guix.gnu.org/57567>, and (2) Bash itself
51# opens a couple of extra FDs.
52initial_fd_list="$(echo /proc/$$/fd/*)"
53fd_list="$(guix shell --bootstrap guile-bootstrap -- \
54 bash -c 'echo /proc/$$/fd/*')"
55test "$(echo $fd_list | wc -w)" -le "$(echo $initial_fd_list | wc -w)"
56
57# Ignoring unauthorized files.
58cat > "$tmpdir/guix.scm" <<EOF
59This is a broken guix.scm file.
60EOF
61(cd "$tmpdir"; SHELL="$(type -P true)" guix shell --bootstrap 2> "stderr") && false
62grep "not authorized" "$tmpdir/stderr"
63rm "$tmpdir/stderr"
64
65# Authorize the directory.
66echo "$(realpath "$tmpdir")" > "$configdir/guix/shell-authorized-directories"
67
68# Ignoring 'manifest.scm' and 'guix.scm' in non-interactive use.
69(cd "$tmpdir"; guix shell --bootstrap -- true)
70mv "$tmpdir/guix.scm" "$tmpdir/manifest.scm"
71(cd "$tmpdir"; guix shell --bootstrap -- true)
72rm "$tmpdir/manifest.scm"
73
74# Honoring the local 'manifest.scm' file.
75cat > "$tmpdir/manifest.scm" <<EOF
76(specifications->manifest '("guile-bootstrap"))
77EOF
78cat > "$tmpdir/fake-shell.sh" <<EOF
79#!$SHELL
80# This fake shell allows us to test interactive use.
81exec echo "\$GUIX_ENVIRONMENT"
82EOF
83chmod +x "$tmpdir/fake-shell.sh"
84profile1="$(cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap)"
85profile2="$(guix shell --bootstrap guile-bootstrap -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT')"
86test -n "$profile1"
87test "$profile1" = "$profile2"
88rm "$tmpdir/manifest.scm"
89
90# Do not read manifest when passed '-q'.
91echo "Broken manifest." > "$tmpdir/manifest.scm"
92(cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap -q)
93rm "$tmpdir/manifest.scm"
94
95# Make sure '-D' affects only the immediately following '-f', and not packages
96# that appear later: <https://issues.guix.gnu.org/52093>.
97cat > "$tmpdir/empty-package.scm" <<EOF
98(use-modules (guix) (guix tests)
99 (guix build-system trivial))
100
101(dummy-package "empty-package"
102 (build-system trivial-build-system)) ;zero inputs
103EOF
104
105guix shell --bootstrap --pure -D -f "$tmpdir/empty-package.scm" \
106 guile-bootstrap -- guile --version
107rm "$tmpdir/empty-package.scm"
108
109# Make sure '--development' honors '--system'.
110this_system="$(guile -c '(use-modules (guix utils))
111 (display (%current-system))')"
112other_system="$(guile -c '(use-modules (guix utils))
113 (display (if (string=? "riscv64-linux" (%current-system))
114 "x86_64-linux"
115 "riscv64-linux"))')"
116cat > "$tmpdir/some-package.scm" <<EOF
117(use-modules (guix utils)
118 (guix packages)
119 (gnu packages base))
120
121(define unsupported-dependency
122 (package
123 (inherit grep)
124 (name "unsupported-dependency")
125 (supported-systems '())))
126
127(package
128 (inherit hello)
129 (name "phony-package")
130 (inputs
131 (if (string=? (%current-system) "$this_system")
132 (list unsupported-dependency)
133 '())))
134EOF
135
136guix shell -D -f "$tmpdir/some-package.scm" -n && false
137guix shell -D -f "$tmpdir/some-package.scm" -n -s "$other_system"
138
139
140if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
141then
142 # Compute the build environment for the initial GNU Make.
143 guix shell --bootstrap --no-substitutes --search-paths --pure \
144 -D -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
145
146 # Make sure bootstrap binaries are in the profile.
147 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
148
149 # Make sure the bootstrap binaries are all listed where they belong.
150 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
151 grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
152 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
153 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
154 do
155 guix gc --references "$profile" | grep "$dep"
156 done
157
158 # 'make-boot0' itself must not be listed.
159 guix gc --references "$profile" | grep make-boot0 && false
160
161 # Honoring the local 'guix.scm' file.
162 echo '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/guix.scm"
163 (cd "$tmpdir"; guix shell --bootstrap --search-paths --pure > "b")
164 cmp "$tmpdir/a" "$tmpdir/b"
165 rm "$tmpdir/guix.scm"
166fi