gnu: jack-2: Update to 1.9.14.
[jackhill/guix/guix.git] / tests / guix-package.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
487cbb01 2# Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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
b1fb6634 36trap 'rm -f "$profile" "$profile.lock" "$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 87# Make sure multiple arguments to -i works.
ccabb664 88guix package --bootstrap -i guile zile -p "$profile" -n
6447738c 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
487cbb01
LC
100# Make sure we get an error when trying to remove something that's not
101# installed.
102if guix package --bootstrap -r something-not-installed -p "$profile";
103then false; else true; fi
104
64fc89b6 105# Check whether `--list-available' returns something sensible.
03f4ef28 106guix package -p "$profile" -A 'gui.*e' | grep guile
64fc89b6 107
2aa6efb0 108# Check whether `--show' returns something sensible.
3ce9aa44 109guix package --show=guile | grep "^name: guile"
2aa6efb0 110
1b0a86dd 111# Ensure `--show' doesn't fail for packages with non-package inputs.
5e6feee6
EB
112guix package --show=texlive
113
65216315
LC
114# Fail for non-existent packages or package/version pairs.
115if guix package --show=does-not-exist; then false; else true; fi
116if guix package --show=emacs@42; then false; else true; fi
117
1b0a86dd
LC
118# Search.
119LC_MESSAGES=C
120export LC_MESSAGES
121test "`guix package -s "An example GNU package" | grep ^name:`" = \
122 "name: hello"
123test -z "`guix package -s "n0t4r341p4ck4g3"`"
124
db5a9444
LC
125# Search with one and then two regexps.
126# First we get printed circuit boards *and* board games.
127guix package -s '\<board\>' > "$tmpfile"
128grep '^name: pcb' "$tmpfile"
129grep '^name: gnubg' "$tmpfile"
130
131# Second we get only board games.
132guix package -s '\<board\>' -s game > "$tmpfile"
133grep -v '^name: pcb' "$tmpfile" > /dev/null
134grep '^name: gnubg' "$tmpfile"
135
136rm -f "$tmpfile"
137
0fb40579
LC
138# Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
139mkdir "$module_dir"
140cat > "$module_dir/foo.scm"<<EOF
141(define-module (foo)
142 #:use-module (guix packages)
143 #:use-module (gnu packages base))
144
145(define-public deprecated
146 (deprecated-package "fileutils" coreutils))
147EOF
148
149guix build -L "$module_dir" -e '(@ (foo) deprecated)' -n
150test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = ""
151
152rm -rf "$module_dir"
153
1b0a86dd
LC
154# Make sure `--search' can display all the packages.
155guix package --search="" > /dev/null
156
d7ddb257
LC
157# There's no generation older than 12 months, so the following command should
158# have no effect.
159generation="`readlink_base "$profile"`"
160if guix package -p "$profile" --delete-generations=12m;
161then false; else true; fi
162test "`readlink_base "$profile"`" = "$generation"
163
d26eb84d
LC
164# The following command should not delete the current generation, even though
165# it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
166# there's nothing else to delete, it should just fail.
167guix package --list-generations -p "$profile"
168if guix package --bootstrap -p "$profile" --delete-generations=1..
169then false; else true; fi
170test "`readlink_base "$profile"`" = "$generation"
171
c9323a4c
LC
172# Make sure $profile is a GC root at this point.
173real_profile="`readlink -f "$profile"`"
174if guix gc -d "$real_profile"
175then false; else true; fi
176test -d "$real_profile"
177
178# Now, let's remove all the symlinks to $real_profile, and make sure
179# $real_profile is no longer a GC root.
180rm "$profile" "$profile"-[0-9]-link
181guix gc -d "$real_profile"
182[ ! -d "$real_profile" ]
183
494dc2fc
LC
184# Package transformations.
185
186# Make sure we get the right version number when using '--with-source'.
187mkdir "$module_dir"
188emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
189touch "$emacs_tarball"
190guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
191 2> "$tmpfile"
c136da3f 192grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile"
494dc2fc
LC
193rm "$emacs_tarball" "$tmpfile"
194rmdir "$module_dir"
195
bc6e291e
LC
196# Profiles with a relative file name. Make sure we don't create dangling
197# symlinks--see bug report at
198# <https://lists.gnu.org/archive/html/guix-devel/2018-07/msg00036.html>.
199mkdir -p "$module_dir/foo"
200( cd "$module_dir" ; \
201 guix package --bootstrap -i guile-bootstrap -p foo/prof )
202test -f "$module_dir/foo/prof/bin/guile"
203rm "$module_dir/foo"/*
204rmdir "$module_dir/foo"
205rmdir "$module_dir"
494dc2fc 206
67668155 207#
0ec1af59 208# Try with the default profile.
67668155 209#
0ec1af59
LC
210
211XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
212export XDG_CACHE_HOME
88371f0d 213HOME="$PWD/t-home-$$"
0ec1af59
LC
214export HOME
215
216mkdir -p "$HOME"
217
59c51be2
LC
218# Get the canonical directory name so that 'guix package' recognizes it.
219HOME="`cd $HOME; pwd -P`"
220
e49951eb 221guix package --bootstrap -i guile-bootstrap
0ec1af59
LC
222test -L "$HOME/.guix-profile"
223test -f "$HOME/.guix-profile/bin/guile"
24e262f0 224
d9307267
LC
225# Move to the empty profile.
226default_profile="`readlink "$HOME/.guix-profile"`"
227for i in `seq 1 3`
228do
d2952326
LC
229 # Make sure the current generation is a GC root.
230 profile_link="`readlink "$default_profile"`"
231 guix gc --list-live | grep "`readlink "$profile_link"`"
232
e49951eb 233 guix package --bootstrap --roll-back
d9307267
LC
234 ! test -f "$HOME/.guix-profile/bin"
235 ! test -f "$HOME/.guix-profile/lib"
bc6e291e 236 test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
d9307267 237done
3b9c0020 238
88371f0d
LC
239# Check whether '-p ~/.guix-profile' makes any difference.
240# See <http://bugs.gnu.org/17939>.
241if test -e "$HOME/.guix-profile-0-link"; then false; fi
242if test -e "$HOME/.guix-profile-1-link"; then false; fi
243guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
244if test -e "$HOME/.guix-profile-1-link"; then false; fi
245guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
246if test -e "$HOME/.guix-profile-0-link"; then false; fi
247
3b9c0020 248# Extraneous argument.
e49951eb 249if guix package install foo-bar;
aa92cf98 250then false; else true; fi
1a43e4dc
LC
251
252# Make sure the "broken pipe" doesn't yield an error.
253# Note: 'pipefail' is a Bash-specific option.
254set -o pipefail || true
255guix package -A g | head -1 2> "$HOME/err1"
256guix package -I | head -1 2> "$HOME/err2"
257test "`cat "$HOME/err1" "$HOME/err2"`" = ""
300868ba
LC
258
259# Make sure '-L' extends the package module search path.
300868ba 260mkdir "$module_dir"
300868ba
LC
261
262cat > "$module_dir/foo.scm"<<EOF
263(define-module (foo)
264 #:use-module (guix packages)
265 #:use-module (gnu packages emacs))
266
267(define-public x
268 (package (inherit emacs)
269 (name "emacs-foo-bar")
270 (version "42")))
271EOF
272
273guix package -A emacs-foo-bar -L "$module_dir" | grep 42
1b846da8 274guix package -i emacs-foo-bar@42 -n -L "$module_dir"
8689901f
LC
275
276# Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
277GUIX_PACKAGE_PATH="$module_dir"
278export GUIX_PACKAGE_PATH
279guix package -A emacs-foo-bar | grep 42
1b846da8 280guix package -i emacs-foo-bar@42 -n
ee06af5b 281
002d17dc
RV
282# Make sure GUIX_PACKAGE_PATH/'-L' takes precedence in case of duplicate packages.
283cat > "$module_dir/bar.scm"<<EOF
284(define-module (bar)
285 #:use-module (guix packages))
286
287(define-public hello
288 (package (inherit (@@ (gnu packages base) hello))
289 (synopsis "an overridden version of GNU hello")))
290EOF
291
292guix package -i hello -n 2>&1 | grep choosing.*bar.scm
293( unset GUIX_PACKAGE_PATH; \
294 guix package -i hello -n -L "$module_dir" 2>&1 | grep choosing.*bar.scm )
295
ee06af5b
LC
296# Make sure patches that live under $GUIX_PACKAGE_PATH are found.
297cat > "$module_dir/emacs.patch"<<EOF
298This is a fake patch.
299EOF
300cat > "$module_dir/foo.scm"<<EOF
301(define-module (foo)
302 #:use-module (guix packages)
303 #:use-module (gnu packages)
304 #:use-module (gnu packages emacs))
305
306(define-public x
307 (package (inherit emacs)
308 (source (origin (inherit (package-source emacs))
309 (patches (list (search-patch "emacs.patch")))))
310 (name "emacs-foo-bar-patched")
311 (version "42")))
5763ad92
LC
312
313(define-public y
314 (package (inherit emacs)
315 (name "super-non-portable-emacs")
316 (supported-systems '("foobar64-hurd"))))
ee06af5b
LC
317EOF
318guix package -i emacs-foo-bar-patched -n
319
223d7939
LC
320# Same when -L is used.
321( unset GUIX_PACKAGE_PATH; \
322 guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
323
0d279400
DT
324# Make sure installing from a file works.
325cat > "$module_dir/package.scm"<<EOF
326(use-modules (gnu))
327(use-package-modules bootstrap)
328
329%bootstrap-guile
330EOF
331guix package --bootstrap --install-from-file="$module_dir/package.scm"
332
f9c04003
LC
333# Make sure an error is raised if the file doesn't return a package.
334cat > "$module_dir/package.scm"<<EOF
335(use-modules (gnu packages base))
336
337(define my-package coreutils) ;returns *unspecified*
338EOF
339if guix package --bootstrap --install-from-file="$module_dir/package.scm"
340then false; else true; fi
341
342rm "$module_dir/package.scm"
343
5763ad92
LC
344# This one should not show up in searches since it's no supported on the
345# current system.
346test "`guix package -A super-non-portable-emacs`" = ""
347test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
348
fc8fdcf5
LC
349# Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
350guix package --bootstrap -p "$profile" -i guile-bootstrap
351
352cat > "$module_dir/foo.scm"<<EOF
353(define-module (foo)
354 #:use-module (guix)
355 #:use-module (gnu packages bootstrap))
356
357(define-public x
358 (package (inherit %bootstrap-guile) (version "42")))
359EOF
360
361guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile
362test ! -f "$profile/bin/guile"
363guix package --bootstrap -p "$profile" --roll-back
364test -f "$profile/bin/guile"
365rm "$profile-2-link"
366
847391fe
DP
367unset GUIX_PACKAGE_PATH
368
fc8fdcf5 369
847391fe 370# Using 'GUIX_BUILD_OPTIONS'.
847391fe 371available="`guix package -A | sort`"
442a6ff5 372GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
847391fe
DP
373export GUIX_BUILD_OPTIONS
374
375# Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
376# which would break 'guix package -A' and similar.
377available2="`guix package -A | sort`"
378test "$available2" = "$available"
379guix package -I
1b676447 380
442a6ff5
LC
381# Restore '--no-grafts', which makes sure we don't end up building stuff when
382# '--dry-run' is passed.
383GUIX_BUILD_OPTIONS="--no-grafts"
1b676447 384
5f1087c4 385# Applying a manifest file.
1b676447
DT
386cat > "$module_dir/manifest.scm"<<EOF
387(use-package-modules bootstrap)
388
389(packages->manifest (list %bootstrap-guile))
390EOF
391guix package --bootstrap -m "$module_dir/manifest.scm"
392guix package -I | grep guile
393test `guix package -I | wc -l` -eq 1
811b21fb
LC
394guix package --rollback --bootstrap
395
bf9206d8
LC
396# Applying two manifests.
397cat > "$module_dir/manifest2.scm"<<EOF
398(use-modules (gnu packages bootstrap) (guix))
399(define p (package (inherit %bootstrap-guile) (name "eliug")))
400(packages->manifest (list p))
401EOF
402guix package --bootstrap \
403 -m "$module_dir/manifest.scm" -m "$module_dir/manifest2.scm"
404guix package -I | grep guile
405guix package -I | grep eliug
406test `guix package -I | wc -l` -eq 2
407guix package --rollback --bootstrap
408
811b21fb
LC
409# Applying a manifest file with inferior packages.
410cat > "$module_dir/manifest.scm"<<EOF
411(use-modules (guix inferior))
412
413(define i
414 (open-inferior "$abs_top_srcdir" #:command "scripts/guix"))
415
416(let ((guile (car (lookup-inferior-packages i "guile-bootstrap"))))
417 (packages->manifest (list guile)))
418EOF
419guix package --bootstrap -m "$module_dir/manifest.scm"
420guix package -I | grep guile
421test `guix package -I | wc -l` -eq 1
5f1087c4
LC
422
423# Error reporting.
424cat > "$module_dir/manifest.scm"<<EOF
425(use-package-modules bootstrap)
426(packages->manifest
427 (list %bootstrap-guile
428 wonderful-package-that-does-not-exist))
429EOF
430if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
431 2> "$module_dir/stderr"
432then false
433else
434 cat "$module_dir/stderr"
ae0307f7 435 grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
5f1087c4
LC
436 "$module_dir/stderr"
437fi
387e6b9e
CM
438
439# Verify that package outputs are included in search results.
440rm -rf "$module_dir"
441mkdir "$module_dir"
442cat > "$module_dir/foo.scm"<<EOF
443(define-module (foo)
444 #:use-module (guix packages)
445 #:use-module (guix build-system trivial))
446
447(define-public dummy-package
448 (package
449 (name "dummy-package")
450 (version "dummy-version")
451 (outputs '("out" "dummy-output"))
452 (source #f)
3972dc5d 453 ;; Without a real build system, the "guix package -s" command will fail.
387e6b9e
CM
454 (build-system trivial-build-system)
455 (synopsis "dummy-synopsis")
456 (description "dummy-description")
457 (home-page "https://dummy-home-page")
458 (license #f)))
459EOF
460guix package -L "$module_dir" -s dummy-output > /tmp/out
461test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
462rm -rf "$module_dir"
3972dc5d
LC
463
464# Make sure we can see user profiles.
465guix package --list-profiles | grep "$profile"
466guix package --list-profiles | grep '\.guix-profile'
b1fb6634
JL
467
468# Make sure we can properly lock a profile.
469mkdir "$module_dir"
dac7928d
LC
470echo "(open-output-file \"$module_dir/ready\") (sleep 60)" \
471 > "$module_dir/manifest.scm"
b1fb6634
JL
472guix package -m "$module_dir/manifest.scm" -p "$module_dir/profile" &
473pid=$!
dac7928d 474while [ ! -f "$module_dir/ready" ] ; do sleep 0.5 ; done
b1fb6634
JL
475if guix install emacs -p "$module_dir/profile"; then kill $pid; false; else true; fi
476kill $pid