guix home: Add 'container' command.
[jackhill/guix/guix.git] / tests / guix-shell.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2021-2022 Ludovic Courtès <ludo@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 the 'guix shell' alias.
21 #
22
23 guix shell --version
24
25 configdir="t-guix-shell-config-$$"
26 tmpdir="t-guix-shell-$$"
27 trap 'rm -r "$tmpdir" "$configdir"' EXIT
28 mkdir "$tmpdir" "$configdir" "$configdir/guix"
29
30 XDG_CONFIG_HOME="$(realpath $configdir)"
31 export XDG_CONFIG_HOME
32
33 guix shell --bootstrap --pure guile-bootstrap -- guile --version
34
35 # '--ad-hoc' is a thing of the past.
36 ! guix shell --ad-hoc guile-bootstrap
37
38 # Rejecting unsupported packages.
39 ! guix shell -s armhf-linux intelmetool -n
40
41 # Ignoring unauthorized files.
42 cat > "$tmpdir/guix.scm" <<EOF
43 This is a broken guix.scm file.
44 EOF
45 ! (cd "$tmpdir"; SHELL="$(type -P true)" guix shell --bootstrap 2> "stderr")
46 grep "not authorized" "$tmpdir/stderr"
47 rm "$tmpdir/stderr"
48
49 # Authorize the directory.
50 echo "$(realpath "$tmpdir")" > "$configdir/guix/shell-authorized-directories"
51
52 # Ignoring 'manifest.scm' and 'guix.scm' in non-interactive use.
53 (cd "$tmpdir"; guix shell --bootstrap -- true)
54 mv "$tmpdir/guix.scm" "$tmpdir/manifest.scm"
55 (cd "$tmpdir"; guix shell --bootstrap -- true)
56 rm "$tmpdir/manifest.scm"
57
58 # Honoring the local 'manifest.scm' file.
59 cat > "$tmpdir/manifest.scm" <<EOF
60 (specifications->manifest '("guile-bootstrap"))
61 EOF
62 cat > "$tmpdir/fake-shell.sh" <<EOF
63 #!$SHELL
64 # This fake shell allows us to test interactive use.
65 exec echo "\$GUIX_ENVIRONMENT"
66 EOF
67 chmod +x "$tmpdir/fake-shell.sh"
68 profile1="$(cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap)"
69 profile2="$(guix shell --bootstrap guile-bootstrap -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT')"
70 test -n "$profile1"
71 test "$profile1" = "$profile2"
72 rm "$tmpdir/manifest.scm"
73
74 # Do not read manifest when passed '-q'.
75 echo "Broken manifest." > "$tmpdir/manifest.scm"
76 (cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap -q)
77 rm "$tmpdir/manifest.scm"
78
79 # Make sure '-D' affects only the immediately following '-f', and not packages
80 # that appear later: <https://issues.guix.gnu.org/52093>.
81 cat > "$tmpdir/empty-package.scm" <<EOF
82 (use-modules (guix) (guix tests)
83 (guix build-system trivial))
84
85 (dummy-package "empty-package"
86 (build-system trivial-build-system)) ;zero inputs
87 EOF
88
89 guix shell --bootstrap --pure -D -f "$tmpdir/empty-package.scm" \
90 guile-bootstrap -- guile --version
91 rm "$tmpdir/empty-package.scm"
92
93 if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
94 then
95 # Compute the build environment for the initial GNU Make.
96 guix shell --bootstrap --no-substitutes --search-paths --pure \
97 -D -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
98
99 # Make sure bootstrap binaries are in the profile.
100 profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
101
102 # Make sure the bootstrap binaries are all listed where they belong.
103 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
104 grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
105 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
106 for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
107 do
108 guix gc --references "$profile" | grep "$dep"
109 done
110
111 # 'make-boot0' itself must not be listed.
112 ! guix gc --references "$profile" | grep make-boot0
113
114 # Honoring the local 'guix.scm' file.
115 echo '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/guix.scm"
116 (cd "$tmpdir"; guix shell --bootstrap --search-paths --pure > "b")
117 cmp "$tmpdir/a" "$tmpdir/b"
118 rm "$tmpdir/guix.scm"
119 fi