guix-package.sh 17 KB

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