2024-05-28 14:10:02 +00:00
|
|
|
# shellcheck shell=bash
|
|
|
|
|
2024-06-16 10:13:07 +00:00
|
|
|
# for shellcheck
|
|
|
|
: "${test_nix_conf_dir?}" "${test_nix_conf?}"
|
|
|
|
|
|
|
|
if isTestOnNixOS; then
|
|
|
|
|
|
|
|
mkdir -p "$test_nix_conf_dir" "$TEST_HOME"
|
|
|
|
|
|
|
|
export NIX_USER_CONF_FILES="$test_nix_conf_dir/nix.conf"
|
|
|
|
mkdir -p "$test_nix_conf_dir" "$TEST_HOME"
|
2024-06-20 18:26:07 +00:00
|
|
|
! test -e "$test_nix_conf"
|
2024-06-16 10:13:07 +00:00
|
|
|
cat > "$test_nix_conf_dir/nix.conf" <<EOF
|
2024-06-20 12:49:53 +00:00
|
|
|
# TODO: this is not needed for all tests and prevents stable commands from be tested in isolation
|
2024-06-16 10:13:07 +00: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 12:56:14 +00: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 14:23:08 +00:00
|
|
|
if [[ -e "$TEST_ROOT" ]]; then
|
|
|
|
chmod -R u+w "$TEST_ROOT"
|
|
|
|
rm -rf "$TEST_ROOT"
|
|
|
|
fi
|
2024-05-06 13:42:49 +00: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 16:42:38 +00: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 17:02:10 +00:00
|
|
|
build-users-group =
|
2017-08-31 12:28:25 +00:00
|
|
|
keep-derivations = false
|
2018-11-07 16:08:28 +00:00
|
|
|
sandbox = false
|
2023-10-25 09:39:18 +00:00
|
|
|
experimental-features = nix-command
|
2020-07-02 14:37:30 +00:00
|
|
|
gc-reserved-space = 0
|
2020-12-09 13:53:45 +00:00
|
|
|
substituters =
|
2020-01-28 15:34:37 +00:00
|
|
|
flake-registry = $TEST_ROOT/registry.json
|
2021-02-05 11:11:50 +00:00
|
|
|
show-trace = true
|
2018-02-13 13:16:32 +00:00
|
|
|
include nix.conf.extra
|
2021-07-26 04:54:55 +00:00
|
|
|
trusted-users = $(whoami)
|
2018-02-13 13:16:32 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF
|
2010-02-24 13:12:57 +00:00
|
|
|
fsync-metadata = false
|
2023-10-25 09:39:18 +00:00
|
|
|
extra-experimental-features = flakes
|
2018-02-13 13:16:32 +00: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 13:42:49 +00: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 13:42:49 +00:00
|
|
|
# Sanity check
|
2016-07-27 15:14:41 +00:00
|
|
|
test -e "$NIX_STATE_DIR"/db/db.sqlite
|
2024-06-16 10:13:07 +00:00
|
|
|
|
|
|
|
fi # !isTestOnNixOS
|