guix-package.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 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. # Test the `guix package' command-line utility.
  21. #
  22. guix package --version
  23. readlink_base ()
  24. {
  25. basename `readlink "$1"`
  26. }
  27. module_dir="t-guix-package-$$"
  28. profile="t-profile-$$"
  29. tmpfile="t-guix-package-file-$$"
  30. rm -f "$profile" "$tmpfile"
  31. trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
  32. # Use `-e' with a non-package expression.
  33. ! guix package --bootstrap -e +
  34. # Install a store item and make sure the version and output in the manifest
  35. # are correct.
  36. guix package --bootstrap -p "$profile" -i `guix build guile-bootstrap`
  37. test "`guix package -A guile-bootstrap | cut -f 1-2`" \
  38. = "`guix package -p "$profile" -I | cut -f 1-2`"
  39. test "`guix package -p "$profile" -I | cut -f 3`" = "out"
  40. rm "$profile"
  41. guix package --bootstrap -p "$profile" -i guile-bootstrap
  42. test -L "$profile" && test -L "$profile-1-link"
  43. test -f "$profile/bin/guile"
  44. # Make sure the profile is a GC root.
  45. guix gc --list-live | grep "`readlink "$profile-1-link"`"
  46. # Installing the same package a second time does nothing.
  47. guix package --bootstrap -p "$profile" -i guile-bootstrap
  48. test -L "$profile" && test -L "$profile-1-link"
  49. ! test -f "$profile-2-link"
  50. test -f "$profile/bin/guile"
  51. # Collisions are properly flagged (in this case, 'g-wrap' propagates
  52. # guile@2.2, which conflicts with guile@2.0.)
  53. ! guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0
  54. guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \
  55. --allow-collisions
  56. # No search path env. var. here.
  57. guix package -p "$profile" --search-paths
  58. guix package -p "$profile" --search-paths | grep '^export PATH='
  59. test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
  60. ( set -e; set -x; \
  61. eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
  62. test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
  63. type -P rm )
  64. # Exit with 1 when a generation does not exist.
  65. ! guix package -p "$profile" --delete-generations=42
  66. # Exit with 0 when trying to delete the zeroth generation.
  67. guix package -p "$profile" --delete-generations=0
  68. # Make sure multiple arguments to -i works.
  69. guix package --bootstrap -i guile zile -p "$profile" -n
  70. # Make sure the `:' syntax works.
  71. guix package --bootstrap -i "glibc:debug" -p "$profile" -n
  72. # Make sure nonexistent outputs are reported.
  73. guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
  74. ! guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n
  75. ! guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile"
  76. # Make sure we get an error when trying to remove something that's not
  77. # installed.
  78. ! guix package --bootstrap -r something-not-installed -p "$profile"
  79. # Check whether `--list-available' returns something sensible.
  80. guix package -p "$profile" -A 'gui.*e' | grep guile
  81. # Check whether `--show' returns something sensible.
  82. guix package --show=guile | grep "^name: guile"
  83. # Ensure `--show' doesn't fail for packages with non-package inputs.
  84. guix package --show=texlive
  85. # Fail for non-existent packages or package/version pairs.
  86. ! guix package --show=does-not-exist
  87. ! guix package --show=emacs@42
  88. # Search.
  89. LC_MESSAGES=C
  90. export LC_MESSAGES
  91. test "`guix package -s "An example GNU package" | grep ^name:`" = \
  92. "name: hello"
  93. test -z "`guix package -s "n0t4r341p4ck4g3"`"
  94. # Search with one and then two regexps.
  95. # First we get printed circuit boards *and* board games.
  96. guix package -s '\<board\>' > "$tmpfile"
  97. grep '^name: pcb' "$tmpfile"
  98. grep '^name: gnubg' "$tmpfile"
  99. # Second we get only board games.
  100. guix package -s '\<board\>' -s game > "$tmpfile"
  101. grep -v '^name: pcb' "$tmpfile" > /dev/null
  102. grep '^name: gnubg' "$tmpfile"
  103. rm -f "$tmpfile"
  104. # Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>.
  105. mkdir "$module_dir"
  106. cat > "$module_dir/foo.scm"<<EOF
  107. (define-module (foo)
  108. #:use-module (guix packages)
  109. #:use-module (gnu packages base))
  110. (define-public deprecated
  111. (deprecated-package "fileutils" coreutils))
  112. EOF
  113. guix build -L "$module_dir" -e '(@ (foo) deprecated)' -n
  114. test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = ""
  115. rm -rf "$module_dir"
  116. # Make sure `--search' can display all the packages.
  117. guix package --search="" > /dev/null
  118. # There's no generation older than 12 months, so the following command should
  119. # have no effect.
  120. generation="`readlink_base "$profile"`"
  121. ! guix package -p "$profile" --delete-generations=12m
  122. test "`readlink_base "$profile"`" = "$generation"
  123. # The following command should not delete the current generation, even though
  124. # it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
  125. # there's nothing else to delete, it should just fail.
  126. guix package --list-generations -p "$profile"
  127. ! guix package --bootstrap -p "$profile" --delete-generations=1..
  128. test "`readlink_base "$profile"`" = "$generation"
  129. # Make sure $profile is a GC root at this point.
  130. real_profile="`readlink -f "$profile"`"
  131. ! guix gc -d "$real_profile"
  132. test -d "$real_profile"
  133. # Now, let's remove all the symlinks to $real_profile, and make sure
  134. # $real_profile is no longer a GC root.
  135. rm "$profile" "$profile"-[0-9]-link
  136. guix gc -d "$real_profile"
  137. [ ! -d "$real_profile" ]
  138. # Package transformations.
  139. # Make sure we get the right version number when using '--with-source'.
  140. mkdir "$module_dir"
  141. emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
  142. touch "$emacs_tarball"
  143. guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
  144. 2> "$tmpfile"
  145. grep -E 'emacs[[:blank:]]+42\.5\.9rc7' "$tmpfile"
  146. rm "$emacs_tarball" "$tmpfile"
  147. rmdir "$module_dir"
  148. # Install with package transformations.
  149. guix install --bootstrap -p "$profile" sed --with-input=sed=guile-bootstrap
  150. grep "sed=guile-bootstrap" "$profile/manifest"
  151. test "$(readlink -f "$profile/bin/guile")" \
  152. = "$(guix build guile-bootstrap)/bin/guile"
  153. test ! -f "$profile/bin/sed"
  154. # Make sure the package transformation is preserved.
  155. guix package --bootstrap -p "$profile" -u
  156. grep "sed=guile-bootstrap" "$profile/manifest"
  157. test "$(readlink -f "$profile/bin/guile")" \
  158. = "$(guix build guile-bootstrap)/bin/guile"
  159. test ! -f "$profile/bin/sed"
  160. rm "$profile" "$profile"-[0-9]-link
  161. # Profiles with a relative file name. Make sure we don't create dangling
  162. # symlinks--see bug report at
  163. # <https://lists.gnu.org/archive/html/guix-devel/2018-07/msg00036.html>.
  164. mkdir -p "$module_dir/foo"
  165. ( cd "$module_dir" ; \
  166. guix package --bootstrap -i guile-bootstrap -p foo/prof )
  167. test -f "$module_dir/foo/prof/bin/guile"
  168. rm "$module_dir/foo"/*
  169. rmdir "$module_dir/foo"
  170. rmdir "$module_dir"
  171. #
  172. # Try with the default profile.
  173. #
  174. XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  175. export XDG_CACHE_HOME
  176. HOME="$PWD/t-home-$$"
  177. export HOME
  178. mkdir -p "$HOME"
  179. # Get the canonical directory name so that 'guix package' recognizes it.
  180. HOME="`cd $HOME; pwd -P`"
  181. guix package --bootstrap -i guile-bootstrap
  182. test -L "$HOME/.guix-profile"
  183. test -f "$HOME/.guix-profile/bin/guile"
  184. # Move to the empty profile.
  185. default_profile="`readlink "$HOME/.guix-profile"`"
  186. for i in `seq 1 3`
  187. do
  188. # Make sure the current generation is a GC root.
  189. profile_link="`readlink "$default_profile"`"
  190. guix gc --list-live | grep "`readlink "$profile_link"`"
  191. guix package --bootstrap --roll-back
  192. ! test -f "$HOME/.guix-profile/bin"
  193. ! test -f "$HOME/.guix-profile/lib"
  194. test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`"
  195. done
  196. # Check whether '-p ~/.guix-profile' makes any difference.
  197. # See <http://bugs.gnu.org/17939>.
  198. ! test -e "$HOME/.guix-profile-0-link"
  199. ! test -e "$HOME/.guix-profile-1-link"
  200. guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
  201. ! test -e "$HOME/.guix-profile-1-link"
  202. guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
  203. ! test -e "$HOME/.guix-profile-0-link"
  204. # Extraneous argument.
  205. ! guix package install foo-bar
  206. # Make sure the "broken pipe" doesn't yield an error.
  207. # Note: 'pipefail' is a Bash-specific option.
  208. set -o pipefail || true
  209. guix package -A g | head -1 2> "$HOME/err1"
  210. guix package -I | head -1 2> "$HOME/err2"
  211. test "`cat "$HOME/err1" "$HOME/err2"`" = ""
  212. # Make sure '-L' extends the package module search path.
  213. mkdir "$module_dir"
  214. cat > "$module_dir/foo.scm"<<EOF
  215. (define-module (foo)
  216. #:use-module (guix packages)
  217. #:use-module (gnu packages emacs))
  218. (define-public x
  219. (package (inherit emacs)
  220. (name "emacs-foo-bar")
  221. (version "42.77.0")))
  222. EOF
  223. guix package -A emacs-foo-bar -L "$module_dir" | grep 42
  224. guix package -i emacs-foo-bar@42 -n -L "$module_dir"
  225. # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
  226. GUIX_PACKAGE_PATH="$module_dir"
  227. export GUIX_PACKAGE_PATH
  228. guix package -A emacs-foo-bar | grep 42
  229. guix package -i emacs-foo-bar@42 -n
  230. # Make sure GUIX_PACKAGE_PATH/'-L' takes precedence in case of duplicate packages.
  231. cat > "$module_dir/bar.scm"<<EOF
  232. (define-module (bar)
  233. #:use-module (guix packages))
  234. (define-public hello
  235. (package (inherit (@@ (gnu packages base) hello))
  236. (synopsis "an overridden version of GNU hello")))
  237. EOF
  238. guix package -i hello -n 2>&1 | grep choosing.*bar.scm
  239. ( unset GUIX_PACKAGE_PATH; \
  240. guix package -i hello -n -L "$module_dir" 2>&1 | grep choosing.*bar.scm )
  241. # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
  242. cat > "$module_dir/emacs.patch"<<EOF
  243. This is a fake patch.
  244. EOF
  245. cat > "$module_dir/foo.scm"<<EOF
  246. (define-module (foo)
  247. #:use-module (guix packages)
  248. #:use-module (gnu packages)
  249. #:use-module (gnu packages emacs))
  250. (define-public x
  251. (package (inherit emacs)
  252. (source (origin (inherit (package-source emacs))
  253. (patches (list (search-patch "emacs.patch")))))
  254. (name "emacs-foo-bar-patched")
  255. (version "42.42.42")))
  256. (define-public y
  257. (package (inherit emacs)
  258. (name "super-non-portable-emacs")
  259. (supported-systems '("foobar64-hurd"))))
  260. EOF
  261. guix package -i emacs-foo-bar-patched -n
  262. # Same when -L is used.
  263. ( unset GUIX_PACKAGE_PATH; \
  264. guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
  265. # Make sure installing from a file works.
  266. cat > "$module_dir/package.scm"<<EOF
  267. (use-modules (gnu))
  268. (use-package-modules bootstrap)
  269. %bootstrap-guile
  270. EOF
  271. guix package --bootstrap --install-from-file="$module_dir/package.scm"
  272. # Make sure an error is raised if the file doesn't return a package.
  273. cat > "$module_dir/package.scm"<<EOF
  274. (use-modules (gnu packages base))
  275. (define my-package coreutils) ;returns *unspecified*
  276. EOF
  277. ! guix package --bootstrap --install-from-file="$module_dir/package.scm"
  278. rm "$module_dir/package.scm"
  279. # This one should not show up in searches since it's no supported on the
  280. # current system.
  281. test "`guix package -A super-non-portable-emacs`" = ""
  282. test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
  283. # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>.
  284. guix package --bootstrap -p "$profile" -i guile-bootstrap
  285. cat > "$module_dir/foo.scm"<<EOF
  286. (define-module (foo)
  287. #:use-module (guix)
  288. #:use-module (gnu packages bootstrap))
  289. (define-public x
  290. (package (inherit %bootstrap-guile) (version "42")))
  291. EOF
  292. guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile
  293. test ! -f "$profile/bin/guile"
  294. guix package --bootstrap -p "$profile" --roll-back
  295. test -f "$profile/bin/guile"
  296. rm "$profile-2-link"
  297. unset GUIX_PACKAGE_PATH
  298. # Using 'GUIX_BUILD_OPTIONS'.
  299. available="`guix package -A | sort`"
  300. GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
  301. export GUIX_BUILD_OPTIONS
  302. # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
  303. # which would break 'guix package -A' and similar.
  304. available2="`guix package -A | sort`"
  305. test "$available2" = "$available"
  306. guix package -I
  307. # Restore '--no-grafts', which makes sure we don't end up building stuff when
  308. # '--dry-run' is passed.
  309. GUIX_BUILD_OPTIONS="--no-grafts"
  310. # Applying a manifest file.
  311. cat > "$module_dir/manifest.scm"<<EOF
  312. (use-package-modules bootstrap)
  313. (packages->manifest (list %bootstrap-guile))
  314. EOF
  315. guix package --bootstrap -m "$module_dir/manifest.scm"
  316. guix package -I | grep guile
  317. test `guix package -I | wc -l` -eq 1
  318. # Export a manifest, instantiate it, and make sure we get the same profile.
  319. profile_directory="$(readlink -f "$default_profile")"
  320. guix package --export-manifest > "$tmpfile"
  321. guix package --rollback --bootstrap
  322. guix package --bootstrap -m "$tmpfile"
  323. test "$(readlink -f "$default_profile")" = "$profile_directory"
  324. guix package --rollback --bootstrap
  325. # Applying two manifests.
  326. cat > "$module_dir/manifest2.scm"<<EOF
  327. (use-modules (gnu packages bootstrap) (guix))
  328. (define p (package (inherit %bootstrap-guile) (name "eliug")))
  329. (packages->manifest (list p))
  330. EOF
  331. guix package --bootstrap \
  332. -m "$module_dir/manifest.scm" -m "$module_dir/manifest2.scm"
  333. guix package -I | grep guile
  334. guix package -I | grep eliug
  335. test `guix package -I | wc -l` -eq 2
  336. guix package --rollback --bootstrap
  337. # Applying a manifest file with inferior packages.
  338. cat > "$module_dir/manifest.scm"<<EOF
  339. (use-modules (guix inferior))
  340. (define i
  341. (open-inferior "$abs_top_srcdir" #:command "scripts/guix"))
  342. (let ((guile (car (lookup-inferior-packages i "guile-bootstrap"))))
  343. (packages->manifest (list guile)))
  344. EOF
  345. guix package --bootstrap -m "$module_dir/manifest.scm"
  346. guix package -I | grep guile
  347. test `guix package -I | wc -l` -eq 1
  348. # Error reporting.
  349. cat > "$module_dir/manifest.scm"<<EOF
  350. (use-package-modules bootstrap)
  351. (packages->manifest
  352. (list %bootstrap-guile
  353. wonderful-package-that-does-not-exist))
  354. EOF
  355. if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
  356. 2> "$module_dir/stderr"
  357. then false
  358. else
  359. cat "$module_dir/stderr"
  360. grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
  361. "$module_dir/stderr"
  362. fi
  363. # Verify that package outputs are included in search results.
  364. rm -rf "$module_dir"
  365. mkdir "$module_dir"
  366. cat > "$module_dir/foo.scm"<<EOF
  367. (define-module (foo)
  368. #:use-module (guix packages)
  369. #:use-module (guix build-system trivial))
  370. (define-public dummy-package
  371. (package
  372. (name "dummy-package")
  373. (version "dummy-version")
  374. (outputs '("out" "dummy-output"))
  375. (source #f)
  376. ;; Without a real build system, the "guix package -s" command will fail.
  377. (build-system trivial-build-system)
  378. (synopsis "dummy-synopsis")
  379. (description "dummy-description")
  380. (home-page "https://dummy-home-page")
  381. (license #f)))
  382. EOF
  383. guix package -L "$module_dir" -s dummy-output > /tmp/out
  384. test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
  385. rm -rf "$module_dir"
  386. # Make sure we can see user profiles.
  387. guix package --list-profiles | grep "$profile"
  388. guix package --list-profiles | grep '\.guix-profile'
  389. # Make sure we can properly lock a profile.
  390. mkdir "$module_dir"
  391. echo "(open-output-file \"$module_dir/ready\") (sleep 60)" \
  392. > "$module_dir/manifest.scm"
  393. guix package -m "$module_dir/manifest.scm" -p "$module_dir/profile" &
  394. pid=$!
  395. while [ ! -f "$module_dir/ready" ] ; do sleep 0.5 ; done
  396. if guix install emacs -p "$module_dir/profile"; then kill $pid; false; else true; fi
  397. kill $pid