projects/guix·blob master · refs

546 lines · 17.4 KiB

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