gtk and wayland update
[jackhill/guix/guix.git] / tests / guix-package.sh
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>
5 #
6 # This file is part of GNU Guix.
7 #
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.
12 #
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.
17 #
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/>.
20
21 #
22 # Test the `guix package' command-line utility.
23 #
24
25 guix package --version
26
27 readlink_base ()
28 {
29 basename `readlink "$1"`
30 }
31
32 module_dir="t-guix-package-$$"
33 profile="t-profile-$$"
34 tmpfile="t-guix-package-file-$$"
35 rm -f "$profile" "$tmpfile"
36
37 trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
38
39 # Use `-e' with a non-package expression.
40 ! guix package --bootstrap -e +
41
42 # Install a store item and make sure the version and output in the manifest
43 # are correct.
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"
48 rm "$profile"
49
50 guix package --bootstrap -p "$profile" -i guile-bootstrap
51 test -L "$profile" && test -L "$profile-1-link"
52 test -f "$profile/bin/guile"
53
54 # Make sure the profile is a GC root.
55 guix gc --list-live | grep "`readlink "$profile-1-link"`"
56
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"
62
63 # Unsupported packages cannot be installed.
64 ! guix package -e '(begin (use-modules (guix) (gnu packages base)) (package (inherit sed) (supported-systems (list))))' -n
65 case $(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;;
72 esac
73
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
77
78 guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \
79 --allow-collisions
80
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
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 )
89
90 # Exit with 1 when a generation does not exist.
91 ! guix package -p "$profile" --delete-generations=42
92
93 # Exit with 0 when trying to delete the zeroth generation.
94 guix package -p "$profile" --delete-generations=0
95
96 # Make sure multiple arguments to -i works.
97 guix package --bootstrap -i guile zile -p "$profile" -n
98
99 # Make sure the `:' syntax works.
100 guix package --bootstrap -i "glibc:debug" -p "$profile" -n
101
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"
106
107 # Make sure we get an error when trying to remove something that's not
108 # installed.
109 ! guix package --bootstrap -r something-not-installed -p "$profile"
110
111 # Check whether `--list-available' returns something sensible.
112 guix package -p "$profile" -A 'gui.*e' | grep guile
113
114 # Check whether `--show' returns something sensible.
115 guix package --show=guile | grep "^name: guile"
116
117 # Ensure `--show' doesn't fail for packages with non-package inputs.
118 guix package --show=texlive
119
120 # Fail for non-existent packages or package/version pairs.
121 ! guix package --show=does-not-exist
122 ! guix package --show=emacs@42
123
124 # Search.
125 LC_MESSAGES=C
126 export LC_MESSAGES
127 test "`guix package -s "An example GNU package" | grep ^name:`" = \
128 "name: hello"
129 test -z "`guix package -s "n0t4r341p4ck4g3"`"
130
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"
136
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"
141
142 rm -f "$tmpfile"
143
144 # Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
145 mkdir "$module_dir"
146 cat > "$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-is-the-old-name" coreutils))
153 EOF
154
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:`" = ""
157
158 rm -rf "$module_dir"
159
160 # Make sure `--search' can display all the packages.
161 guix package --search="" > /dev/null
162
163 # There's no generation older than 12 months, so the following command should
164 # have no effect.
165 generation="`readlink_base "$profile"`"
166 ! guix package -p "$profile" --delete-generations=12m
167 test "`readlink_base "$profile"`" = "$generation"
168
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"
175
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"
180
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" ]
186
187 # Package transformations.
188
189 # Make sure we get the right version number when using '--with-source'.
190 mkdir "$module_dir"
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 \
194 2> "$tmpfile"
195 grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile"
196 rm "$emacs_tarball" "$tmpfile"
197 rmdir "$module_dir"
198
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"
205
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
213
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>.
217 mkdir "$module_dir"
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))
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)))
236 EOF
237 guix package -p "$profile" -L "$module_dir"\
238 -i hello dummy-package \
239 --without-tests=hello -n
240 rm "$module_dir/test.scm"
241 rmdir "$module_dir"
242
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"
252 rmdir "$module_dir"
253
254 #
255 # Try with the default profile.
256 #
257
258 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
259 export XDG_CACHE_HOME
260 HOME="$PWD/t-home-$$"
261 export HOME
262
263 mkdir -p "$HOME"
264
265 # Get the canonical directory name so that 'guix package' recognizes it.
266 HOME="`cd $HOME; pwd -P`"
267
268 guix package --bootstrap -i guile-bootstrap
269 test -L "$HOME/.guix-profile"
270 test -f "$HOME/.guix-profile/bin/guile"
271
272 # Move to the empty profile.
273 default_profile="`readlink "$HOME/.guix-profile"`"
274 for i in `seq 1 3`
275 do
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
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`"
284 done
285
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"
294
295 # Extraneous argument.
296 ! guix package install foo-bar
297
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"`" = ""
304
305 # Make sure '-L' extends the package module search path.
306 mkdir "$module_dir"
307
308 cat > "$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")
316 (version "42.77.0")))
317 EOF
318
319 guix package -A emacs-foo-bar -L "$module_dir" | grep 42
320 guix package -i emacs-foo-bar@42 -n -L "$module_dir"
321
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
327
328 # Make sure GUIX_PACKAGE_PATH/'-L' takes precedence in case of duplicate packages.
329 cat > "$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")))
336 EOF
337
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 )
341
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.
345 EOF
346 cat > "$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")
357 (version "42.42.42")))
358
359 (define-public y
360 (package (inherit emacs)
361 (name "super-non-portable-emacs")
362 (supported-systems '("foobar64-hurd"))))
363 EOF
364 guix package -i emacs-foo-bar-patched -n
365
366 # Same when -L is used.
367 ( unset GUIX_PACKAGE_PATH; \
368 guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
369
370 # Make sure installing from a file works.
371 cat > "$module_dir/package.scm"<<EOF
372 (use-modules (gnu))
373 (use-package-modules bootstrap)
374
375 %bootstrap-guile
376 EOF
377 guix package --bootstrap --install-from-file="$module_dir/package.scm"
378
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))
382
383 (define my-package coreutils) ;returns *unspecified*
384 EOF
385 ! guix package --bootstrap --install-from-file="$module_dir/package.scm"
386
387 rm "$module_dir/package.scm"
388
389 # This one should not show up in searches since it's no supported on the
390 # current system.
391 test "`guix package -A super-non-portable-emacs`" = ""
392 test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
393
394 # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
395 guix package --bootstrap -p "$profile" -i guile-bootstrap
396
397 cat > "$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")))
404 EOF
405
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"
410 rm "$profile-2-link"
411
412 unset GUIX_PACKAGE_PATH
413
414
415 # Using 'GUIX_BUILD_OPTIONS'.
416 available="`guix package -A | sort`"
417 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
418 export 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.
422 available2="`guix package -A | sort`"
423 test "$available2" = "$available"
424 guix package -I
425
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"
429
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"
441
442 rm -f "$tmpfile.2nd"
443 guix package --rollback --bootstrap
444
445 # Applying a manifest file.
446 cat > "$module_dir/manifest.scm"<<EOF
447 (use-package-modules bootstrap)
448
449 (packages->manifest (list %bootstrap-guile))
450 EOF
451 guix package --bootstrap -m "$module_dir/manifest.scm"
452 guix package -I | grep guile
453 test `guix package -I | wc -l` -eq 1
454
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"
461
462 guix package --rollback --bootstrap
463
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))
469 EOF
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
476
477 # Applying a manifest file with inferior packages.
478 cat > "$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)))
486 EOF
487 guix package --bootstrap -m "$module_dir/manifest.scm"
488 guix package -I | grep guile
489 test `guix package -I | wc -l` -eq 1
490
491 # Error reporting.
492 cat > "$module_dir/manifest.scm"<<EOF
493 (use-package-modules bootstrap)
494 (packages->manifest
495 (list %bootstrap-guile
496 wonderful-package-that-does-not-exist))
497 EOF
498 if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
499 2> "$module_dir/stderr"
500 then false
501 else
502 cat "$module_dir/stderr"
503 grep "manifest.scm:[1-4]:.*wonderful-package.*: unbound variable" \
504 "$module_dir/stderr"
505 fi
506
507 # Verify that package outputs are included in search results.
508 rm -rf "$module_dir"
509 mkdir "$module_dir"
510 cat > "$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)
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")
526 (license #f)))
527 EOF
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"
530 rm -rf "$module_dir"
531
532 # Make sure we can see user profiles.
533 guix package --list-profiles | grep "$profile"
534 guix package --list-profiles | grep '\.guix-profile'
535
536 # Make sure we can properly lock a profile.
537 mkdir "$module_dir"
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" &
541 pid=$!
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
544 kill $pid