1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2015, 2016, 2017, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
4 # This file is part of GNU Guix.
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.
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.
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/>.
20 # Test 'guix environment'.
25 guix environment
--version
27 tmpdir
="t-guix-environment-$$"
28 gcroot
="t-guix-environment-gc-root-$$"
29 trap 'rm -r "$tmpdir"; rm -f "$gcroot"' EXIT
33 # 'guix environment' launches /bin/sh if 'SHELL' is unset, so export 'SHELL'
34 # since we know it's valid (build environments lack /bin/sh.)
37 # Check the environment variables for the bootstrap Guile.
38 guix environment
--bootstrap --ad-hoc guile-bootstrap
--pure \
39 --search-paths > "$tmpdir/a"
40 guix environment
--bootstrap --ad-hoc guile-bootstrap
:out
--pure \
41 --search-paths > "$tmpdir/b"
43 # $PATH must appear in the search paths, and nothing else.
44 grep -E '^export PATH=.*profile/bin' "$tmpdir/a"
45 test "`wc -l < "$tmpdir/a
"`" = 1
47 # Guile must be on $PATH.
48 test -x `sed -r 's/^export PATH="(.*)"/\1/' "$tmpdir/a"`/guile
50 cmp "$tmpdir/a" "$tmpdir/b"
56 export GUIX_TEST_ABC GUIX_TEST_DEF GUIX_TEST_XYZ
57 guix environment
--bootstrap --ad-hoc guile-bootstrap
--pure \
58 --preserve='^GUIX_TEST_A' --preserve='^GUIX_TEST_D' \
59 -- "$SHELL" -c set > "$tmpdir/a"
60 grep '^PATH=' "$tmpdir/a"
61 grep '^GUIX_TEST_ABC=' "$tmpdir/a"
62 grep '^GUIX_TEST_DEF=' "$tmpdir/a"
63 ! grep '^GUIX_TEST_XYZ=' "$tmpdir/a"
65 # Make sure the exit value is preserved.
66 if guix environment
--bootstrap --ad-hoc guile-bootstrap
--pure \
67 -- guile
-c '(exit 42)'
74 # Make sure 'GUIX_ENVIRONMENT' points to the profile.
75 guix environment
--bootstrap --ad-hoc guile-bootstrap
--pure \
76 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
78 # Make sure 'GUIX_ENVIRONMENT' points to the profile when building from a
80 echo "(use-modules (guix profiles) (gnu packages bootstrap))
82 (packages->manifest (list %bootstrap-guile))
83 " > $tmpdir/manifest.scm
84 guix environment
--bootstrap --manifest=$tmpdir/manifest.scm
--pure \
85 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile"'
87 # Make sure '--manifest' can be specified multiple times.
88 cat > "$tmpdir/manifest2.scm" <<EOF
89 (use-modules (guix) (guix profiles)
90 (guix build-system trivial)
91 (gnu packages bootstrap))
95 (inherit %bootstrap-guile)
97 (build-system trivial-build-system)
100 (#:guile ,%bootstrap-guile
104 (mkdir (string-append %output "/eliug")))))))))
106 guix environment
--bootstrap -m "$tmpdir/manifest.scm" \
107 -m "$tmpdir/manifest2.scm" --pure \
108 -- "$SHELL" -c 'test -f "$GUIX_ENVIRONMENT/bin/guile" && test -d "$GUIX_ENVIRONMENT/eliug"'
110 # Make sure '-r' works as expected.
112 expected
="`guix environment --bootstrap --ad-hoc guile-bootstrap \
113 -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT'`"
114 guix environment
--bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
116 test `readlink "$gcroot"` = "$expected"
118 # Make sure '-r' is idempotent.
119 guix environment
--bootstrap -r "$gcroot" --ad-hoc guile-bootstrap \
121 test `readlink "$gcroot"` = "$expected"
123 # Make sure '-p' works as expected.
124 test $
(guix environment
-p "$gcroot" -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT') = "$expected"
125 paths1
="$(guix environment -p "$gcroot" --search-paths)"
126 paths2
="$(guix environment --bootstrap --ad-hoc guile-bootstrap --search-paths)"
127 test "$paths1" = "$paths2"
131 # Try '-r' with a relative file name.
132 (cd "$tmpdir"; mkdir
"gc-root";
133 guix environment
--bootstrap -r "gc-root/r" --ad-hoc guile-bootstrap \
135 rm "gc-root/r"; rmdir "gc-root")
137 # Same with an absolute file name.
138 guix environment
--bootstrap -r "$PWD/$gcroot" --ad-hoc guile-bootstrap \
140 test `readlink "$gcroot"` = "$expected"
144 # On x86_64, we should be able to create a 32-bit environment.
145 guix environment
--bootstrap --ad-hoc guile-bootstrap
--pure \
146 -- guile
-c '(exit (string-prefix? "x86_64" %host-type))'
147 guix environment
--bootstrap --ad-hoc guile-bootstrap
--pure \
149 -- guile
-c '(exit (string-prefix? "i686" %host-type))'
152 echo "nothing to do" >&2
156 # Make sure we can build the environment of 'guix'. There may be collisions
157 # in its profile (e.g., for 'gzip'), but we have to accept them.
158 guix environment guix
--bootstrap -n
160 # Try program transformation options.
161 mkdir
"$tmpdir/emacs-36.8"
162 drv
="`guix environment --ad-hoc emacs -n 2>&1 | grep 'emacs.*\.drv'`"
163 transformed_drv
="`guix environment --ad-hoc emacs --with-source="$tmpdir/emacs-36.8
" -n 2>&1 | grep 'emacs.*\.drv'`"
165 test "$drv" != "$transformed_drv"
166 case "$transformed_drv" in
167 *-emacs-36.8.drv
) true
;;
170 rmdir "$tmpdir/emacs-36.8"
172 # Transformation options without '--ad-hoc'.
173 drv
="`guix environment -n emacs-geiser 2>&1 | grep '\.drv$'`"
174 transformed_drv
="`guix environment -n emacs-geiser \
175 --with-input=emacs-minimal=vim 2>&1 | grep '\.drv$'`"
176 test "$drv" != "$transformed_drv"
178 *-emacs-minimal*.drv
*) true
;;
181 case "$transformed_drv" in
182 *-emacs-minimal*.drv
*) false
;;
185 case "$transformed_drv" in
191 if guile
-c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev
/null
193 # Compute the build environment for the initial GNU Make.
194 guix environment
--bootstrap --no-substitutes --search-paths --pure \
195 -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
197 # Make sure bootstrap binaries are in the profile.
198 profile
=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
200 # Make sure the bootstrap binaries are all listed where they belong.
201 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
202 grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
203 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
204 for dep
in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
206 guix gc
--references "$profile" |
grep "$dep"
209 # 'make-boot0' itself must not be listed.
210 ! guix gc
--references "$profile" |
grep make-boot0
212 # Make sure that the shell spawned with '--exec' sees the same environment
213 # as returned by '--search-paths'.
214 guix environment
--bootstrap --no-substitutes --pure \
215 -e '(@ (guix tests) gnu-make-for-tests)' \
216 -- /bin
/sh
-c 'echo $PATH $C_INCLUDE_PATH $LIBRARY_PATH' > "$tmpdir/b"
217 ( .
"$tmpdir/a" ; echo $PATH $C_INCLUDE_PATH $LIBRARY_PATH ) > "$tmpdir/c"
218 cmp "$tmpdir/b" "$tmpdir/c"
222 # The following test assumes 'make-boot0' has a "debug" output.
223 make_boot0_debug
="`guix build -e '(@ (guix tests) gnu-make-for-tests)' | grep -e -debug`"
224 test "x$make_boot0_debug" != "x"
226 # Make sure the "debug" output is not listed.
227 ! guix gc
--references "$profile" |
grep "$make_boot0_debug"
229 # Compute the build environment for the initial GNU Make, but add in the
230 # bootstrap Guile as an ad-hoc addition.
231 guix environment
--bootstrap --no-substitutes --search-paths --pure \
232 -e '(@ (guix tests) gnu-make-for-tests)' \
233 --ad-hoc guile-bootstrap
> "$tmpdir/a"
234 profile
=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
236 # Make sure the bootstrap binaries are all listed where they belong.
237 grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
238 grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
239 grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
240 for dep
in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0 \
243 guix gc
--references "$profile" |
grep "$dep"
246 # Make sure a package list with plain package objects and package+output
247 # tuples can be used with -e.
248 expr_list_test_code
="
249 (list (@ (guix tests) gnu-make-for-tests)
250 (list (@ (gnu packages bootstrap) %bootstrap-guile) \"out\"))"
252 guix environment
--bootstrap --ad-hoc --no-substitutes --search-paths \
253 --pure -e "$expr_list_test_code" > "$tmpdir/a"
254 profile
=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
256 for dep
in make-test-boot0 guile-bootstrap
258 guix gc
--references "$profile" |
grep "$dep"