You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

132 lines
4.5 KiB

  1. #!/bin/sh
  2. # GNU Guix --- Functional package management for GNU
  3. # Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.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. # Usage: ./test-env COMMAND ARG...
  20. #
  21. # Run the daemon in the build directory, and run COMMAND within
  22. # `pre-inst-env'. This is used to run unit tests with the just-built
  23. # daemon, unless `--disable-daemon' was passed at configure time.
  24. # Make sure 'cd' behaves deterministically and doesn't write anything to
  25. # stdout.
  26. unset CDPATH
  27. if [ -x "@abs_top_builddir@/guix-daemon" ]
  28. then
  29. # Silence the daemon's output, which is often useless, as well as that of
  30. # Bash (such as "Terminated" messages when 'guix-daemon' is killed.)
  31. exec 2> /dev/null
  32. NIX_STORE_DIR="@GUIX_TEST_ROOT@/store"
  33. # Do that because store.scm calls `canonicalize-path' on it.
  34. mkdir -p "$NIX_STORE_DIR"
  35. # Canonicalize the store directory name in an attempt to avoid symlinks in
  36. # it or its parent directories. See <http://bugs.gnu.org/17935>.
  37. NIX_STORE_DIR="`cd "@GUIX_TEST_ROOT@/store"; pwd -P`"
  38. NIX_LOCALSTATE_DIR="@GUIX_TEST_ROOT@/var"
  39. NIX_LOG_DIR="@GUIX_TEST_ROOT@/var/log/guix"
  40. NIX_DB_DIR="@GUIX_TEST_ROOT@/db"
  41. NIX_ROOT_FINDER="@abs_top_builddir@/nix/scripts/list-runtime-roots"
  42. # Choose a PID-dependent name to allow for parallel builds. Note
  43. # that the directory name must be chosen so that the socket's file
  44. # name is less than 108-char long (the size of `sun_path' in glibc).
  45. # Currently, in Nix builds, we're at ~106 chars...
  46. NIX_STATE_DIR="@GUIX_TEST_ROOT@/var/$$"
  47. # We can't exit when we reach the limit, because perhaps the test doesn't
  48. # actually rely on the daemon, but at least warn.
  49. if test "`echo -n "$NIX_STATE_DIR/daemon-socket/socket" | wc -c`" -ge 108
  50. then
  51. echo "warning: exceeding socket file name limit; test may fail!" >&2
  52. fi
  53. # The configuration directory, for import/export signing keys.
  54. NIX_CONF_DIR="@GUIX_TEST_ROOT@/etc"
  55. if [ ! -d "$NIX_CONF_DIR" ]
  56. then
  57. # Copy the keys so that the secret key has the right permissions (the
  58. # daemon errors out when this is not the case.)
  59. mkdir -p "$NIX_CONF_DIR"
  60. cp "@abs_top_srcdir@/tests/signing-key.sec" \
  61. "@abs_top_srcdir@/tests/signing-key.pub" \
  62. "$NIX_CONF_DIR"
  63. chmod 400 "$NIX_CONF_DIR/signing-key.sec"
  64. fi
  65. # A place to store data of the substituter.
  66. GUIX_BINARY_SUBSTITUTE_URL="file://$NIX_STATE_DIR/substituter-data"
  67. rm -rf "$NIX_STATE_DIR/substituter-data"
  68. mkdir -p "$NIX_STATE_DIR/substituter-data"
  69. # For a number of tests, we want to allow unsigned narinfos, for
  70. # simplicity.
  71. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes
  72. # Place for the substituter's cache.
  73. XDG_CACHE_HOME="$NIX_STATE_DIR/cache-$$"
  74. # For the (guix import snix) tests.
  75. NIXPKGS="@NIXPKGS@"
  76. export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \
  77. NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR \
  78. NIX_ROOT_FINDER GUIX_BINARY_SUBSTITUTE_URL \
  79. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \
  80. NIX_CONF_DIR XDG_CACHE_HOME NIXPKGS
  81. # Launch the daemon without chroot support because is may be
  82. # unavailable, for instance if we're not running as root.
  83. "@abs_top_builddir@/pre-inst-env" \
  84. "@abs_top_builddir@/guix-daemon" --disable-chroot \
  85. --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" &
  86. daemon_pid=$!
  87. trap "kill $daemon_pid ; rm -rf $NIX_STATE_DIR" EXIT
  88. fi
  89. # Avoid issues that could stem from l10n, such as language/encoding
  90. # mismatches.
  91. unset LANGUAGE
  92. LC_MESSAGES=C
  93. export LC_MESSAGES
  94. # Disable grafts by default because they can cause things to be built
  95. # regardless of '--dry-run'.
  96. GUIX_BUILD_OPTIONS="--no-grafts"
  97. export GUIX_BUILD_OPTIONS
  98. # Ignore user settings.
  99. unset GUIX_PACKAGE_PATH
  100. storedir="@storedir@"
  101. prefix="@prefix@"
  102. datarootdir="@datarootdir@"
  103. datadir="@datadir@"
  104. localstatedir="@localstatedir@"
  105. export storedir prefix datarootdir datadir localstatedir
  106. "@abs_top_builddir@/pre-inst-env" "$@"
  107. exit $?