guix-package.sh 16 KB

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