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