pull: Always install the ~/.config/guix/latest symlink.
[jackhill/guix/guix.git] / tests / guix-package.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
ee06af5b 2# Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
acc08466 3# Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
0afdc485 4#
233e7676 5# This file is part of GNU Guix.
0afdc485 6#
233e7676 7# GNU Guix is free software; you can redistribute it and/or modify it
0afdc485
LC
8# under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or (at
10# your option) any later version.
11#
233e7676 12# GNU Guix is distributed in the hope that it will be useful, but
0afdc485
LC
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
233e7676 18# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
0afdc485
LC
19
20#
e49951eb 21# Test the `guix package' command-line utility.
0afdc485
LC
22#
23
e49951eb 24guix package --version
0afdc485 25
24e262f0
LC
26readlink_base ()
27{
28 basename `readlink "$1"`
29}
30
e25234e3 31module_dir="t-guix-package-$$"
0afdc485
LC
32profile="t-profile-$$"
33rm -f "$profile"
34
e25234e3 35trap 'rm "$profile" "$profile-"[0-9]* ; rm -rf "$module_dir" t-home-'"$$" EXIT
7a6548cb 36
5d4b411f
LC
37# Use `-e' with a non-package expression.
38if guix package --bootstrap -e +;
39then false; else true; fi
40
e49951eb 41guix package --bootstrap -p "$profile" -i guile-bootstrap
0afdc485
LC
42test -L "$profile" && test -L "$profile-1-link"
43test -f "$profile/bin/guile"
44
d2952326
LC
45# Make sure the profile is a GC root.
46guix gc --list-live | grep "`readlink "$profile-1-link"`"
47
1c67d639 48# Installing the same package a second time does nothing.
e49951eb 49guix package --bootstrap -p "$profile" -i guile-bootstrap
1c67d639
LC
50test -L "$profile" && test -L "$profile-1-link"
51! test -f "$profile-2-link"
52test -f "$profile/bin/guile"
0afdc485 53
5924080d
LC
54# No search path env. var. here.
55guix package --search-paths -p "$profile"
56test "`guix package --search-paths -p "$profile" | wc -l`" = 0
57
ad1ebab3
LC
58# Check whether we have network access.
59if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
60then
bdb36958 61 boot_make="(@@ (gnu packages commencement) gnu-make-boot0)"
81b66f85 62 boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
5d4b411f 63 guix package --bootstrap -p "$profile" -i "$boot_make_drv"
ad1ebab3
LC
64 test -L "$profile-2-link"
65 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
0afdc485 66
733b4130 67
ad1ebab3
LC
68 # Check whether `--list-installed' works.
69 # XXX: Change the tests when `--install' properly extracts the package
70 # name and version string.
e49951eb 71 installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
ad1ebab3 72 case "x$installed" in
6c1cd80d
NK
73 "guile-bootstrap make-boot0")
74 true;;
75 "make-boot0 guile-bootstrap")
76 true;;
77 "*")
ad1ebab3
LC
78 false;;
79 esac
733b4130 80
e49951eb 81 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
733b4130 82
2cd09108
NK
83 # List generations.
84 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
85 = " guile-bootstrap"
86
0ab212b9
NK
87 # Exit with 1 when a generation does not exist.
88 if guix package -p "$profile" --list-generations=42;
89 then false; else true; fi
b3bb82f1
AK
90 if guix package -p "$profile" --switch-generation=99;
91 then false; else true; fi
0ab212b9 92
ad1ebab3 93 # Remove a package.
e49951eb 94 guix package --bootstrap -p "$profile" -r "guile-bootstrap"
ad1ebab3
LC
95 test -L "$profile-3-link"
96 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
24e262f0
LC
97
98 # Roll back.
e49951eb 99 guix package --roll-back -p "$profile"
24e262f0
LC
100 test "`readlink_base "$profile"`" = "$profile-2-link"
101 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
e49951eb 102 guix package --roll-back -p "$profile"
24e262f0
LC
103 test "`readlink_base "$profile"`" = "$profile-1-link"
104 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
105
b3bb82f1
AK
106 # Switch to the rolled generation and switch back.
107 guix package -p "$profile" --switch-generation=2
108 test "`readlink_base "$profile"`" = "$profile-2-link"
109 guix package -p "$profile" --switch-generation=-1
110 test "`readlink_base "$profile"`" = "$profile-1-link"
111
d9307267
LC
112 # Move to the empty profile.
113 for i in `seq 1 3`
114 do
6c1cd80d
NK
115 guix package --bootstrap --roll-back -p "$profile"
116 ! test -f "$profile/bin"
117 ! test -f "$profile/lib"
118 test "`readlink_base "$profile"`" = "$profile-0-link"
d9307267 119 done
24e262f0 120
4b2bc804
NK
121 # Test that '--list-generations' does not output the zeroth generation.
122 test -z "`guix package -p "$profile" -l 0`"
123
82fe08ed 124 # Reinstall after roll-back to the empty profile.
5d4b411f 125 guix package --bootstrap -p "$profile" -e "$boot_make"
82fe08ed
LC
126 test "`readlink_base "$profile"`" = "$profile-1-link"
127 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
24e262f0 128
9ac9360d
NK
129 # Check that the first generation is the current one.
130 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
131
82fe08ed 132 # Roll-back to generation 0, and install---all at once.
e49951eb 133 guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
82fe08ed
LC
134 test "`readlink_base "$profile"`" = "$profile-1-link"
135 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
136
137 # Install Make.
5d4b411f 138 guix package --bootstrap -p "$profile" -e "$boot_make"
82fe08ed 139 test "`readlink_base "$profile"`" = "$profile-2-link"
24e262f0 140 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
741c70c6 141 grep "`guix build -e "$boot_make"`" "$profile/manifest"
9241172c
LC
142
143 # Make a "hole" in the list of generations, and make sure we can
b3bb82f1 144 # roll back and switch "over" it.
82fe08ed 145 rm "$profile-1-link"
e49951eb 146 guix package --bootstrap -p "$profile" --roll-back
82fe08ed 147 test "`readlink_base "$profile"`" = "$profile-0-link"
b3bb82f1
AK
148 guix package -p "$profile" --switch-generation=+1
149 test "`readlink_base "$profile"`" = "$profile-2-link"
5924080d
LC
150
151 # Make sure LIBRARY_PATH gets listed by `--search-paths'.
152 guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
153 guix package --search-paths -p "$profile" | grep LIBRARY_PATH
b7884ca3
NK
154
155 # Delete the third generation and check that it was actually deleted.
156 guix package -p "$profile" --delete-generations=3
157 test -z "`guix package -p "$profile" -l 3`"
158
159 # Exit with 1 when a generation does not exist.
160 if guix package -p "$profile" --delete-generations=42;
161 then false; else true; fi
162
163 # Exit with 0 when trying to delete the zeroth generation.
164 guix package -p "$profile" --delete-generations=0
ad1ebab3 165fi
0afdc485 166
6447738c
MW
167# Make sure multiple arguments to -i works.
168guix package --bootstrap -i guile gcc -p "$profile" -n
169
9518856b 170# Make sure the `:' syntax works.
ecb1b610 171guix package --bootstrap -i "glibc:debug" -p "$profile" -n
9518856b 172
aa92cf98 173# Make sure nonexistent outputs are reported.
e49951eb
MW
174guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
175if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
aa92cf98 176then false; else true; fi
e49951eb 177if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
aa92cf98
LC
178then false; else true; fi
179
64fc89b6 180# Check whether `--list-available' returns something sensible.
03f4ef28 181guix package -p "$profile" -A 'gui.*e' | grep guile
64fc89b6 182
2aa6efb0 183# Check whether `--show' returns something sensible.
3ce9aa44 184guix package --show=guile | grep "^name: guile"
2aa6efb0 185
1b0a86dd 186# Ensure `--show' doesn't fail for packages with non-package inputs.
5e6feee6
EB
187guix package --show=texlive
188
1b0a86dd
LC
189# Search.
190LC_MESSAGES=C
191export LC_MESSAGES
192test "`guix package -s "An example GNU package" | grep ^name:`" = \
193 "name: hello"
194test -z "`guix package -s "n0t4r341p4ck4g3"`"
195
196# Make sure `--search' can display all the packages.
197guix package --search="" > /dev/null
198
d7ddb257
LC
199# There's no generation older than 12 months, so the following command should
200# have no effect.
201generation="`readlink_base "$profile"`"
202if guix package -p "$profile" --delete-generations=12m;
203then false; else true; fi
204test "`readlink_base "$profile"`" = "$generation"
205
67668155 206#
0ec1af59 207# Try with the default profile.
67668155 208#
0ec1af59
LC
209
210XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
211export XDG_CACHE_HOME
88371f0d 212HOME="$PWD/t-home-$$"
0ec1af59
LC
213export HOME
214
215mkdir -p "$HOME"
216
59c51be2
LC
217# Get the canonical directory name so that 'guix package' recognizes it.
218HOME="`cd $HOME; pwd -P`"
219
e49951eb 220guix package --bootstrap -i guile-bootstrap
0ec1af59
LC
221test -L "$HOME/.guix-profile"
222test -f "$HOME/.guix-profile/bin/guile"
24e262f0 223
67668155
LC
224if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
225then
5d4b411f 226 guix package --bootstrap -e "$boot_make"
67668155
LC
227 test -f "$HOME/.guix-profile/bin/make"
228 first_environment="`cd $HOME/.guix-profile ; pwd`"
229
e49951eb 230 guix package --bootstrap --roll-back
67668155
LC
231 test -f "$HOME/.guix-profile/bin/guile"
232 ! test -f "$HOME/.guix-profile/bin/make"
233 test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment"
234fi
235
d9307267
LC
236# Move to the empty profile.
237default_profile="`readlink "$HOME/.guix-profile"`"
238for i in `seq 1 3`
239do
d2952326
LC
240 # Make sure the current generation is a GC root.
241 profile_link="`readlink "$default_profile"`"
242 guix gc --list-live | grep "`readlink "$profile_link"`"
243
e49951eb 244 guix package --bootstrap --roll-back
d9307267
LC
245 ! test -f "$HOME/.guix-profile/bin"
246 ! test -f "$HOME/.guix-profile/lib"
247 test "`readlink "$default_profile"`" = "$default_profile-0-link"
248done
3b9c0020 249
88371f0d
LC
250# Check whether '-p ~/.guix-profile' makes any difference.
251# See <http://bugs.gnu.org/17939>.
252if test -e "$HOME/.guix-profile-0-link"; then false; fi
253if test -e "$HOME/.guix-profile-1-link"; then false; fi
254guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
255if test -e "$HOME/.guix-profile-1-link"; then false; fi
256guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
257if test -e "$HOME/.guix-profile-0-link"; then false; fi
258
3b9c0020 259# Extraneous argument.
e49951eb 260if guix package install foo-bar;
aa92cf98 261then false; else true; fi
1a43e4dc
LC
262
263# Make sure the "broken pipe" doesn't yield an error.
264# Note: 'pipefail' is a Bash-specific option.
265set -o pipefail || true
266guix package -A g | head -1 2> "$HOME/err1"
267guix package -I | head -1 2> "$HOME/err2"
268test "`cat "$HOME/err1" "$HOME/err2"`" = ""
300868ba
LC
269
270# Make sure '-L' extends the package module search path.
300868ba 271mkdir "$module_dir"
300868ba
LC
272
273cat > "$module_dir/foo.scm"<<EOF
274(define-module (foo)
275 #:use-module (guix packages)
276 #:use-module (gnu packages emacs))
277
278(define-public x
279 (package (inherit emacs)
280 (name "emacs-foo-bar")
281 (version "42")))
282EOF
283
284guix package -A emacs-foo-bar -L "$module_dir" | grep 42
285guix package -i emacs-foo-bar-42 -n -L "$module_dir"
8689901f
LC
286
287# Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
288GUIX_PACKAGE_PATH="$module_dir"
289export GUIX_PACKAGE_PATH
290guix package -A emacs-foo-bar | grep 42
291guix package -i emacs-foo-bar-42 -n
ee06af5b
LC
292
293# Make sure patches that live under $GUIX_PACKAGE_PATH are found.
294cat > "$module_dir/emacs.patch"<<EOF
295This is a fake patch.
296EOF
297cat > "$module_dir/foo.scm"<<EOF
298(define-module (foo)
299 #:use-module (guix packages)
300 #:use-module (gnu packages)
301 #:use-module (gnu packages emacs))
302
303(define-public x
304 (package (inherit emacs)
305 (source (origin (inherit (package-source emacs))
306 (patches (list (search-patch "emacs.patch")))))
307 (name "emacs-foo-bar-patched")
308 (version "42")))
309EOF
310guix package -i emacs-foo-bar-patched -n
311
847391fe
DP
312unset GUIX_PACKAGE_PATH
313
314# Using 'GUIX_BUILD_OPTIONS'.
847391fe
DP
315available="`guix package -A | sort`"
316GUIX_BUILD_OPTIONS="--dry-run"
317export GUIX_BUILD_OPTIONS
318
319# Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
320# which would break 'guix package -A' and similar.
321available2="`guix package -A | sort`"
322test "$available2" = "$available"
323guix package -I