guix-package.sh 15 KB

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