tests: Disable grafts by default.
[jackhill/guix/guix.git] / test-env.in
CommitLineData
69cfce50
LC
1#!/bin/sh
2
233e7676 3# GNU Guix --- Functional package management for GNU
aac783ca 4# Copyright © 2012, 2013, 2014, 2015, 2016 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.
30unset CDPATH
31
69cfce50
LC
32if [ -x "@abs_top_builddir@/guix-daemon" ]
33then
69cfce50 34 NIX_STORE_DIR="@GUIX_TEST_ROOT@/store"
8ad49499
LC
35
36 # Do that because store.scm calls `canonicalize-path' on it.
37 mkdir -p "$NIX_STORE_DIR"
38
39 # Canonicalize the store directory name in an attempt to avoid symlinks in
40 # it or its parent directories. See <http://bugs.gnu.org/17935>.
41 NIX_STORE_DIR="`cd "@GUIX_TEST_ROOT@/store"; pwd -P`"
42
69cfce50 43 NIX_LOCALSTATE_DIR="@GUIX_TEST_ROOT@/var"
aa2480e5 44 NIX_LOG_DIR="@GUIX_TEST_ROOT@/var/log/guix"
69cfce50
LC
45 NIX_DB_DIR="@GUIX_TEST_ROOT@/db"
46 NIX_ROOT_FINDER="@abs_top_builddir@/nix/scripts/list-runtime-roots"
8a9451c8
LC
47
48 # Choose a PID-dependent name to allow for parallel builds. Note
49 # that the directory name must be chosen so that the socket's file
50 # name is less than 108-char long (the size of `sun_path' in glibc).
51 # Currently, in Nix builds, we're at ~106 chars...
f65cf81a 52 NIX_STATE_DIR="@GUIX_TEST_ROOT@/var/$$"
8a9451c8 53
2178ed66
LC
54 # We can't exit when we reach the limit, because perhaps the test doesn't
55 # actually rely on the daemon, but at least warn.
56 if test "`echo -n "$NIX_STATE_DIR/daemon-socket/socket" | wc -c`" -ge 108
57 then
58 echo "warning: exceeding socket file name limit; test may fail!" >&2
59 fi
60
526382ff
LC
61 # The configuration directory, for import/export signing keys.
62 NIX_CONF_DIR="@GUIX_TEST_ROOT@/etc"
63 if [ ! -d "$NIX_CONF_DIR" ]
64 then
65 # Copy the keys so that the secret key has the right permissions (the
66 # daemon errors out when this is not the case.)
67 mkdir -p "$NIX_CONF_DIR"
68 cp "@abs_top_srcdir@/tests/signing-key.sec" \
69 "@abs_top_srcdir@/tests/signing-key.pub" \
70 "$NIX_CONF_DIR"
71 chmod 400 "$NIX_CONF_DIR/signing-key.sec"
72 fi
73
f65cf81a
LC
74 # A place to store data of the substituter.
75 GUIX_BINARY_SUBSTITUTE_URL="file://$NIX_STATE_DIR/substituter-data"
76 rm -rf "$NIX_STATE_DIR/substituter-data"
77 mkdir -p "$NIX_STATE_DIR/substituter-data"
78
e9c6c584
NK
79 # For a number of tests, we want to allow unsigned narinfos, for
80 # simplicity.
81 GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES=yes
82
eba783b7
LC
83 # Place for the substituter's cache.
84 XDG_CACHE_HOME="$NIX_STATE_DIR/cache-$$"
85
f073e523
LC
86 # For the (guix import snix) tests.
87 NIXPKGS="@NIXPKGS@"
88
aac783ca
LC
89 export NIX_IGNORE_SYMLINK_STORE NIX_STORE_DIR \
90 NIX_LOCALSTATE_DIR NIX_LOG_DIR NIX_STATE_DIR NIX_DB_DIR \
91 NIX_ROOT_FINDER GUIX_BINARY_SUBSTITUTE_URL \
92 GUIX_ALLOW_UNAUTHENTICATED_SUBSTITUTES \
f073e523 93 NIX_CONF_DIR XDG_CACHE_HOME NIXPKGS
69cfce50 94
69cfce50
LC
95 # Launch the daemon without chroot support because is may be
96 # unavailable, for instance if we're not running as root.
f65cf81a 97 "@abs_top_builddir@/pre-inst-env" \
4938b0ee
LC
98 "@abs_top_builddir@/guix-daemon" --disable-chroot \
99 --substitute-urls="$GUIX_BINARY_SUBSTITUTE_URL" &
69cfce50
LC
100
101 daemon_pid=$!
102 trap "kill $daemon_pid ; rm -rf $NIX_STATE_DIR" EXIT
103fi
104
736755e2
LC
105# Avoid issues that could stem from l10n, such as language/encoding
106# mismatches.
107unset LANGUAGE
108LC_MESSAGES=C
109export LC_MESSAGES
110
442a6ff5
LC
111# Disable grafts by default because they can cause things to be built
112# regardless of '--dry-run'.
113GUIX_BUILD_OPTIONS="--no-grafts"
114export GUIX_BUILD_OPTIONS
115
16eb115e 116# Ignore user settings.
442a6ff5 117unset GUIX_PACKAGE_PATH
8689901f 118
a7a4e6a4
LC
119storedir="@storedir@"
120prefix="@prefix@"
121datarootdir="@datarootdir@"
122datadir="@datadir@"
123localstatedir="@localstatedir@"
124export storedir prefix datarootdir datadir localstatedir
125
69cfce50
LC
126"@abs_top_builddir@/pre-inst-env" "$@"
127exit $?