1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
4 # Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
6 # This file is part of GNU Guix.
8 # GNU Guix is free software; you can redistribute it and/or modify it
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.
13 # GNU Guix is distributed in the hope that it will be useful, but
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.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 # Test the `guix package' command-line utility.
25 guix package
--version
29 basename `readlink "$1"`
32 module_dir
="t-guix-package-$$"
33 profile
="t-profile-$$"
34 tmpfile
="t-guix-package-file-$$"
35 rm -f "$profile" "$tmpfile"
37 trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
39 # Use `-e' with a non-package expression.
40 ! guix package
--bootstrap -e +
42 # Install a store item and make sure the version and output in the manifest
44 guix package
--bootstrap -p "$profile" -i `guix build guile-bootstrap`
45 test "`guix package -A guile-bootstrap | cut -f 1-2`" \
46 = "`guix package -p "$profile" -I | cut -f 1-2`"
47 test "`guix package -p "$profile" -I | cut -f 3`" = "out"
50 guix package
--bootstrap -p "$profile" -i guile-bootstrap
51 test -L "$profile" && test -L "$profile-1-link"
52 test -f "$profile/bin/guile"
54 # Make sure the profile is a GC root.
55 guix gc
--list-live |
grep "`readlink "$profile-1-link"`"
57 # Installing the same package a second time does nothing.
58 guix package
--bootstrap -p "$profile" -i guile-bootstrap
59 test -L "$profile" && test -L "$profile-1-link"
60 ! test -f "$profile-2-link"
61 test -f "$profile/bin/guile"
63 # Unsupported packages cannot be installed.
64 ! guix package
-e '(begin (use-modules (guix) (gnu packages base)) (package (inherit sed) (supported-systems (list))))' -n
67 ! guix package
-i novena-eeprom
-n
70 ! guix package
-i intelmetool
-n
74 # Collisions are properly flagged (in this case, 'g-wrap' propagates
75 # guile@2.2, which conflicts with guile@2.0.)
76 ! guix package
--bootstrap -n -p "$profile" -i g-wrap guile@
2.0
78 guix package
--bootstrap -n -p "$profile" -i g-wrap guile@
2.0 \
81 # No search path env. var. here.
82 guix package
-p "$profile" --search-paths
83 guix package
-p "$profile" --search-paths |
grep '^export PATH='
84 test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
86 eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
87 test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
90 # Exit with 1 when a generation does not exist.
91 ! guix package
-p "$profile" --delete-generations=42
93 # Exit with 0 when trying to delete the zeroth generation.
94 guix package
-p "$profile" --delete-generations=0
96 # Make sure multiple arguments to -i works.
97 guix package
--bootstrap -i guile zile
-p "$profile" -n
99 # Make sure the `:' syntax works.
100 guix package
--bootstrap -i "glibc:debug" -p "$profile" -n
102 # Make sure nonexistent outputs are reported.
103 guix package
--bootstrap -i "guile-bootstrap:out" -p "$profile" -n
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"
107 # Make sure we get an error when trying to remove something that's not
109 ! guix package
--bootstrap -r something-not-installed
-p "$profile"
111 # Check whether `--list-available' returns something sensible.
112 guix package
-p "$profile" -A 'gui.*e' |
grep guile
114 # Check whether `--show' returns something sensible.
115 guix package
--show=guile |
grep "^name: guile"
117 # Ensure `--show' doesn't fail for packages with non-package inputs.
118 guix package
--show=texlive
120 # Fail for non-existent packages or package/version pairs.
121 ! guix package
--show=does-not-exist
122 ! guix package
--show=emacs@
42
127 test "`guix package -s "An example GNU package
" | grep ^name:`" = \
129 test -z "`guix package -s "n0t4r341p4ck4g3
"`"
131 # Search with one and then two regexps.
132 # First we get printed circuit boards *and* board games.
133 guix package
-s '\<board\>' > "$tmpfile"
134 grep '^name: pcb' "$tmpfile"
135 grep '^name: gnubg' "$tmpfile"
137 # Second we get only board games.
138 guix package
-s '\<board\>' -s game
> "$tmpfile"
139 grep -v '^name: pcb' "$tmpfile" > /dev
/null
140 grep '^name: gnubg' "$tmpfile"
144 # Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
146 cat > "$module_dir/foo.scm"<<EOF
148 #:use-module (guix packages)
149 #:use-module (gnu packages base))
151 (define-public deprecated
152 (deprecated-package "fileutils-is-the-old-name" coreutils))
155 guix build
-L "$module_dir" -e '(@ (foo) deprecated)' -n
156 test "`guix package -L "$module_dir" -s ^fileutils-is-the-old-name$ | grep ^name:`" = ""
160 # Make sure `--search' can display all the packages.
161 guix package
--search="" > /dev
/null
163 # There's no generation older than 12 months, so the following command should
165 generation
="`readlink_base "$profile"`"
166 ! guix package
-p "$profile" --delete-generations=12m
167 test "`readlink_base "$profile"`" = "$generation"
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.
172 guix package
--list-generations -p "$profile"
173 ! guix package
--bootstrap -p "$profile" --delete-generations=1..
174 test "`readlink_base "$profile"`" = "$generation"
176 # Make sure $profile is a GC root at this point.
177 real_profile
="`readlink -f "$profile"`"
178 ! guix gc
-d "$real_profile"
179 test -d "$real_profile"
181 # Now, let's remove all the symlinks to $real_profile, and make sure
182 # $real_profile is no longer a GC root.
183 rm "$profile" "$profile"-[0-9]-link
184 guix gc
-d "$real_profile"
185 [ ! -d "$real_profile" ]
187 # Package transformations.
189 # Make sure we get the right version number when using '--with-source'.
191 emacs_tarball
="$module_dir/emacs-42.5.9rc7.tar.gz"
192 touch "$emacs_tarball"
193 guix package
-p "$profile" -i emacs
--with-source="$emacs_tarball" -n \
195 grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile"
196 rm "$emacs_tarball" "$tmpfile"
199 # Install with package transformations.
200 guix
install --bootstrap -p "$profile" sed --with-input=sed=guile-bootstrap
201 grep "sed=guile-bootstrap" "$profile/manifest"
202 test "$(readlink -f "$profile/bin
/guile
")" \
203 = "$(guix build guile-bootstrap)/bin/guile"
204 test ! -f "$profile/bin/sed"
206 # Make sure the package transformation is preserved.
207 guix package
--bootstrap -p "$profile" -u
208 grep "sed=guile-bootstrap" "$profile/manifest"
209 test "$(readlink -f "$profile/bin
/guile
")" \
210 = "$(guix build guile-bootstrap)/bin/guile"
211 test ! -f "$profile/bin/sed"
212 rm "$profile" "$profile"-[0-9]-link
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>.
218 cat > "$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))
224 (define-public dummy-package
226 (name "dummy-package")
229 (build-system trivial-build-system)
233 (description "dummy")
237 guix package
-p "$profile" -L "$module_dir"\
238 -i hello dummy-package \
239 --without-tests=hello
-n
240 rm "$module_dir/test.scm"
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>.
246 mkdir
-p "$module_dir/foo"
247 ( cd "$module_dir" ; \
248 guix package
--bootstrap -i guile-bootstrap
-p foo
/prof
)
249 test -f "$module_dir/foo/prof/bin/guile"
250 rm "$module_dir/foo"/*
251 rmdir "$module_dir/foo"
255 # Try with the default profile.
258 XDG_CACHE_HOME
="${XDG_CACHE_HOME:-$HOME/.cache}"
259 export XDG_CACHE_HOME
260 HOME
="$PWD/t-home-$$"
265 # Get the canonical directory name so that 'guix package' recognizes it.
266 HOME
="`cd $HOME; pwd -P`"
268 guix package
--bootstrap -i guile-bootstrap
269 test -L "$HOME/.guix-profile"
270 test -f "$HOME/.guix-profile/bin/guile"
272 # Move to the empty profile.
273 default_profile
="`readlink "$HOME/.guix-profile
"`"
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"`"
280 guix package
--bootstrap --roll-back
281 ! test -f "$HOME/.guix-profile/bin"
282 ! test -f "$HOME/.guix-profile/lib"
283 test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
286 # Check whether '-p ~/.guix-profile' makes any difference.
287 # See <http://bugs.gnu.org/17939>.
288 ! test -e "$HOME/.guix-profile-0-link"
289 ! test -e "$HOME/.guix-profile-1-link"
290 guix package
--bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
291 ! test -e "$HOME/.guix-profile-1-link"
292 guix package
--bootstrap --roll-back -p "$HOME/.guix-profile"
293 ! test -e "$HOME/.guix-profile-0-link"
295 # Extraneous argument.
296 ! guix package
install foo-bar
298 # Make sure the "broken pipe" doesn't yield an error.
299 # Note: 'pipefail' is a Bash-specific option.
300 set -o pipefail || true
301 guix package
-A g |
head -1 2> "$HOME/err1"
302 guix package
-I |
head -1 2> "$HOME/err2"
303 test "`cat "$HOME/err1
" "$HOME/err2
"`" = ""
305 # Make sure '-L' extends the package module search path.
308 cat > "$module_dir/foo.scm"<<EOF
310 #:use-module (guix packages)
311 #:use-module (gnu packages emacs))
314 (package (inherit emacs)
315 (name "emacs-foo-bar")
316 (version "42.77.0")))
319 guix package
-A emacs-foo-bar
-L "$module_dir" |
grep 42
320 guix package
-i emacs-foo-bar@
42 -n -L "$module_dir"
322 # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
323 GUIX_PACKAGE_PATH
="$module_dir"
324 export GUIX_PACKAGE_PATH
325 guix package
-A emacs-foo-bar |
grep 42
326 guix package
-i emacs-foo-bar@
42 -n
328 # Make sure GUIX_PACKAGE_PATH/'-L' takes precedence in case of duplicate packages.
329 cat > "$module_dir/bar.scm"<<EOF
331 #:use-module (guix packages))
334 (package (inherit (@@ (gnu packages base) hello))
335 (synopsis "an overridden version of GNU hello")))
338 guix 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
)
342 # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
343 cat > "$module_dir/emacs.patch"<<EOF
344 This is a fake patch.
346 cat > "$module_dir/foo.scm"<<EOF
348 #:use-module (guix packages)
349 #:use-module (gnu packages)
350 #:use-module (gnu packages emacs))
353 (package (inherit emacs)
354 (source (origin (inherit (package-source emacs))
355 (patches (list (search-patch "emacs.patch")))))
356 (name "emacs-foo-bar-patched")
357 (version "42.42.42")))
360 (package (inherit emacs)
361 (name "super-non-portable-emacs")
362 (supported-systems '("foobar64-hurd"))))
364 guix package
-i emacs-foo-bar-patched
-n
366 # Same when -L is used.
367 ( unset GUIX_PACKAGE_PATH
; \
368 guix package
-L "$module_dir" -i emacs-foo-bar-patched
-n )
370 # Make sure installing from a file works.
371 cat > "$module_dir/package.scm"<<EOF
373 (use-package-modules bootstrap)
377 guix package
--bootstrap --install-from-file="$module_dir/package.scm"
379 # Make sure an error is raised if the file doesn't return a package.
380 cat > "$module_dir/package.scm"<<EOF
381 (use-modules (gnu packages base))
383 (define my-package coreutils) ;returns *unspecified*
385 ! guix package
--bootstrap --install-from-file="$module_dir/package.scm"
387 rm "$module_dir/package.scm"
389 # This one should not show up in searches since it's no supported on the
391 test "`guix package -A super-non-portable-emacs`" = ""
392 test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
394 # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
395 guix package
--bootstrap -p "$profile" -i guile-bootstrap
397 cat > "$module_dir/foo.scm"<<EOF
400 #:use-module (gnu packages bootstrap))
403 (package (inherit %bootstrap-guile) (version "42")))
406 guix package
--bootstrap -p "$profile" -r guile-bootstrap
-u guile
407 test ! -f "$profile/bin/guile"
408 guix package
--bootstrap -p "$profile" --roll-back
409 test -f "$profile/bin/guile"
412 unset GUIX_PACKAGE_PATH
415 # Using 'GUIX_BUILD_OPTIONS'.
416 available
="`guix package -A | sort`"
417 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
418 export GUIX_BUILD_OPTIONS
420 # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
421 # which would break 'guix package -A' and similar.
422 available2
="`guix package -A | sort`"
423 test "$available2" = "$available"
426 # Restore '--no-grafts', which makes sure we don't end up building stuff when
427 # '--dry-run' is passed.
428 GUIX_BUILD_OPTIONS
="--no-grafts"
430 # Install using the "imperative model", export a manifest, instantiate it, and
431 # make sure we get the same profile.
432 guix package
--bootstrap -i guile-bootstrap
--without-tests=foo
433 profile_directory
="$(readlink -f "$default_profile")"
434 guix package
--export-manifest > "$tmpfile"
435 grep 'without-tests.*foo' "$tmpfile"
436 guix package
--rollback --bootstrap
437 guix package
--bootstrap -m "$tmpfile"
438 test "$(readlink -f "$default_profile")" = "$profile_directory"
439 guix package
--export-manifest > "$tmpfile.2nd"
440 cmp "$tmpfile" "$tmpfile.2nd"
443 guix package
--rollback --bootstrap
445 # Applying a manifest file.
446 cat > "$module_dir/manifest.scm"<<EOF
447 (use-package-modules bootstrap)
449 (packages->manifest (list %bootstrap-guile))
451 guix package
--bootstrap -m "$module_dir/manifest.scm"
452 guix package
-I |
grep guile
453 test `guix package -I | wc -l` -eq 1
455 # Export a manifest, instantiate it, and make sure we get the same profile.
456 profile_directory
="$(readlink -f "$default_profile")"
457 guix package
--export-manifest > "$tmpfile"
458 guix package
--rollback --bootstrap
459 guix package
--bootstrap -m "$tmpfile"
460 test "$(readlink -f "$default_profile")" = "$profile_directory"
462 guix package
--rollback --bootstrap
464 # Applying two manifests.
465 cat > "$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))
470 guix package
--bootstrap \
471 -m "$module_dir/manifest.scm" -m "$module_dir/manifest2.scm"
472 guix package
-I |
grep guile
473 guix package
-I |
grep eliug
474 test `guix package -I | wc -l` -eq 2
475 guix package
--rollback --bootstrap
477 # Applying a manifest file with inferior packages.
478 cat > "$module_dir/manifest.scm"<<EOF
479 (use-modules (guix inferior))
482 (open-inferior "$abs_top_srcdir" #:command "scripts/guix"))
484 (let ((guile (car (lookup-inferior-packages i "guile-bootstrap"))))
485 (packages->manifest (list guile)))
487 guix package
--bootstrap -m "$module_dir/manifest.scm"
488 guix package
-I |
grep guile
489 test `guix package -I | wc -l` -eq 1
492 cat > "$module_dir/manifest.scm"<<EOF
493 (use-package-modules bootstrap)
495 (list %bootstrap-guile
496 wonderful-package-that-does-not-exist))
498 if guix package
--bootstrap -n -m "$module_dir/manifest.scm" \
499 2> "$module_dir/stderr"
502 cat "$module_dir/stderr"
503 grep "manifest.scm:[1-4]:.*wonderful-package.*: unbound variable" \
507 # Verify that package outputs are included in search results.
510 cat > "$module_dir/foo.scm"<<EOF
512 #:use-module (guix packages)
513 #:use-module (guix build-system trivial))
515 (define-public dummy-package
517 (name "dummy-package")
518 (version "dummy-version")
519 (outputs '("out" "dummy-output"))
521 ;; Without a real build system, the "guix package -s" command will fail.
522 (build-system trivial-build-system)
523 (synopsis "dummy-synopsis")
524 (description "dummy-description")
525 (home-page "https://dummy-home-page")
528 guix package
-L "$module_dir" -s dummy-output
> /tmp
/out
529 test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
532 # Make sure we can see user profiles.
533 guix package
--list-profiles |
grep "$profile"
534 guix package
--list-profiles |
grep '\.guix-profile'
536 # Make sure we can properly lock a profile.
538 echo "(open-output-file \"$module_dir/ready\") (sleep 60)" \
539 > "$module_dir/manifest.scm"
540 guix package
-m "$module_dir/manifest.scm" -p "$module_dir/profile" &
542 while [ ! -f "$module_dir/ready" ] ; do sleep 0.5 ; done
543 if guix
install emacs
-p "$module_dir/profile"; then kill $pid; false
; else true
; fi