test-procedure 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 © 2021 Maxime Devos <maximedevos@@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. # based upon test-env
  20. # run this in a
  21. # guix environment guix --ad-hoc gnunet
  22. # Start GNUnet
  23. gnunetdir=`guix build gnunet`
  24. OLDPATH=$PATH
  25. PATH=$gnunetdir/bin:$gnunetdir/lib/gnunet/libexec:$PATH
  26. export PATH; hash
  27. function on_exit ()
  28. {
  29. if [ -n "$gfs_pid" ]
  30. then
  31. kill "$gfs_pid"
  32. fi
  33. if [ -n "$gds_pid" ]
  34. then
  35. kill "$gds_pid"
  36. fi
  37. if [ -n "$daemon_pid" ]
  38. then
  39. kill "$daemon_pid"
  40. fi
  41. if [ -n "$gpublish_pid" ]
  42. then
  43. kill "$gpublish_pid"
  44. fi
  45. }
  46. trap on_exit EXIT
  47. gnunet-service-fs&
  48. gfs_pid=$!
  49. gnunet-service-datastore&
  50. gds_pid=$!
  51. ####
  52. TESTDIR=$PWD/gtest
  53. NIX_STORE_DIR=$TESTDIR/store
  54. GUIX_LOG_DIRECTORY=$TESTDIR/log
  55. GUIX_DATABASE_DIRECTORY=$TESTDIR/db
  56. GUIX_STATE_DIRECTORY=$TESTDIR/state
  57. GUIX_CONFIGURATION_DIRECTORY=$TESTDIR/CONFIGURATION
  58. # The configuration directory, for import/export signing keys.
  59. GUIX_CONFIGURATION_DIRECTORY="/home/sylviidae/guix/git/guix-download-hook/test-tmp/etc"
  60. mkdir -p $GUIX_LOG_DIRECTORY $GUIX_DATABASE_DIRECTORY $GUIX_STATE_DIRECTORY $GUIX_CONFIGURATION_DIRECTORY $NIX_STORE_DIR
  61. if [ ! -d "$GUIX_CONFIGURATION_DIRECTORY" ]
  62. then
  63. # Copy the keys so that the secret key has the right permissions (the
  64. # daemon errors out when this is not the case.)
  65. mkdir -p "$GUIX_CONFIGURATION_DIRECTORY"
  66. cp "$PWD/tests/signing-key.sec" \
  67. "$PWD/tests/signing-key.pub" \
  68. "$GUIX_CONFIGURATION_DIRECTORY"
  69. chmod 400 "$GUIX_CONFIGURATION_DIRECTORY/signing-key.sec"
  70. fi
  71. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes
  72. XDG_CACHE_HOME="$GUIX_STATE_DIRECTORY/cache"
  73. mkdir -p "$XDG_CACHE_HOME"
  74. GUIX_BINARY_SUBSTITUTE_URL="http://localhost:7777"
  75. export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \
  76. GUIX_LOG_DIRECTORY GUIX_STATE_DIRECTORY GUIX_DATABASE_DIRECTORY \
  77. GUIX_BINARY_SUBSTITUTE_URL \
  78. GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \
  79. GUIX_CONFIGURATION_DIRECTORY XDG_CACHE_HOME
  80. # Launch the daemon without chroot support because is may be
  81. # unavailable, for instance if we're not running as root.
  82. # Also enable the GNUnet substituter
  83. "$PWD/pre-inst-env" "$PWD/guix-daemon" \
  84. --substitute-methods="gnunet http" \
  85. --disable-chroot \
  86. --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" &
  87. daemon_pid=$!
  88. # Avoid issues that could stem from l10n, such as language/encoding
  89. # mismatches.
  90. unset LANGUAGE
  91. LC_MESSAGES=C
  92. export LC_MESSAGES
  93. # Disable grafts by default because they can cause things to be built
  94. # regardless of '--dry-run'.
  95. GUIX_BUILD_OPTIONS="--no-grafts"
  96. export GUIX_BUILD_OPTIONS
  97. # Ignore user settings.
  98. unset GUIX_PACKAGE_PATH
  99. # Make sure the daemon is running
  100. ./pre-inst-env guile -c \
  101. '(use-modules (guix))
  102. (let loop ((i 10))
  103. (catch #t
  104. (lambda () (open-connection))
  105. (lambda (key . args)
  106. (if (zero? i)
  107. (apply throw key args)
  108. (begin (usleep 500000) (loop (- i 1)))))))'
  109. # The test suite expects the 'guile-bootstrap' package to be available.
  110. # Normally the Guile bootstrap tarball is downloaded by a fixed-output
  111. # derivation but when network access is missing we allow users to drop
  112. # the tarball in 'gnu/packages/bootstrap/SYSTEM' and "intern" it here.
  113. bootstrap_directory1="$PWD/gnu/packages/bootstrap/x86_64-linux"
  114. bootstrap_directory2="$PWD/gnu/packages/bootstrap/i686-linux"
  115. if [ -d "$bootstrap_directory1" ]
  116. then
  117. for file in "$bootstrap_directory1"/guile-*
  118. do
  119. [ -f "$file" ] && \
  120. "./pre-inst-env" \
  121. guix download "file://$file" > /dev/null
  122. done
  123. fi
  124. if [ -d "$bootstrap_directory2" ]
  125. then
  126. for file in "$bootstrap_directory2"/guile-*
  127. do
  128. [ -f "$file" ] && \
  129. "./pre-inst-env" \
  130. guix download "file://$file" > /dev/null
  131. done
  132. fi
  133. # Build something to substitute
  134. ./pre-inst-env guix build -e '(@@ (gnu packages commencement) bootar)' --no-substitutes
  135. store_path=`./pre-inst-env guix build -e '(@@ (gnu packages commencement) bootar)'`
  136. hash=`echo $store_path | sed -E -e 's/^(.*)\/(.*)-bootar-1a/\2/'`
  137. # Make sure the substitute is cached & publish it
  138. mkdir "$TESTDIR/cache-dir"
  139. ./pre-inst-env guix publish --port=7777 --listen=localhost --cache="$TESTDIR/cache-dir" \
  140. --hooks=$PWD/hook.scm --public-key=tests/signing-key.pub \
  141. --secret-key=tests/signing-key.sec&
  142. gpublish_pid=$!
  143. sleep 3
  144. ./pre-inst-env guix download http://localhost:7777/$hash.narinfo
  145. # ^ this should have a GNUnet: gnunet://fs/chk/... line
  146. # Let's try substitution now, in an environment without a network!
  147. echo "Please disconnect from the network"
  148. echo "(Not strictly necessary)"
  149. echo "(Only to demonstrate the substitution happens via GNUnet)"
  150. ./pre-inst-env guix gc --delete "$store_path"
  151. sleep 4
  152. echo "It's assumed you have been disconnected!"
  153. ./pre-inst-env guix build -e '(@@ (gnu packages commencement) bootar)'
  154. echo "The above substitution should have happened via GNUnet!"