Commit | Line | Data |
---|---|---|
69cfce50 LC |
1 | #!/bin/sh |
2 | ||
233e7676 | 3 | # GNU Guix --- Functional package management for GNU |
a87d66f3 | 4 | # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
69cfce50 | 5 | # |
233e7676 | 6 | # This file is part of GNU Guix. |
69cfce50 | 7 | # |
233e7676 | 8 | # GNU Guix is free software; you can redistribute it and/or modify it |
69cfce50 LC |
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. | |
12 | # | |
233e7676 | 13 | # GNU Guix is distributed in the hope that it will be useful, but |
69cfce50 LC |
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. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
233e7676 | 19 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
69cfce50 LC |
20 | |
21 | # Usage: ./test-env COMMAND ARG... | |
22 | # | |
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. | |
26 | ||
d8805b95 LC |
27 | |
28 | # Make sure 'cd' behaves deterministically and doesn't write anything to | |
29 | # stdout. | |
30 | unset CDPATH | |
31 | ||
4d9ed584 LC |
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 | |
39 | ;; | |
40 | esac | |
41 | ||
69cfce50 LC |
42 | if [ -x "@abs_top_builddir@/guix-daemon" ] |
43 | then | |
69cfce50 | 44 | NIX_STORE_DIR="@GUIX_TEST_ROOT@/store" |
8ad49499 LC |
45 | |
46 | # Do that because store.scm calls `canonicalize-path' on it. | |
47 | mkdir -p "$NIX_STORE_DIR" | |
48 | ||
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`" | |
52 | ||
69cfce50 | 53 | NIX_LOCALSTATE_DIR="@GUIX_TEST_ROOT@/var" |
a87d66f3 LC |
54 | GUIX_LOG_DIRECTORY="@GUIX_TEST_ROOT@/var/log/guix" |
55 | GUIX_DATABASE_DIRECTORY="@GUIX_TEST_ROOT@/db" | |
8a9451c8 LC |
56 | |
57 | # Choose a PID-dependent name to allow for parallel builds. Note | |
58 | # that the directory name must be chosen so that the socket's file | |
59 | # name is less than 108-char long (the size of `sun_path' in glibc). | |
60 | # Currently, in Nix builds, we're at ~106 chars... | |
a87d66f3 | 61 | GUIX_STATE_DIRECTORY="@GUIX_TEST_ROOT@/var/$$" |
8a9451c8 | 62 | |
2178ed66 LC |
63 | # We can't exit when we reach the limit, because perhaps the test doesn't |
64 | # actually rely on the daemon, but at least warn. | |
a87d66f3 | 65 | if test "`echo -n "$GUIX_STATE_DIRECTORY/daemon-socket/socket" | wc -c`" -ge 108 |
2178ed66 LC |
66 | then |
67 | echo "warning: exceeding socket file name limit; test may fail!" >&2 | |
68 | fi | |
69 | ||
526382ff | 70 | # The configuration directory, for import/export signing keys. |
9dd674db DC |
71 | GUIX_CONFIGURATION_DIRECTORY="@GUIX_TEST_ROOT@/etc" |
72 | if [ ! -d "$GUIX_CONFIGURATION_DIRECTORY" ] | |
526382ff LC |
73 | then |
74 | # Copy the keys so that the secret key has the right permissions (the | |
75 | # daemon errors out when this is not the case.) | |
9dd674db | 76 | mkdir -p "$GUIX_CONFIGURATION_DIRECTORY" |
526382ff LC |
77 | cp "@abs_top_srcdir@/tests/signing-key.sec" \ |
78 | "@abs_top_srcdir@/tests/signing-key.pub" \ | |
9dd674db DC |
79 | "$GUIX_CONFIGURATION_DIRECTORY" |
80 | chmod 400 "$GUIX_CONFIGURATION_DIRECTORY/signing-key.sec" | |
526382ff LC |
81 | fi |
82 | ||
f65cf81a | 83 | # A place to store data of the substituter. |
a87d66f3 LC |
84 | GUIX_BINARY_SUBSTITUTE_URL="file://$GUIX_STATE_DIRECTORY/substituter-data" |
85 | rm -rf "$GUIX_STATE_DIRECTORY/substituter-data" | |
86 | mkdir -p "$GUIX_STATE_DIRECTORY/substituter-data" | |
f65cf81a | 87 | |
e9c6c584 NK |
88 | # For a number of tests, we want to allow unsigned narinfos, for |
89 | # simplicity. | |
90 | GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes | |
91 | ||
eba783b7 | 92 | # Place for the substituter's cache. |
a87d66f3 | 93 | XDG_CACHE_HOME="$GUIX_STATE_DIRECTORY/cache-$$" |
eba783b7 | 94 | |
f073e523 LC |
95 | # For the (guix import snix) tests. |
96 | NIXPKGS="@NIXPKGS@" | |
97 | ||
aac783ca | 98 | export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \ |
a87d66f3 | 99 | NIX_LOCALSTATE_DIR GUIX_LOG_DIRECTORY GUIX_STATE_DIRECTORY GUIX_DATABASE_DIRECTORY \ |
47e99e62 | 100 | GUIX_BINARY_SUBSTITUTE_URL \ |
aac783ca | 101 | GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \ |
9dd674db | 102 | GUIX_CONFIGURATION_DIRECTORY XDG_CACHE_HOME NIXPKGS |
69cfce50 | 103 | |
69cfce50 LC |
104 | # Launch the daemon without chroot support because is may be |
105 | # unavailable, for instance if we're not running as root. | |
f65cf81a | 106 | "@abs_top_builddir@/pre-inst-env" \ |
4938b0ee LC |
107 | "@abs_top_builddir@/guix-daemon" --disable-chroot \ |
108 | --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" & | |
69cfce50 LC |
109 | |
110 | daemon_pid=$! | |
a87d66f3 | 111 | trap "kill $daemon_pid ; rm -rf $GUIX_STATE_DIRECTORY" EXIT |
4f024ef3 LC |
112 | |
113 | # The test suite expects the 'guile-bootstrap' package to be available. | |
114 | # Normally the Guile bootstrap tarball is downloaded by a fixed-output | |
115 | # derivation but when network access is missing we allow users to drop | |
116 | # the tarball in 'gnu/packages/bootstrap/SYSTEM' and "intern" it here. | |
117 | bootstrap_directory="@abs_top_builddir@/gnu/packages/bootstrap/@guix_system@" | |
118 | if [ -d "$bootstrap_directory" ] | |
119 | then | |
479c0e3f LC |
120 | # Make sure 'guix-daemon' is listening before invoking 'guix |
121 | # download'. | |
122 | "@abs_top_builddir@/pre-inst-env" "@GUILE@" -c \ | |
123 | '(use-modules (guix)) | |
124 | (let loop ((i 10)) | |
125 | (catch #t | |
126 | (lambda () (open-connection)) | |
127 | (lambda (key . args) | |
128 | (if (zero? i) | |
129 | (apply throw key args) | |
130 | (begin (usleep 500000) (loop (- i 1)))))))' | |
131 | ||
4f024ef3 LC |
132 | for file in "$bootstrap_directory"/guile-* |
133 | do | |
9e7b87dd | 134 | [ -f "$file" ] && \ |
4f024ef3 LC |
135 | "@abs_top_builddir@/pre-inst-env" \ |
136 | guix download "file://$file" > /dev/null | |
137 | done | |
138 | fi | |
69cfce50 LC |
139 | fi |
140 | ||
736755e2 LC |
141 | # Avoid issues that could stem from l10n, such as language/encoding |
142 | # mismatches. | |
143 | unset LANGUAGE | |
144 | LC_MESSAGES=C | |
145 | export LC_MESSAGES | |
146 | ||
442a6ff5 LC |
147 | # Disable grafts by default because they can cause things to be built |
148 | # regardless of '--dry-run'. | |
149 | GUIX_BUILD_OPTIONS="--no-grafts" | |
150 | export GUIX_BUILD_OPTIONS | |
151 | ||
16eb115e | 152 | # Ignore user settings. |
442a6ff5 | 153 | unset GUIX_PACKAGE_PATH |
8689901f | 154 | |
a7a4e6a4 LC |
155 | storedir="@storedir@" |
156 | prefix="@prefix@" | |
157 | datarootdir="@datarootdir@" | |
158 | datadir="@datadir@" | |
159 | localstatedir="@localstatedir@" | |
160 | export storedir prefix datarootdir datadir localstatedir | |
161 | ||
69cfce50 LC |
162 | "@abs_top_builddir@/pre-inst-env" "$@" |
163 | exit $? |