hash: sha256 port now implements 'port-position'.
[jackhill/guix/guix.git] / tests / guix-package.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
0fb40579 2# Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 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 32profile="t-profile-$$"
db5a9444
LC
33tmpfile="t-guix-package-file-$$"
34rm -f "$profile" "$tmpfile"
0afdc485 35
db5a9444 36trap 'rm -f "$profile" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
7a6548cb 37
5d4b411f
LC
38# Use `-e' with a non-package expression.
39if guix package --bootstrap -e +;
40then false; else true; fi
41
aa042770
LC
42# Install a store item and make sure the version and output in the manifest
43# are correct.
44guix package --bootstrap -p "$profile" -i `guix build guile-bootstrap`
45test "`guix package -A guile-bootstrap | cut -f 1-2`" \
46 = "`guix package -p "$profile" -I | cut -f 1-2`"
47test "`guix package -p "$profile" -I | cut -f 3`" = "out"
48rm "$profile"
49
e49951eb 50guix package --bootstrap -p "$profile" -i guile-bootstrap
0afdc485
LC
51test -L "$profile" && test -L "$profile-1-link"
52test -f "$profile/bin/guile"
53
d2952326
LC
54# Make sure the profile is a GC root.
55guix gc --list-live | grep "`readlink "$profile-1-link"`"
56
1c67d639 57# Installing the same package a second time does nothing.
e49951eb 58guix package --bootstrap -p "$profile" -i guile-bootstrap
1c67d639
LC
59test -L "$profile" && test -L "$profile-1-link"
60! test -f "$profile-2-link"
61test -f "$profile/bin/guile"
0afdc485 62
477ee222
LC
63# Collisions are properly flagged (in this case, 'g-wrap' propagates
64# guile@2.2, which conflicts with guile@2.0.)
65if guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0
fc95dc4c
LC
66then false; else true; fi
67
477ee222 68guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \
fc95dc4c
LC
69 --allow-collisions
70
5924080d 71# No search path env. var. here.
dbc31ab2
LC
72guix package -p "$profile" --search-paths
73guix package -p "$profile" --search-paths | grep '^export PATH='
74test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
75( set -e; set -x; \
76 eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
77 test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
78 type -P rm )
5924080d 79
57b86237
LC
80# Exit with 1 when a generation does not exist.
81if guix package -p "$profile" --delete-generations=42;
82then false; else true; fi
83
84# Exit with 0 when trying to delete the zeroth generation.
85guix package -p "$profile" --delete-generations=0
0afdc485 86
6447738c
MW
87# Make sure multiple arguments to -i works.
88guix package --bootstrap -i guile gcc -p "$profile" -n
89
9518856b 90# Make sure the `:' syntax works.
ecb1b610 91guix package --bootstrap -i "glibc:debug" -p "$profile" -n
9518856b 92
aa92cf98 93# Make sure nonexistent outputs are reported.
e49951eb
MW
94guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
95if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
aa92cf98 96then false; else true; fi
e49951eb 97if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
aa92cf98
LC
98then false; else true; fi
99
64fc89b6 100# Check whether `--list-available' returns something sensible.
03f4ef28 101guix package -p "$profile" -A 'gui.*e' | grep guile
64fc89b6 102
2aa6efb0 103# Check whether `--show' returns something sensible.
3ce9aa44 104guix package --show=guile | grep "^name: guile"
2aa6efb0 105
1b0a86dd 106# Ensure `--show' doesn't fail for packages with non-package inputs.
5e6feee6
EB
107guix package --show=texlive
108
1b0a86dd
LC
109# Search.
110LC_MESSAGES=C
111export LC_MESSAGES
112test "`guix package -s "An example GNU package" | grep ^name:`" = \
113 "name: hello"
114test -z "`guix package -s "n0t4r341p4ck4g3"`"
115
db5a9444
LC
116# Search with one and then two regexps.
117# First we get printed circuit boards *and* board games.
118guix package -s '\<board\>' > "$tmpfile"
119grep '^name: pcb' "$tmpfile"
120grep '^name: gnubg' "$tmpfile"
121
122# Second we get only board games.
123guix package -s '\<board\>' -s game > "$tmpfile"
124grep -v '^name: pcb' "$tmpfile" > /dev/null
125grep '^name: gnubg' "$tmpfile"
126
127rm -f "$tmpfile"
128
0fb40579
LC
129# Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
130mkdir "$module_dir"
131cat > "$module_dir/foo.scm"<<EOF
132(define-module (foo)
133 #:use-module (guix packages)
134 #:use-module (gnu packages base))
135
136(define-public deprecated
137 (deprecated-package "fileutils" coreutils))
138EOF
139
140guix build -L "$module_dir" -e '(@ (foo) deprecated)' -n
141test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = ""
142
143rm -rf "$module_dir"
144
1b0a86dd
LC
145# Make sure `--search' can display all the packages.
146guix package --search="" > /dev/null
147
d7ddb257
LC
148# There's no generation older than 12 months, so the following command should
149# have no effect.
150generation="`readlink_base "$profile"`"
151if guix package -p "$profile" --delete-generations=12m;
152then false; else true; fi
153test "`readlink_base "$profile"`" = "$generation"
154
d26eb84d
LC
155# The following command should not delete the current generation, even though
156# it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
157# there's nothing else to delete, it should just fail.
158guix package --list-generations -p "$profile"
159if guix package --bootstrap -p "$profile" --delete-generations=1..
160then false; else true; fi
161test "`readlink_base "$profile"`" = "$generation"
162
c9323a4c
LC
163# Make sure $profile is a GC root at this point.
164real_profile="`readlink -f "$profile"`"
165if guix gc -d "$real_profile"
166then false; else true; fi
167test -d "$real_profile"
168
169# Now, let's remove all the symlinks to $real_profile, and make sure
170# $real_profile is no longer a GC root.
171rm "$profile" "$profile"-[0-9]-link
172guix gc -d "$real_profile"
173[ ! -d "$real_profile" ]
174
494dc2fc
LC
175# Package transformations.
176
177# Make sure we get the right version number when using '--with-source'.
178mkdir "$module_dir"
179emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
180touch "$emacs_tarball"
181guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
182 2> "$tmpfile"
183grep -E 'emacs[[:blank:]]+42\.5\.9rc7[[:blank:]]+.*-emacs-42.5.9rc7' \
184 "$tmpfile"
185rm "$emacs_tarball" "$tmpfile"
186rmdir "$module_dir"
187
bc6e291e
LC
188# Profiles with a relative file name. Make sure we don't create dangling
189# symlinks--see bug report at
190# <https://lists.gnu.org/archive/html/guix-devel/2018-07/msg00036.html>.
191mkdir -p "$module_dir/foo"
192( cd "$module_dir" ; \
193 guix package --bootstrap -i guile-bootstrap -p foo/prof )
194test -f "$module_dir/foo/prof/bin/guile"
195rm "$module_dir/foo"/*
196rmdir "$module_dir/foo"
197rmdir "$module_dir"
494dc2fc 198
67668155 199#
0ec1af59 200# Try with the default profile.
67668155 201#
0ec1af59
LC
202
203XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
204export XDG_CACHE_HOME
88371f0d 205HOME="$PWD/t-home-$$"
0ec1af59
LC
206export HOME
207
208mkdir -p "$HOME"
209
59c51be2
LC
210# Get the canonical directory name so that 'guix package' recognizes it.
211HOME="`cd $HOME; pwd -P`"
212
e49951eb 213guix package --bootstrap -i guile-bootstrap
0ec1af59
LC
214test -L "$HOME/.guix-profile"
215test -f "$HOME/.guix-profile/bin/guile"
24e262f0 216
d9307267
LC
217# Move to the empty profile.
218default_profile="`readlink "$HOME/.guix-profile"`"
219for i in `seq 1 3`
220do
d2952326
LC
221 # Make sure the current generation is a GC root.
222 profile_link="`readlink "$default_profile"`"
223 guix gc --list-live | grep "`readlink "$profile_link"`"
224
e49951eb 225 guix package --bootstrap --roll-back
d9307267
LC
226 ! test -f "$HOME/.guix-profile/bin"
227 ! test -f "$HOME/.guix-profile/lib"
bc6e291e 228 test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
d9307267 229done
3b9c0020 230
88371f0d
LC
231# Check whether '-p ~/.guix-profile' makes any difference.
232# See <http://bugs.gnu.org/17939>.
233if test -e "$HOME/.guix-profile-0-link"; then false; fi
234if test -e "$HOME/.guix-profile-1-link"; then false; fi
235guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
236if test -e "$HOME/.guix-profile-1-link"; then false; fi
237guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
238if test -e "$HOME/.guix-profile-0-link"; then false; fi
239
3b9c0020 240# Extraneous argument.
e49951eb 241if guix package install foo-bar;
aa92cf98 242then false; else true; fi
1a43e4dc
LC
243
244# Make sure the "broken pipe" doesn't yield an error.
245# Note: 'pipefail' is a Bash-specific option.
246set -o pipefail || true
247guix package -A g | head -1 2> "$HOME/err1"
248guix package -I | head -1 2> "$HOME/err2"
249test "`cat "$HOME/err1" "$HOME/err2"`" = ""
300868ba
LC
250
251# Make sure '-L' extends the package module search path.
300868ba 252mkdir "$module_dir"
300868ba
LC
253
254cat > "$module_dir/foo.scm"<<EOF
255(define-module (foo)
256 #:use-module (guix packages)
257 #:use-module (gnu packages emacs))
258
259(define-public x
260 (package (inherit emacs)
261 (name "emacs-foo-bar")
262 (version "42")))
263EOF
264
265guix package -A emacs-foo-bar -L "$module_dir" | grep 42
1b846da8 266guix package -i emacs-foo-bar@42 -n -L "$module_dir"
8689901f
LC
267
268# Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
269GUIX_PACKAGE_PATH="$module_dir"
270export GUIX_PACKAGE_PATH
271guix package -A emacs-foo-bar | grep 42
1b846da8 272guix package -i emacs-foo-bar@42 -n
ee06af5b
LC
273
274# Make sure patches that live under $GUIX_PACKAGE_PATH are found.
275cat > "$module_dir/emacs.patch"<<EOF
276This is a fake patch.
277EOF
278cat > "$module_dir/foo.scm"<<EOF
279(define-module (foo)
280 #:use-module (guix packages)
281 #:use-module (gnu packages)
282 #:use-module (gnu packages emacs))
283
284(define-public x
285 (package (inherit emacs)
286 (source (origin (inherit (package-source emacs))
287 (patches (list (search-patch "emacs.patch")))))
288 (name "emacs-foo-bar-patched")
289 (version "42")))
5763ad92
LC
290
291(define-public y
292 (package (inherit emacs)
293 (name "super-non-portable-emacs")
294 (supported-systems '("foobar64-hurd"))))
ee06af5b
LC
295EOF
296guix package -i emacs-foo-bar-patched -n
297
223d7939
LC
298# Same when -L is used.
299( unset GUIX_PACKAGE_PATH; \
300 guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
301
0d279400
DT
302# Make sure installing from a file works.
303cat > "$module_dir/package.scm"<<EOF
304(use-modules (gnu))
305(use-package-modules bootstrap)
306
307%bootstrap-guile
308EOF
309guix package --bootstrap --install-from-file="$module_dir/package.scm"
310
5763ad92
LC
311# This one should not show up in searches since it's no supported on the
312# current system.
313test "`guix package -A super-non-portable-emacs`" = ""
314test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
315
fc8fdcf5
LC
316# Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
317guix package --bootstrap -p "$profile" -i guile-bootstrap
318
319cat > "$module_dir/foo.scm"<<EOF
320(define-module (foo)
321 #:use-module (guix)
322 #:use-module (gnu packages bootstrap))
323
324(define-public x
325 (package (inherit %bootstrap-guile) (version "42")))
326EOF
327
328guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile
329test ! -f "$profile/bin/guile"
330guix package --bootstrap -p "$profile" --roll-back
331test -f "$profile/bin/guile"
332rm "$profile-2-link"
333
847391fe
DP
334unset GUIX_PACKAGE_PATH
335
fc8fdcf5 336
847391fe 337# Using 'GUIX_BUILD_OPTIONS'.
847391fe 338available="`guix package -A | sort`"
442a6ff5 339GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
847391fe
DP
340export GUIX_BUILD_OPTIONS
341
342# Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
343# which would break 'guix package -A' and similar.
344available2="`guix package -A | sort`"
345test "$available2" = "$available"
346guix package -I
1b676447 347
442a6ff5
LC
348# Restore '--no-grafts', which makes sure we don't end up building stuff when
349# '--dry-run' is passed.
350GUIX_BUILD_OPTIONS="--no-grafts"
1b676447 351
5f1087c4 352# Applying a manifest file.
1b676447
DT
353cat > "$module_dir/manifest.scm"<<EOF
354(use-package-modules bootstrap)
355
356(packages->manifest (list %bootstrap-guile))
357EOF
358guix package --bootstrap -m "$module_dir/manifest.scm"
359guix package -I | grep guile
360test `guix package -I | wc -l` -eq 1
5f1087c4
LC
361
362# Error reporting.
363cat > "$module_dir/manifest.scm"<<EOF
364(use-package-modules bootstrap)
365(packages->manifest
366 (list %bootstrap-guile
367 wonderful-package-that-does-not-exist))
368EOF
369if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
370 2> "$module_dir/stderr"
371then false
372else
373 cat "$module_dir/stderr"
ae0307f7 374 grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
5f1087c4
LC
375 "$module_dir/stderr"
376fi