1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
5 # This file is part of GNU Guix.
7 # GNU Guix is free software; you can redistribute it and/or modify it
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.
12 # GNU Guix is distributed in the hope that it will be useful, but
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.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 # Test the `guix package' command-line utility.
24 guix package
--version
28 basename `readlink "$1"`
31 module_dir
="t-guix-package-$$"
32 profile
="t-profile-$$"
33 tmpfile
="t-guix-package-file-$$"
34 rm -f "$profile" "$tmpfile"
36 trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
38 # Use `-e' with a non-package expression.
39 if guix package
--bootstrap -e +;
40 then false
; else true
; fi
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 # Collisions are properly flagged (in this case, 'g-wrap' propagates
64 # guile@2.2, which conflicts with guile@2.0.)
65 if guix package
--bootstrap -n -p "$profile" -i g-wrap guile@
2.0
66 then false
; else true
; fi
68 guix package
--bootstrap -n -p "$profile" -i g-wrap guile@
2.0 \
71 # No search path env. var. here.
72 guix package
-p "$profile" --search-paths
73 guix package
-p "$profile" --search-paths |
grep '^export PATH='
74 test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
76 eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
77 test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
80 # Exit with 1 when a generation does not exist.
81 if guix package
-p "$profile" --delete-generations=42;
82 then false
; else true
; fi
84 # Exit with 0 when trying to delete the zeroth generation.
85 guix package
-p "$profile" --delete-generations=0
87 # Make sure multiple arguments to -i works.
88 guix package
--bootstrap -i guile zile
-p "$profile" -n
90 # Make sure the `:' syntax works.
91 guix package
--bootstrap -i "glibc:debug" -p "$profile" -n
93 # Make sure nonexistent outputs are reported.
94 guix package
--bootstrap -i "guile-bootstrap:out" -p "$profile" -n
95 if guix package
--bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
96 then false
; else true
; fi
97 if guix package
--bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
98 then false
; else true
; fi
100 # Make sure we get an error when trying to remove something that's not
102 if guix package
--bootstrap -r something-not-installed
-p "$profile";
103 then false
; else true
; fi
105 # Check whether `--list-available' returns something sensible.
106 guix package
-p "$profile" -A 'gui.*e' |
grep guile
108 # Check whether `--show' returns something sensible.
109 guix package
--show=guile |
grep "^name: guile"
111 # Ensure `--show' doesn't fail for packages with non-package inputs.
112 guix package
--show=texlive
114 # Fail for non-existent packages or package/version pairs.
115 if guix package
--show=does-not-exist
; then false
; else true
; fi
116 if guix package
--show=emacs@
42; then false
; else true
; fi
121 test "`guix package -s "An example GNU package
" | grep ^name:`" = \
123 test -z "`guix package -s "n0t4r341p4ck4g3
"`"
125 # Search with one and then two regexps.
126 # First we get printed circuit boards *and* board games.
127 guix package
-s '\<board\>' > "$tmpfile"
128 grep '^name: pcb' "$tmpfile"
129 grep '^name: gnubg' "$tmpfile"
131 # Second we get only board games.
132 guix package
-s '\<board\>' -s game
> "$tmpfile"
133 grep -v '^name: pcb' "$tmpfile" > /dev
/null
134 grep '^name: gnubg' "$tmpfile"
138 # Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
140 cat > "$module_dir/foo.scm"<<EOF
142 #:use-module (guix packages)
143 #:use-module (gnu packages base))
145 (define-public deprecated
146 (deprecated-package "fileutils" coreutils))
149 guix build
-L "$module_dir" -e '(@ (foo) deprecated)' -n
150 test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = ""
154 # Make sure `--search' can display all the packages.
155 guix package
--search="" > /dev
/null
157 # There's no generation older than 12 months, so the following command should
159 generation
="`readlink_base "$profile"`"
160 if guix package
-p "$profile" --delete-generations=12m
;
161 then false
; else true
; fi
162 test "`readlink_base "$profile"`" = "$generation"
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.
167 guix package
--list-generations -p "$profile"
168 if guix package
--bootstrap -p "$profile" --delete-generations=1..
169 then false
; else true
; fi
170 test "`readlink_base "$profile"`" = "$generation"
172 # Make sure $profile is a GC root at this point.
173 real_profile
="`readlink -f "$profile"`"
174 if guix gc
-d "$real_profile"
175 then false
; else true
; fi
176 test -d "$real_profile"
178 # Now, let's remove all the symlinks to $real_profile, and make sure
179 # $real_profile is no longer a GC root.
180 rm "$profile" "$profile"-[0-9]-link
181 guix gc
-d "$real_profile"
182 [ ! -d "$real_profile" ]
184 # Package transformations.
186 # Make sure we get the right version number when using '--with-source'.
188 emacs_tarball
="$module_dir/emacs-42.5.9rc7.tar.gz"
189 touch "$emacs_tarball"
190 guix package
-p "$profile" -i emacs
--with-source="$emacs_tarball" -n \
192 grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile"
193 rm "$emacs_tarball" "$tmpfile"
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>.
199 mkdir
-p "$module_dir/foo"
200 ( cd "$module_dir" ; \
201 guix package
--bootstrap -i guile-bootstrap
-p foo
/prof
)
202 test -f "$module_dir/foo/prof/bin/guile"
203 rm "$module_dir/foo"/*
204 rmdir "$module_dir/foo"
208 # Try with the default profile.
211 XDG_CACHE_HOME
="${XDG_CACHE_HOME:-$HOME/.cache}"
212 export XDG_CACHE_HOME
213 HOME
="$PWD/t-home-$$"
218 # Get the canonical directory name so that 'guix package' recognizes it.
219 HOME
="`cd $HOME; pwd -P`"
221 guix package
--bootstrap -i guile-bootstrap
222 test -L "$HOME/.guix-profile"
223 test -f "$HOME/.guix-profile/bin/guile"
225 # Move to the empty profile.
226 default_profile
="`readlink "$HOME/.guix-profile
"`"
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"`"
233 guix package
--bootstrap --roll-back
234 ! test -f "$HOME/.guix-profile/bin"
235 ! test -f "$HOME/.guix-profile/lib"
236 test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
239 # Check whether '-p ~/.guix-profile' makes any difference.
240 # See <http://bugs.gnu.org/17939>.
241 if test -e "$HOME/.guix-profile-0-link"; then false
; fi
242 if test -e "$HOME/.guix-profile-1-link"; then false
; fi
243 guix package
--bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
244 if test -e "$HOME/.guix-profile-1-link"; then false
; fi
245 guix package
--bootstrap --roll-back -p "$HOME/.guix-profile"
246 if test -e "$HOME/.guix-profile-0-link"; then false
; fi
248 # Extraneous argument.
249 if guix package
install foo-bar
;
250 then false
; else true
; fi
252 # Make sure the "broken pipe" doesn't yield an error.
253 # Note: 'pipefail' is a Bash-specific option.
254 set -o pipefail || true
255 guix package
-A g |
head -1 2> "$HOME/err1"
256 guix package
-I |
head -1 2> "$HOME/err2"
257 test "`cat "$HOME/err1
" "$HOME/err2
"`" = ""
259 # Make sure '-L' extends the package module search path.
262 cat > "$module_dir/foo.scm"<<EOF
264 #:use-module (guix packages)
265 #:use-module (gnu packages emacs))
268 (package (inherit emacs)
269 (name "emacs-foo-bar")
273 guix package
-A emacs-foo-bar
-L "$module_dir" |
grep 42
274 guix package
-i emacs-foo-bar@
42 -n -L "$module_dir"
276 # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
277 GUIX_PACKAGE_PATH
="$module_dir"
278 export GUIX_PACKAGE_PATH
279 guix package
-A emacs-foo-bar |
grep 42
280 guix package
-i emacs-foo-bar@
42 -n
282 # Make sure GUIX_PACKAGE_PATH/'-L' takes precedence in case of duplicate packages.
283 cat > "$module_dir/bar.scm"<<EOF
285 #:use-module (guix packages))
288 (package (inherit (@@ (gnu packages base) hello))
289 (synopsis "an overridden version of GNU hello")))
292 guix 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
)
296 # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
297 cat > "$module_dir/emacs.patch"<<EOF
298 This is a fake patch.
300 cat > "$module_dir/foo.scm"<<EOF
302 #:use-module (guix packages)
303 #:use-module (gnu packages)
304 #:use-module (gnu packages emacs))
307 (package (inherit emacs)
308 (source (origin (inherit (package-source emacs))
309 (patches (list (search-patch "emacs.patch")))))
310 (name "emacs-foo-bar-patched")
314 (package (inherit emacs)
315 (name "super-non-portable-emacs")
316 (supported-systems '("foobar64-hurd"))))
318 guix package
-i emacs-foo-bar-patched
-n
320 # Same when -L is used.
321 ( unset GUIX_PACKAGE_PATH
; \
322 guix package
-L "$module_dir" -i emacs-foo-bar-patched
-n )
324 # Make sure installing from a file works.
325 cat > "$module_dir/package.scm"<<EOF
327 (use-package-modules bootstrap)
331 guix package
--bootstrap --install-from-file="$module_dir/package.scm"
333 # Make sure an error is raised if the file doesn't return a package.
334 cat > "$module_dir/package.scm"<<EOF
335 (use-modules (gnu packages base))
337 (define my-package coreutils) ;returns *unspecified*
339 if guix package
--bootstrap --install-from-file="$module_dir/package.scm"
340 then false
; else true
; fi
342 rm "$module_dir/package.scm"
344 # This one should not show up in searches since it's no supported on the
346 test "`guix package -A super-non-portable-emacs`" = ""
347 test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
349 # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
350 guix package
--bootstrap -p "$profile" -i guile-bootstrap
352 cat > "$module_dir/foo.scm"<<EOF
355 #:use-module (gnu packages bootstrap))
358 (package (inherit %bootstrap-guile) (version "42")))
361 guix package
--bootstrap -p "$profile" -r guile-bootstrap
-u guile
362 test ! -f "$profile/bin/guile"
363 guix package
--bootstrap -p "$profile" --roll-back
364 test -f "$profile/bin/guile"
367 unset GUIX_PACKAGE_PATH
370 # Using 'GUIX_BUILD_OPTIONS'.
371 available
="`guix package -A | sort`"
372 GUIX_BUILD_OPTIONS
="--dry-run --no-grafts"
373 export GUIX_BUILD_OPTIONS
375 # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
376 # which would break 'guix package -A' and similar.
377 available2
="`guix package -A | sort`"
378 test "$available2" = "$available"
381 # Restore '--no-grafts', which makes sure we don't end up building stuff when
382 # '--dry-run' is passed.
383 GUIX_BUILD_OPTIONS
="--no-grafts"
385 # Applying a manifest file.
386 cat > "$module_dir/manifest.scm"<<EOF
387 (use-package-modules bootstrap)
389 (packages->manifest (list %bootstrap-guile))
391 guix package
--bootstrap -m "$module_dir/manifest.scm"
392 guix package
-I |
grep guile
393 test `guix package -I | wc -l` -eq 1
394 guix package
--rollback --bootstrap
396 # Applying two manifests.
397 cat > "$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))
402 guix package
--bootstrap \
403 -m "$module_dir/manifest.scm" -m "$module_dir/manifest2.scm"
404 guix package
-I |
grep guile
405 guix package
-I |
grep eliug
406 test `guix package -I | wc -l` -eq 2
407 guix package
--rollback --bootstrap
409 # Applying a manifest file with inferior packages.
410 cat > "$module_dir/manifest.scm"<<EOF
411 (use-modules (guix inferior))
414 (open-inferior "$abs_top_srcdir" #:command "scripts/guix"))
416 (let ((guile (car (lookup-inferior-packages i "guile-bootstrap"))))
417 (packages->manifest (list guile)))
419 guix package
--bootstrap -m "$module_dir/manifest.scm"
420 guix package
-I |
grep guile
421 test `guix package -I | wc -l` -eq 1
424 cat > "$module_dir/manifest.scm"<<EOF
425 (use-package-modules bootstrap)
427 (list %bootstrap-guile
428 wonderful-package-that-does-not-exist))
430 if guix package
--bootstrap -n -m "$module_dir/manifest.scm" \
431 2> "$module_dir/stderr"
434 cat "$module_dir/stderr"
435 grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
439 # Verify that package outputs are included in search results.
442 cat > "$module_dir/foo.scm"<<EOF
444 #:use-module (guix packages)
445 #:use-module (guix build-system trivial))
447 (define-public dummy-package
449 (name "dummy-package")
450 (version "dummy-version")
451 (outputs '("out" "dummy-output"))
453 ;; Without a real build system, the "guix package -s" command will fail.
454 (build-system trivial-build-system)
455 (synopsis "dummy-synopsis")
456 (description "dummy-description")
457 (home-page "https://dummy-home-page")
460 guix package
-L "$module_dir" -s dummy-output
> /tmp
/out
461 test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
464 # Make sure we can see user profiles.
465 guix package
--list-profiles |
grep "$profile"
466 guix package
--list-profiles |
grep '\.guix-profile'
468 # Make sure we can properly lock a profile.
470 echo "(open-output-file \"$module_dir/ready\") (sleep 60)" \
471 > "$module_dir/manifest.scm"
472 guix package
-m "$module_dir/manifest.scm" -p "$module_dir/profile" &
474 while [ ! -f "$module_dir/ready" ] ; do sleep 0.5 ; done
475 if guix
install emacs
-p "$module_dir/profile"; then kill $pid; false
; else true
; fi