Merge branch 'origin/core-updates-next' into core-updates
[jackhill/guix/guix.git] / tests / guix-package.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
4 #
5 # This file is part of GNU Guix.
6 #
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.
11 #
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.
16 #
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/>.
19
20 #
21 # Test the `guix package' command-line utility.
22 #
23
24 guix package --version
25
26 readlink_base ()
27 {
28 basename `readlink "$1"`
29 }
30
31 module_dir="t-guix-package-$$"
32 profile="t-profile-$$"
33 tmpfile="t-guix-package-file-$$"
34 rm -f "$profile" "$tmpfile"
35
36 trap 'rm -f "$profile" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
37
38 # Use `-e' with a non-package expression.
39 if guix package --bootstrap -e +;
40 then false; else true; fi
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 # 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
67
68 guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \
69 --allow-collisions
70
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
75 ( set -e; set -x; \
76 eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
77 test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
78 type -P rm )
79
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
83
84 # Exit with 0 when trying to delete the zeroth generation.
85 guix package -p "$profile" --delete-generations=0
86
87 # Make sure multiple arguments to -i works.
88 guix package --bootstrap -i guile gcc -p "$profile" -n
89
90 # Make sure the `:' syntax works.
91 guix package --bootstrap -i "glibc:debug" -p "$profile" -n
92
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
99
100 # Check whether `--list-available' returns something sensible.
101 guix package -p "$profile" -A 'gui.*e' | grep guile
102
103 # Check whether `--show' returns something sensible.
104 guix package --show=guile | grep "^name: guile"
105
106 # Ensure `--show' doesn't fail for packages with non-package inputs.
107 guix package --show=texlive
108
109 # Search.
110 LC_MESSAGES=C
111 export LC_MESSAGES
112 test "`guix package -s "An example GNU package" | grep ^name:`" = \
113 "name: hello"
114 test -z "`guix package -s "n0t4r341p4ck4g3"`"
115
116 # Search with one and then two regexps.
117 # First we get printed circuit boards *and* board games.
118 guix package -s '\<board\>' > "$tmpfile"
119 grep '^name: pcb' "$tmpfile"
120 grep '^name: gnubg' "$tmpfile"
121
122 # Second we get only board games.
123 guix package -s '\<board\>' -s game > "$tmpfile"
124 grep -v '^name: pcb' "$tmpfile" > /dev/null
125 grep '^name: gnubg' "$tmpfile"
126
127 rm -f "$tmpfile"
128
129 # Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
130 mkdir "$module_dir"
131 cat > "$module_dir/foo.scm"<<EOF
132 (define-module (foo)
133 #:use-module (guix packages)
134 #:use-module (gnu packages base))
135
136 (define-public deprecated
137 (deprecated-package "fileutils" coreutils))
138 EOF
139
140 guix build -L "$module_dir" -e '(@ (foo) deprecated)' -n
141 test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = ""
142
143 rm -rf "$module_dir"
144
145 # Make sure `--search' can display all the packages.
146 guix package --search="" > /dev/null
147
148 # There's no generation older than 12 months, so the following command should
149 # have no effect.
150 generation="`readlink_base "$profile"`"
151 if guix package -p "$profile" --delete-generations=12m;
152 then false; else true; fi
153 test "`readlink_base "$profile"`" = "$generation"
154
155 # The following command should not delete the current generation, even though
156 # it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
157 # there's nothing else to delete, it should just fail.
158 guix package --list-generations -p "$profile"
159 if guix package --bootstrap -p "$profile" --delete-generations=1..
160 then false; else true; fi
161 test "`readlink_base "$profile"`" = "$generation"
162
163 # Make sure $profile is a GC root at this point.
164 real_profile="`readlink -f "$profile"`"
165 if guix gc -d "$real_profile"
166 then false; else true; fi
167 test -d "$real_profile"
168
169 # Now, let's remove all the symlinks to $real_profile, and make sure
170 # $real_profile is no longer a GC root.
171 rm "$profile" "$profile"-[0-9]-link
172 guix gc -d "$real_profile"
173 [ ! -d "$real_profile" ]
174
175 # Package transformations.
176
177 # Make sure we get the right version number when using '--with-source'.
178 mkdir "$module_dir"
179 emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
180 touch "$emacs_tarball"
181 guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
182 2> "$tmpfile"
183 grep -E 'emacs[[:blank:]]+42\.5\.9rc7[[:blank:]]+.*-emacs-42.5.9rc7' \
184 "$tmpfile"
185 rm "$emacs_tarball" "$tmpfile"
186 rmdir "$module_dir"
187
188
189 #
190 # Try with the default profile.
191 #
192
193 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
194 export XDG_CACHE_HOME
195 HOME="$PWD/t-home-$$"
196 export HOME
197
198 mkdir -p "$HOME"
199
200 # Get the canonical directory name so that 'guix package' recognizes it.
201 HOME="`cd $HOME; pwd -P`"
202
203 guix package --bootstrap -i guile-bootstrap
204 test -L "$HOME/.guix-profile"
205 test -f "$HOME/.guix-profile/bin/guile"
206
207 # Move to the empty profile.
208 default_profile="`readlink "$HOME/.guix-profile"`"
209 for i in `seq 1 3`
210 do
211 # Make sure the current generation is a GC root.
212 profile_link="`readlink "$default_profile"`"
213 guix gc --list-live | grep "`readlink "$profile_link"`"
214
215 guix package --bootstrap --roll-back
216 ! test -f "$HOME/.guix-profile/bin"
217 ! test -f "$HOME/.guix-profile/lib"
218 test "`readlink "$default_profile"`" = "$default_profile-0-link"
219 done
220
221 # Check whether '-p ~/.guix-profile' makes any difference.
222 # See <http://bugs.gnu.org/17939>.
223 if test -e "$HOME/.guix-profile-0-link"; then false; fi
224 if test -e "$HOME/.guix-profile-1-link"; then false; fi
225 guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
226 if test -e "$HOME/.guix-profile-1-link"; then false; fi
227 guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
228 if test -e "$HOME/.guix-profile-0-link"; then false; fi
229
230 # Extraneous argument.
231 if guix package install foo-bar;
232 then false; else true; fi
233
234 # Make sure the "broken pipe" doesn't yield an error.
235 # Note: 'pipefail' is a Bash-specific option.
236 set -o pipefail || true
237 guix package -A g | head -1 2> "$HOME/err1"
238 guix package -I | head -1 2> "$HOME/err2"
239 test "`cat "$HOME/err1" "$HOME/err2"`" = ""
240
241 # Make sure '-L' extends the package module search path.
242 mkdir "$module_dir"
243
244 cat > "$module_dir/foo.scm"<<EOF
245 (define-module (foo)
246 #:use-module (guix packages)
247 #:use-module (gnu packages emacs))
248
249 (define-public x
250 (package (inherit emacs)
251 (name "emacs-foo-bar")
252 (version "42")))
253 EOF
254
255 guix package -A emacs-foo-bar -L "$module_dir" | grep 42
256 guix package -i emacs-foo-bar@42 -n -L "$module_dir"
257
258 # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
259 GUIX_PACKAGE_PATH="$module_dir"
260 export GUIX_PACKAGE_PATH
261 guix package -A emacs-foo-bar | grep 42
262 guix package -i emacs-foo-bar@42 -n
263
264 # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
265 cat > "$module_dir/emacs.patch"<<EOF
266 This is a fake patch.
267 EOF
268 cat > "$module_dir/foo.scm"<<EOF
269 (define-module (foo)
270 #:use-module (guix packages)
271 #:use-module (gnu packages)
272 #:use-module (gnu packages emacs))
273
274 (define-public x
275 (package (inherit emacs)
276 (source (origin (inherit (package-source emacs))
277 (patches (list (search-patch "emacs.patch")))))
278 (name "emacs-foo-bar-patched")
279 (version "42")))
280
281 (define-public y
282 (package (inherit emacs)
283 (name "super-non-portable-emacs")
284 (supported-systems '("foobar64-hurd"))))
285 EOF
286 guix package -i emacs-foo-bar-patched -n
287
288 # Same when -L is used.
289 ( unset GUIX_PACKAGE_PATH; \
290 guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
291
292 # Make sure installing from a file works.
293 cat > "$module_dir/package.scm"<<EOF
294 (use-modules (gnu))
295 (use-package-modules bootstrap)
296
297 %bootstrap-guile
298 EOF
299 guix package --bootstrap --install-from-file="$module_dir/package.scm"
300
301 # This one should not show up in searches since it's no supported on the
302 # current system.
303 test "`guix package -A super-non-portable-emacs`" = ""
304 test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
305
306 # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
307 guix package --bootstrap -p "$profile" -i guile-bootstrap
308
309 cat > "$module_dir/foo.scm"<<EOF
310 (define-module (foo)
311 #:use-module (guix)
312 #:use-module (gnu packages bootstrap))
313
314 (define-public x
315 (package (inherit %bootstrap-guile) (version "42")))
316 EOF
317
318 guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile
319 test ! -f "$profile/bin/guile"
320 guix package --bootstrap -p "$profile" --roll-back
321 test -f "$profile/bin/guile"
322 rm "$profile-2-link"
323
324 unset GUIX_PACKAGE_PATH
325
326
327 # Using 'GUIX_BUILD_OPTIONS'.
328 available="`guix package -A | sort`"
329 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
330 export GUIX_BUILD_OPTIONS
331
332 # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
333 # which would break 'guix package -A' and similar.
334 available2="`guix package -A | sort`"
335 test "$available2" = "$available"
336 guix package -I
337
338 # Restore '--no-grafts', which makes sure we don't end up building stuff when
339 # '--dry-run' is passed.
340 GUIX_BUILD_OPTIONS="--no-grafts"
341
342 # Applying a manifest file.
343 cat > "$module_dir/manifest.scm"<<EOF
344 (use-package-modules bootstrap)
345
346 (packages->manifest (list %bootstrap-guile))
347 EOF
348 guix package --bootstrap -m "$module_dir/manifest.scm"
349 guix package -I | grep guile
350 test `guix package -I | wc -l` -eq 1
351
352 # Error reporting.
353 cat > "$module_dir/manifest.scm"<<EOF
354 (use-package-modules bootstrap)
355 (packages->manifest
356 (list %bootstrap-guile
357 wonderful-package-that-does-not-exist))
358 EOF
359 if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
360 2> "$module_dir/stderr"
361 then false
362 else
363 cat "$module_dir/stderr"
364 grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
365 "$module_dir/stderr"
366 fi