guix-pack-relocatable.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 --relocatable' using the external store, if any.
  20. #
  21. guix pack --version
  22. # 'guix pack --relocatable' requires a C compiler and libc.a, which our
  23. # bootstrap binaries don't provide. To make the test relatively inexpensive,
  24. # run it on the user's global store if possible, on the grounds that binaries
  25. # 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. STORE_PARENT="`dirname $NIX_STORE_DIR`"
  35. export STORE_PARENT
  36. if test "$STORE_PARENT" = "/"; then exit 77; fi
  37. # This test requires user namespaces and associated command-line tools.
  38. if ! unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"'
  39. then
  40. exit 77
  41. fi
  42. test_directory="`mktemp -d`"
  43. export test_directory
  44. trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
  45. tarball="`guix pack -R -S /Bin=bin sed`"
  46. (cd "$test_directory"; tar xvf "$tarball")
  47. # Run that relocatable 'sed' in a user namespace where we "erase" the store by
  48. # mounting an empty file system on top of it. That way, we exercise the
  49. # wrapper code that creates the user namespace and bind-mounts the store.
  50. unshare -mrf sh -c 'mount -t tmpfs none "$STORE_PARENT"; echo "$STORE_PARENT"/*; "$test_directory/Bin/sed" --version > "$test_directory/output"'
  51. grep 'GNU sed' "$test_directory/output"