guix-pack-localstatedir.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test the 'guix pack --localstatedir' command-line utility.
  20. #
  21. guix pack --version
  22. # 'guix pack --localstatedir' produces derivations that depend on
  23. # guile-sqlite3 and guile-gcrypt. To make that relatively inexpensive, run
  24. # the test in the user's global store if possible, on the grounds that
  25. # binaries may already be there or can be built or downloaded inexpensively.
  26. NIX_STORE_DIR="`guile -c '(use-modules (guix config))(display %storedir)'`"
  27. localstatedir="`guile -c '(use-modules (guix config))(display %localstatedir)'`"
  28. GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
  29. export NIX_STORE_DIR GUIX_DAEMON_SOCKET
  30. if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
  31. then
  32. exit 77
  33. fi
  34. # Build a tarball with '--localstatedir'
  35. the_pack="`guix pack -C none --localstatedir --profile-name=current-guix \
  36. guile-bootstrap`"
  37. test_directory="`mktemp -d`"
  38. trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
  39. cd "$test_directory"
  40. tar -xf "$the_pack"
  41. profile="`find -name current-guix`"
  42. test "`readlink $profile`" = "current-guix-1-link"
  43. test -s "`dirname $profile`/../../../db/db.sqlite"
  44. test -x ".`guix build guile-bootstrap`/bin/guile"
  45. cd -
  46. # Make sure the store database is not completely bogus.
  47. guile -c "(use-modules (sqlite3) (guix config) (ice-9 match))
  48. (define db
  49. (sqlite-open (string-append \"$test_directory\"
  50. %localstatedir
  51. \"/guix/db/db.sqlite\")
  52. SQLITE_OPEN_READONLY))
  53. (define stmt
  54. (sqlite-prepare db \"SELECT * FROM ValidPaths;\"))
  55. (match (sqlite-fold cons '() stmt)
  56. ((#(ids paths hashes times derivers sizes) ...)
  57. (exit (member \"`guix build guile-bootstrap`\" paths))))"