epiphany w/ gtk4 and webkitgtk 2.38
[jackhill/guix/guix.git] / tests / guix-package.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
5a573139 2# Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org>
acc08466 3# Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
aaf54782 4# Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
0afdc485 5#
233e7676 6# This file is part of GNU Guix.
0afdc485 7#
233e7676 8# GNU Guix is free software; you can redistribute it and/or modify it
0afdc485
LC
9# under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 3 of the License, or (at
11# your option) any later version.
12#
233e7676 13# GNU Guix is distributed in the hope that it will be useful, but
0afdc485
LC
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
233e7676 19# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
0afdc485
LC
20
21#
e49951eb 22# Test the `guix package' command-line utility.
0afdc485
LC
23#
24
e49951eb 25guix package --version
0afdc485 26
24e262f0
LC
27readlink_base ()
28{
29 basename `readlink "$1"`
30}
31
e25234e3 32module_dir="t-guix-package-$$"
0afdc485 33profile="t-profile-$$"
db5a9444
LC
34tmpfile="t-guix-package-file-$$"
35rm -f "$profile" "$tmpfile"
0afdc485 36
b1fb6634 37trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
7a6548cb 38
5d4b411f 39# Use `-e' with a non-package expression.
d8934360 40! guix package --bootstrap -e +
5d4b411f 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
5a573139
LC
63# Unsupported packages cannot be installed.
64! guix package -e '(begin (use-modules (guix) (gnu packages base)) (package (inherit sed) (supported-systems (list))))' -n
65case $(uname -m) in
66 x86_64|i[3456]86)
67 ! guix package -i novena-eeprom -n
68 break;;
69 *)
70 ! guix package -i intelmetool -n
71 break;;
72esac
73
477ee222
LC
74# Collisions are properly flagged (in this case, 'g-wrap' propagates
75# guile@2.2, which conflicts with guile@2.0.)
d8934360 76! guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0
fc95dc4c 77
477ee222 78guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \
fc95dc4c
LC
79 --allow-collisions
80
5924080d 81# No search path env. var. here.
dbc31ab2
LC
82guix package -p "$profile" --search-paths
83guix package -p "$profile" --search-paths | grep '^export PATH='
84test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
85( set -e; set -x; \
86 eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
87 test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
88 type -P rm )
5924080d 89
57b86237 90# Exit with 1 when a generation does not exist.
d8934360 91! guix package -p "$profile" --delete-generations=42
57b86237
LC
92
93# Exit with 0 when trying to delete the zeroth generation.
94guix package -p "$profile" --delete-generations=0
0afdc485 95
6447738c 96# Make sure multiple arguments to -i works.
ccabb664 97guix package --bootstrap -i guile zile -p "$profile" -n
6447738c 98
9518856b 99# Make sure the `:' syntax works.
ecb1b610 100guix package --bootstrap -i "glibc:debug" -p "$profile" -n
9518856b 101
aa92cf98 102# Make sure nonexistent outputs are reported.
e49951eb 103guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
d8934360
EB
104! guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n
105! guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile"
aa92cf98 106
487cbb01
LC
107# Make sure we get an error when trying to remove something that's not
108# installed.
d8934360 109! guix package --bootstrap -r something-not-installed -p "$profile"
487cbb01 110
64fc89b6 111# Check whether `--list-available' returns something sensible.
03f4ef28 112guix package -p "$profile" -A 'gui.*e' | grep guile
64fc89b6 113
2aa6efb0 114# Check whether `--show' returns something sensible.
3ce9aa44 115guix package --show=guile | grep "^name: guile"
2aa6efb0 116
1b0a86dd 117# Ensure `--show' doesn't fail for packages with non-package inputs.
5e6feee6
EB
118guix package --show=texlive
119
65216315 120# Fail for non-existent packages or package/version pairs.
d8934360
EB
121! guix package --show=does-not-exist
122! guix package --show=emacs@42
65216315 123
1b0a86dd
LC
124# Search.
125LC_MESSAGES=C
126export LC_MESSAGES
127test "`guix package -s "An example GNU package" | grep ^name:`" = \
128 "name: hello"
129test -z "`guix package -s "n0t4r341p4ck4g3"`"
130
db5a9444
LC
131# Search with one and then two regexps.
132# First we get printed circuit boards *and* board games.
133guix package -s '\<board\>' > "$tmpfile"
134grep '^name: pcb' "$tmpfile"
135grep '^name: gnubg' "$tmpfile"
136
137# Second we get only board games.
138guix package -s '\<board\>' -s game > "$tmpfile"
139grep -v '^name: pcb' "$tmpfile" > /dev/null
140grep '^name: gnubg' "$tmpfile"
141
142rm -f "$tmpfile"
143
0fb40579
LC
144# Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
145mkdir "$module_dir"
146cat > "$module_dir/foo.scm"<<EOF
147(define-module (foo)
148 #:use-module (guix packages)
149 #:use-module (gnu packages base))
150
151(define-public deprecated
152 (deprecated-package "fileutils" coreutils))
153EOF
154
155guix build -L "$module_dir" -e '(@ (foo) deprecated)' -n
156test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = ""
157
158rm -rf "$module_dir"
159
1b0a86dd
LC
160# Make sure `--search' can display all the packages.
161guix package --search="" > /dev/null
162
d7ddb257
LC
163# There's no generation older than 12 months, so the following command should
164# have no effect.
165generation="`readlink_base "$profile"`"
d8934360 166! guix package -p "$profile" --delete-generations=12m
d7ddb257
LC
167test "`readlink_base "$profile"`" = "$generation"
168
d26eb84d
LC
169# The following command should not delete the current generation, even though
170# it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
171# there's nothing else to delete, it should just fail.
172guix package --list-generations -p "$profile"
d8934360 173! guix package --bootstrap -p "$profile" --delete-generations=1..
d26eb84d
LC
174test "`readlink_base "$profile"`" = "$generation"
175
c9323a4c
LC
176# Make sure $profile is a GC root at this point.
177real_profile="`readlink -f "$profile"`"
d8934360 178! guix gc -d "$real_profile"
c9323a4c
LC
179test -d "$real_profile"
180
181# Now, let's remove all the symlinks to $real_profile, and make sure
182# $real_profile is no longer a GC root.
183rm "$profile" "$profile"-[0-9]-link
184guix gc -d "$real_profile"
185[ ! -d "$real_profile" ]
186
494dc2fc
LC
187# Package transformations.
188
189# Make sure we get the right version number when using '--with-source'.
190mkdir "$module_dir"
191emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
192touch "$emacs_tarball"
193guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
194 2> "$tmpfile"
c136da3f 195grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile"
494dc2fc
LC
196rm "$emacs_tarball" "$tmpfile"
197rmdir "$module_dir"
198
8e1907a7
LC
199# Install with package transformations.
200guix install --bootstrap -p "$profile" sed --with-input=sed=guile-bootstrap
201grep "sed=guile-bootstrap" "$profile/manifest"
202test "$(readlink -f "$profile/bin/guile")" \
203 = "$(guix build guile-bootstrap)/bin/guile"
204test ! -f "$profile/bin/sed"
205
206# Make sure the package transformation is preserved.
207guix package --bootstrap -p "$profile" -u
208grep "sed=guile-bootstrap" "$profile/manifest"
209test "$(readlink -f "$profile/bin/guile")" \
210 = "$(guix build guile-bootstrap)/bin/guile"
211test ! -f "$profile/bin/sed"
212rm "$profile" "$profile"-[0-9]-link
213
aaf54782
JP
214# Make sure transformations apply to propagated inputs and don't lead to
215# conflicts when installing them alongside, see
216# <https://issues.guix.gnu.org/55316>.
217mkdir "$module_dir"
218cat > "$module_dir/test.scm" <<EOF
219(define-module (test)
220 #:use-module (guix packages)
221 #:use-module (gnu packages base)
222 #:use-module (guix build-system trivial))
223
224(define-public dummy-package
225 (package
226 (name "dummy-package")
227 (version "1")
228 (source #f)
229 (build-system trivial-build-system)
230 (propagated-inputs
231 (list hello))
232 (synopsis "dummy")
233 (description "dummy")
234 (home-page "dummy")
235 (license #f)))
236EOF
237guix package -p "$profile" -L "$module_dir"\
238 -i hello dummy-package \
239 --without-tests=hello -n
240rm "$module_dir/test.scm"
241rmdir "$module_dir"
242
bc6e291e
LC
243# Profiles with a relative file name. Make sure we don't create dangling
244# symlinks--see bug report at
245# <https://lists.gnu.org/archive/html/guix-devel/2018-07/msg00036.html>.
246mkdir -p "$module_dir/foo"
247( cd "$module_dir" ; \
248 guix package --bootstrap -i guile-bootstrap -p foo/prof )
249test -f "$module_dir/foo/prof/bin/guile"
250rm "$module_dir/foo"/*
251rmdir "$module_dir/foo"
252rmdir "$module_dir"
494dc2fc 253
67668155 254#
0ec1af59 255# Try with the default profile.
67668155 256#
0ec1af59
LC
257
258XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
259export XDG_CACHE_HOME
88371f0d 260HOME="$PWD/t-home-$$"
0ec1af59
LC
261export HOME
262
263mkdir -p "$HOME"
264
59c51be2
LC
265# Get the canonical directory name so that 'guix package' recognizes it.
266HOME="`cd $HOME; pwd -P`"
267
e49951eb 268guix package --bootstrap -i guile-bootstrap
0ec1af59
LC
269test -L "$HOME/.guix-profile"
270test -f "$HOME/.guix-profile/bin/guile"
24e262f0 271
d9307267
LC
272# Move to the empty profile.
273default_profile="`readlink "$HOME/.guix-profile"`"
274for i in `seq 1 3`
275do
d2952326
LC
276 # Make sure the current generation is a GC root.
277 profile_link="`readlink "$default_profile"`"
278 guix gc --list-live | grep "`readlink "$profile_link"`"
279
e49951eb 280 guix package --bootstrap --roll-back
d9307267
LC
281 ! test -f "$HOME/.guix-profile/bin"
282 ! test -f "$HOME/.guix-profile/lib"
bc6e291e 283 test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
d9307267 284done
3b9c0020 285
88371f0d
LC
286# Check whether '-p ~/.guix-profile' makes any difference.
287# See <http://bugs.gnu.org/17939>.
d8934360
EB
288! test -e "$HOME/.guix-profile-0-link"
289! test -e "$HOME/.guix-profile-1-link"
88371f0d 290guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
d8934360 291! test -e "$HOME/.guix-profile-1-link"
88371f0d 292guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
d8934360 293! test -e "$HOME/.guix-profile-0-link"
88371f0d 294
3b9c0020 295# Extraneous argument.
d8934360 296! guix package install foo-bar
1a43e4dc
LC
297
298# Make sure the "broken pipe" doesn't yield an error.
299# Note: 'pipefail' is a Bash-specific option.
300set -o pipefail || true
301guix package -A g | head -1 2> "$HOME/err1"
302guix package -I | head -1 2> "$HOME/err2"
303test "`cat "$HOME/err1" "$HOME/err2"`" = ""
300868ba
LC
304
305# Make sure '-L' extends the package module search path.
300868ba 306mkdir "$module_dir"
300868ba
LC
307
308cat > "$module_dir/foo.scm"<<EOF
309(define-module (foo)
310 #:use-module (guix packages)
311 #:use-module (gnu packages emacs))
312
313(define-public x
314 (package (inherit emacs)
315 (name "emacs-foo-bar")
cc346931 316 (version "42.77.0")))
300868ba
LC
317EOF
318
319guix package -A emacs-foo-bar -L "$module_dir" | grep 42
1b846da8 320guix package -i emacs-foo-bar@42 -n -L "$module_dir"
8689901f
LC
321
322# Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
323GUIX_PACKAGE_PATH="$module_dir"
324export GUIX_PACKAGE_PATH
325guix package -A emacs-foo-bar | grep 42
1b846da8 326guix package -i emacs-foo-bar@42 -n
ee06af5b 327
002d17dc
RV
328# Make sure GUIX_PACKAGE_PATH/'-L' takes precedence in case of duplicate packages.
329cat > "$module_dir/bar.scm"<<EOF
330(define-module (bar)
331 #:use-module (guix packages))
332
333(define-public hello
334 (package (inherit (@@ (gnu packages base) hello))
335 (synopsis "an overridden version of GNU hello")))
336EOF
337
338guix package -i hello -n 2>&1 | grep choosing.*bar.scm
339( unset GUIX_PACKAGE_PATH; \
340 guix package -i hello -n -L "$module_dir" 2>&1 | grep choosing.*bar.scm )
341
ee06af5b
LC
342# Make sure patches that live under $GUIX_PACKAGE_PATH are found.
343cat > "$module_dir/emacs.patch"<<EOF
344This is a fake patch.
345EOF
346cat > "$module_dir/foo.scm"<<EOF
347(define-module (foo)
348 #:use-module (guix packages)
349 #:use-module (gnu packages)
350 #:use-module (gnu packages emacs))
351
352(define-public x
353 (package (inherit emacs)
354 (source (origin (inherit (package-source emacs))
355 (patches (list (search-patch "emacs.patch")))))
356 (name "emacs-foo-bar-patched")
cc346931 357 (version "42.42.42")))
5763ad92
LC
358
359(define-public y
360 (package (inherit emacs)
361 (name "super-non-portable-emacs")
362 (supported-systems '("foobar64-hurd"))))
ee06af5b
LC
363EOF
364guix package -i emacs-foo-bar-patched -n
365
223d7939
LC
366# Same when -L is used.
367( unset GUIX_PACKAGE_PATH; \
368 guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
369
0d279400
DT
370# Make sure installing from a file works.
371cat > "$module_dir/package.scm"<<EOF
372(use-modules (gnu))
373(use-package-modules bootstrap)
374
375%bootstrap-guile
376EOF
377guix package --bootstrap --install-from-file="$module_dir/package.scm"
378
f9c04003
LC
379# Make sure an error is raised if the file doesn't return a package.
380cat > "$module_dir/package.scm"<<EOF
381(use-modules (gnu packages base))
382
383(define my-package coreutils) ;returns *unspecified*
384EOF
d8934360 385! guix package --bootstrap --install-from-file="$module_dir/package.scm"
f9c04003
LC
386
387rm "$module_dir/package.scm"
388
5763ad92
LC
389# This one should not show up in searches since it's no supported on the
390# current system.
391test "`guix package -A super-non-portable-emacs`" = ""
392test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
393
fc8fdcf5
LC
394# Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
395guix package --bootstrap -p "$profile" -i guile-bootstrap
396
397cat > "$module_dir/foo.scm"<<EOF
398(define-module (foo)
399 #:use-module (guix)
400 #:use-module (gnu packages bootstrap))
401
402(define-public x
403 (package (inherit %bootstrap-guile) (version "42")))
404EOF
405
406guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile
407test ! -f "$profile/bin/guile"
408guix package --bootstrap -p "$profile" --roll-back
409test -f "$profile/bin/guile"
410rm "$profile-2-link"
411
847391fe
DP
412unset GUIX_PACKAGE_PATH
413
fc8fdcf5 414
847391fe 415# Using 'GUIX_BUILD_OPTIONS'.
847391fe 416available="`guix package -A | sort`"
442a6ff5 417GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
847391fe
DP
418export GUIX_BUILD_OPTIONS
419
420# Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
421# which would break 'guix package -A' and similar.
422available2="`guix package -A | sort`"
423test "$available2" = "$available"
424guix package -I
1b676447 425
442a6ff5
LC
426# Restore '--no-grafts', which makes sure we don't end up building stuff when
427# '--dry-run' is passed.
428GUIX_BUILD_OPTIONS="--no-grafts"
1b676447 429
90ea8b16
LC
430# Install using the "imperative model", export a manifest, instantiate it, and
431# make sure we get the same profile.
432guix package --bootstrap -i guile-bootstrap --without-tests=foo
433profile_directory="$(readlink -f "$default_profile")"
434guix package --export-manifest > "$tmpfile"
435grep 'without-tests.*foo' "$tmpfile"
436guix package --rollback --bootstrap
437guix package --bootstrap -m "$tmpfile"
438test "$(readlink -f "$default_profile")" = "$profile_directory"
439guix package --export-manifest > "$tmpfile.2nd"
440cmp "$tmpfile" "$tmpfile.2nd"
441
442rm -f "$tmpfile.2nd"
443guix package --rollback --bootstrap
444
5f1087c4 445# Applying a manifest file.
1b676447
DT
446cat > "$module_dir/manifest.scm"<<EOF
447(use-package-modules bootstrap)
448
449(packages->manifest (list %bootstrap-guile))
450EOF
451guix package --bootstrap -m "$module_dir/manifest.scm"
452guix package -I | grep guile
453test `guix package -I | wc -l` -eq 1
9fd7b050
LC
454
455# Export a manifest, instantiate it, and make sure we get the same profile.
456profile_directory="$(readlink -f "$default_profile")"
457guix package --export-manifest > "$tmpfile"
458guix package --rollback --bootstrap
459guix package --bootstrap -m "$tmpfile"
460test "$(readlink -f "$default_profile")" = "$profile_directory"
461
811b21fb
LC
462guix package --rollback --bootstrap
463
bf9206d8
LC
464# Applying two manifests.
465cat > "$module_dir/manifest2.scm"<<EOF
466(use-modules (gnu packages bootstrap) (guix))
467(define p (package (inherit %bootstrap-guile) (name "eliug")))
468(packages->manifest (list p))
469EOF
470guix package --bootstrap \
471 -m "$module_dir/manifest.scm" -m "$module_dir/manifest2.scm"
472guix package -I | grep guile
473guix package -I | grep eliug
474test `guix package -I | wc -l` -eq 2
475guix package --rollback --bootstrap
476
811b21fb
LC
477# Applying a manifest file with inferior packages.
478cat > "$module_dir/manifest.scm"<<EOF
479(use-modules (guix inferior))
480
481(define i
482 (open-inferior "$abs_top_srcdir" #:command "scripts/guix"))
483
484(let ((guile (car (lookup-inferior-packages i "guile-bootstrap"))))
485 (packages->manifest (list guile)))
486EOF
487guix package --bootstrap -m "$module_dir/manifest.scm"
488guix package -I | grep guile
489test `guix package -I | wc -l` -eq 1
5f1087c4
LC
490
491# Error reporting.
492cat > "$module_dir/manifest.scm"<<EOF
493(use-package-modules bootstrap)
494(packages->manifest
495 (list %bootstrap-guile
496 wonderful-package-that-does-not-exist))
497EOF
498if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
499 2> "$module_dir/stderr"
500then false
501else
502 cat "$module_dir/stderr"
524c9800 503 grep "manifest.scm:[1-4]:.*wonderful-package.*: unbound variable" \
5f1087c4
LC
504 "$module_dir/stderr"
505fi
387e6b9e
CM
506
507# Verify that package outputs are included in search results.
508rm -rf "$module_dir"
509mkdir "$module_dir"
510cat > "$module_dir/foo.scm"<<EOF
511(define-module (foo)
512 #:use-module (guix packages)
513 #:use-module (guix build-system trivial))
514
515(define-public dummy-package
516 (package
517 (name "dummy-package")
518 (version "dummy-version")
519 (outputs '("out" "dummy-output"))
520 (source #f)
3972dc5d 521 ;; Without a real build system, the "guix package -s" command will fail.
387e6b9e
CM
522 (build-system trivial-build-system)
523 (synopsis "dummy-synopsis")
524 (description "dummy-description")
525 (home-page "https://dummy-home-page")
526 (license #f)))
527EOF
528guix package -L "$module_dir" -s dummy-output > /tmp/out
529test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
530rm -rf "$module_dir"
3972dc5d
LC
531
532# Make sure we can see user profiles.
533guix package --list-profiles | grep "$profile"
534guix package --list-profiles | grep '\.guix-profile'
b1fb6634
JL
535
536# Make sure we can properly lock a profile.
537mkdir "$module_dir"
dac7928d
LC
538echo "(open-output-file \"$module_dir/ready\") (sleep 60)" \
539 > "$module_dir/manifest.scm"
b1fb6634
JL
540guix package -m "$module_dir/manifest.scm" -p "$module_dir/profile" &
541pid=$!
dac7928d 542while [ ! -f "$module_dir/ready" ] ; do sleep 0.5 ; done
b1fb6634
JL
543if guix install emacs -p "$module_dir/profile"; then kill $pid; false; else true; fi
544kill $pid