gnu: signify: Update to 26.
[guix.git] / build-aux / test-env.in
blobb1470bb953571741ed6987a7b4cae07c750ba7cc
1 #!/bin/sh
3 # GNU Guix --- Functional package management for GNU
4 # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
6 # This file is part of GNU Guix.
8 # GNU Guix is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
13 # GNU Guix is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 # Usage: ./test-env COMMAND ARG...
23 # Run the daemon in the build directory, and run COMMAND within
24 # `pre-inst-env'. This is used to run unit tests with the just-built
25 # daemon, unless `--disable-daemon' was passed at configure time.
28 # Make sure 'cd' behaves deterministically and doesn't write anything to
29 # stdout.
30 unset CDPATH
32 case "$1" in
33 --quiet-stderr)
34 # Silence the daemon's output, which is often useless, as well as that
35 # of Bash (such as "Terminated" messages when 'guix-daemon' is
36 # killed.)
37 exec 2> /dev/null
38 shift
40 esac
42 if [ -x "@abs_top_builddir@/guix-daemon" ]
43 then
44 NIX_STORE_DIR="@GUIX_TEST_ROOT@/store"
46 # Do that because store.scm calls `canonicalize-path' on it.
47 mkdir -p "$NIX_STORE_DIR"
49 # Canonicalize the store directory name in an attempt to avoid symlinks in
50 # it or its parent directories. See <http://bugs.gnu.org/17935>.
51 NIX_STORE_DIR="`cd "@GUIX_TEST_ROOT@/store"; pwd -P`"
53 NIX_LOCALSTATE_DIR="@GUIX_TEST_ROOT@/var"
54 GUIX_LOG_DIRECTORY="@GUIX_TEST_ROOT@/var/log/guix"
55 GUIX_DATABASE_DIRECTORY="@GUIX_TEST_ROOT@/db"
56 NIX_ROOT_FINDER="@abs_top_builddir@/nix/scripts/list-runtime-roots"
58 # Choose a PID-dependent name to allow for parallel builds. Note
59 # that the directory name must be chosen so that the socket's file
60 # name is less than 108-char long (the size of `sun_path' in glibc).
61 # Currently, in Nix builds, we're at ~106 chars...
62 GUIX_STATE_DIRECTORY="@GUIX_TEST_ROOT@/var/$$"
64 # We can't exit when we reach the limit, because perhaps the test doesn't
65 # actually rely on the daemon, but at least warn.
66 if test "`echo -n "$GUIX_STATE_DIRECTORY/daemon-socket/socket" | wc -c`" -ge 108
67 then
68 echo "warning: exceeding socket file name limit; test may fail!" >&2
71 # The configuration directory, for import/export signing keys.
72 GUIX_CONFIGURATION_DIRECTORY="@GUIX_TEST_ROOT@/etc"
73 if [ ! -d "$GUIX_CONFIGURATION_DIRECTORY" ]
74 then
75 # Copy the keys so that the secret key has the right permissions (the
76 # daemon errors out when this is not the case.)
77 mkdir -p "$GUIX_CONFIGURATION_DIRECTORY"
78 cp "@abs_top_srcdir@/tests/signing-key.sec" \
79 "@abs_top_srcdir@/tests/signing-key.pub" \
80 "$GUIX_CONFIGURATION_DIRECTORY"
81 chmod 400 "$GUIX_CONFIGURATION_DIRECTORY/signing-key.sec"
84 # A place to store data of the substituter.
85 GUIX_BINARY_SUBSTITUTE_URL="file://$GUIX_STATE_DIRECTORY/substituter-data"
86 rm -rf "$GUIX_STATE_DIRECTORY/substituter-data"
87 mkdir -p "$GUIX_STATE_DIRECTORY/substituter-data"
89 # For a number of tests, we want to allow unsigned narinfos, for
90 # simplicity.
91 GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes
93 # Place for the substituter's cache.
94 XDG_CACHE_HOME="$GUIX_STATE_DIRECTORY/cache-$$"
96 # For the (guix import snix) tests.
97 NIXPKGS="@NIXPKGS@"
99 export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \
100 NIX_LOCALSTATE_DIR GUIX_LOG_DIRECTORY GUIX_STATE_DIRECTORY GUIX_DATABASE_DIRECTORY \
101 NIX_ROOT_FINDER GUIX_BINARY_SUBSTITUTE_URL \
102 GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \
103 GUIX_CONFIGURATION_DIRECTORY XDG_CACHE_HOME NIXPKGS
105 # Launch the daemon without chroot support because is may be
106 # unavailable, for instance if we're not running as root.
107 "@abs_top_builddir@/pre-inst-env" \
108 "@abs_top_builddir@/guix-daemon" --disable-chroot \
109 --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" &
111 daemon_pid=$!
112 trap "kill $daemon_pid ; rm -rf $GUIX_STATE_DIRECTORY" EXIT
114 # The test suite expects the 'guile-bootstrap' package to be available.
115 # Normally the Guile bootstrap tarball is downloaded by a fixed-output
116 # derivation but when network access is missing we allow users to drop
117 # the tarball in 'gnu/packages/bootstrap/SYSTEM' and "intern" it here.
118 bootstrap_directory="@abs_top_builddir@/gnu/packages/bootstrap/@guix_system@"
119 if [ -d "$bootstrap_directory" ]
120 then
121 # Make sure 'guix-daemon' is listening before invoking 'guix
122 # download'.
123 "@abs_top_builddir@/pre-inst-env" "@GUILE@" -c \
124 '(use-modules (guix))
125 (let loop ((i 10))
126 (catch #t
127 (lambda () (open-connection))
128 (lambda (key . args)
129 (if (zero? i)
130 (apply throw key args)
131 (begin (usleep 500000) (loop (- i 1)))))))'
133 for file in "$bootstrap_directory"/guile-*
135 [ -f "$file" ] && \
136 "@abs_top_builddir@/pre-inst-env" \
137 guix download "file://$file" > /dev/null
138 done
142 # Avoid issues that could stem from l10n, such as language/encoding
143 # mismatches.
144 unset LANGUAGE
145 LC_MESSAGES=C
146 export LC_MESSAGES
148 # Disable grafts by default because they can cause things to be built
149 # regardless of '--dry-run'.
150 GUIX_BUILD_OPTIONS="--no-grafts"
151 export GUIX_BUILD_OPTIONS
153 # Ignore user settings.
154 unset GUIX_PACKAGE_PATH
156 storedir="@storedir@"
157 prefix="@prefix@"
158 datarootdir="@datarootdir@"
159 datadir="@datadir@"
160 localstatedir="@localstatedir@"
161 export storedir prefix datarootdir datadir localstatedir
163 "@abs_top_builddir@/pre-inst-env" "$@"
164 exit $?