2024-05-28 10:10:02 -04:00
|
|
|
# shellcheck shell=bash
|
|
|
|
|
2024-06-16 12:13:07 +02:00
|
|
|
# for shellcheck
|
|
|
|
: "${test_nix_conf_dir?}" "${test_nix_conf?}"
|
|
|
|
|
|
|
|
if isTestOnNixOS; then
|
|
|
|
|
|
|
|
mkdir -p "$test_nix_conf_dir" "$TEST_HOME"
|
|
|
|
|
2024-07-08 16:07:06 -04:00
|
|
|
export NIX_USER_CONF_FILES="$test_nix_conf"
|
2024-06-16 12:13:07 +02:00
|
|
|
mkdir -p "$test_nix_conf_dir" "$TEST_HOME"
|
2024-06-20 20:26:07 +02:00
|
|
|
! test -e "$test_nix_conf"
|
2024-07-08 16:07:06 -04:00
|
|
|
cat > "$test_nix_conf" <<EOF
|
2024-06-20 14:49:53 +02:00
|
|
|
# TODO: this is not needed for all tests and prevents stable commands from be tested in isolation
|
2024-06-16 12:13:07 +02:00
|
|
|
experimental-features = nix-command flakes
|
|
|
|
flake-registry = $TEST_ROOT/registry.json
|
|
|
|
show-trace = true
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# When we're doing everything in the same store, we need to bring
|
|
|
|
# dependencies into context.
|
|
|
|
sed -i "$(dirname "${BASH_SOURCE[0]}")"/../config.nix \
|
|
|
|
-e 's^\(shell\) = "/nix/store/\([^/]*\)/\(.*\)";^\1 = builtins.appendContext "/nix/store/\2" { "/nix/store/\2".path = true; } + "/\3";^' \
|
|
|
|
-e 's^\(path\) = "/nix/store/\([^/]*\)/\(.*\)";^\1 = builtins.appendContext "/nix/store/\2" { "/nix/store/\2".path = true; } + "/\3";^' \
|
|
|
|
;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2004-05-04 12:15:30 +00:00
|
|
|
test -n "$TEST_ROOT"
|
2024-05-13 14:56:14 +02:00
|
|
|
# We would delete any daemon socket, so let's stop the daemon first.
|
|
|
|
killDaemon
|
|
|
|
# Destroy the test directory that may have persisted from previous runs
|
2024-05-14 16:23:08 +02:00
|
|
|
if [[ -e "$TEST_ROOT" ]]; then
|
|
|
|
chmod -R u+w "$TEST_ROOT"
|
|
|
|
rm -rf "$TEST_ROOT"
|
|
|
|
fi
|
2024-05-06 15:42:49 +02:00
|
|
|
mkdir -p "$TEST_ROOT"
|
|
|
|
mkdir "$TEST_HOME"
|
2004-05-04 12:15:30 +00:00
|
|
|
|
|
|
|
mkdir "$NIX_STORE_DIR"
|
2005-02-01 17:50:48 +00:00
|
|
|
mkdir "$NIX_LOCALSTATE_DIR"
|
2024-06-12 12:42:38 -04:00
|
|
|
mkdir -p "$NIX_LOG_DIR/drvs"
|
2004-05-04 12:15:30 +00:00
|
|
|
mkdir "$NIX_STATE_DIR"
|
2005-02-15 09:39:12 +00:00
|
|
|
mkdir "$NIX_CONF_DIR"
|
2004-05-04 12:15:30 +00:00
|
|
|
|
2005-02-15 09:39:12 +00:00
|
|
|
cat > "$NIX_CONF_DIR"/nix.conf <<EOF
|
2014-05-02 19:02:10 +02:00
|
|
|
build-users-group =
|
2017-08-31 14:28:25 +02:00
|
|
|
keep-derivations = false
|
2018-11-07 17:08:28 +01:00
|
|
|
sandbox = false
|
2023-10-25 11:39:18 +02:00
|
|
|
experimental-features = nix-command
|
2020-07-02 16:37:30 +02:00
|
|
|
gc-reserved-space = 0
|
2020-12-09 14:53:45 +01:00
|
|
|
substituters =
|
2020-01-28 16:34:37 +01:00
|
|
|
flake-registry = $TEST_ROOT/registry.json
|
2021-02-05 12:11:50 +01:00
|
|
|
show-trace = true
|
2018-02-13 08:16:32 -05:00
|
|
|
include nix.conf.extra
|
2021-07-26 06:54:55 +02:00
|
|
|
trusted-users = $(whoami)
|
2018-02-13 08:16:32 -05:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF
|
2010-02-24 13:12:57 +00:00
|
|
|
fsync-metadata = false
|
2023-10-25 11:39:18 +02:00
|
|
|
extra-experimental-features = flakes
|
2018-02-13 08:16:32 -05:00
|
|
|
!include nix.conf.extra.not-there
|
2005-02-15 09:39:12 +00:00
|
|
|
EOF
|
|
|
|
|
2004-05-04 12:15:30 +00:00
|
|
|
# Initialise the database.
|
2024-05-06 15:42:49 +02:00
|
|
|
# The flag itself does nothing, but running the command touches the store
|
2011-10-10 21:32:34 +00:00
|
|
|
nix-store --init
|
2024-05-06 15:42:49 +02:00
|
|
|
# Sanity check
|
2016-07-27 17:14:41 +02:00
|
|
|
test -e "$NIX_STATE_DIR"/db/db.sqlite
|
2024-06-16 12:13:07 +02:00
|
|
|
|
|
|
|
fi # !isTestOnNixOS
|