2024-05-28 17:10:02 +03:00
|
|
|
# shellcheck shell=bash
|
|
|
|
|
2024-06-16 13:13:07 +03: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-19 22:46:01 +03:00
|
|
|
(! test -e "$test_nix_conf")
|
2024-06-16 13:13:07 +03:00
|
|
|
cat > "$test_nix_conf_dir/nix.conf" <<EOF
|
|
|
|
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 15:15:30 +03:00
|
|
|
test -n "$TEST_ROOT"
|
2024-05-13 15:56:14 +03: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 17:23:08 +03:00
|
|
|
if [[ -e "$TEST_ROOT" ]]; then
|
|
|
|
chmod -R u+w "$TEST_ROOT"
|
|
|
|
rm -rf "$TEST_ROOT"
|
|
|
|
fi
|
2024-05-06 16:42:49 +03:00
|
|
|
mkdir -p "$TEST_ROOT"
|
|
|
|
mkdir "$TEST_HOME"
|
2004-05-04 15:15:30 +03:00
|
|
|
|
|
|
|
mkdir "$NIX_STORE_DIR"
|
2005-02-01 19:50:48 +02:00
|
|
|
mkdir "$NIX_LOCALSTATE_DIR"
|
2024-06-12 19:42:38 +03:00
|
|
|
mkdir -p "$NIX_LOG_DIR/drvs"
|
2004-05-04 15:15:30 +03:00
|
|
|
mkdir "$NIX_STATE_DIR"
|
2005-02-15 11:39:12 +02:00
|
|
|
mkdir "$NIX_CONF_DIR"
|
2004-05-04 15:15:30 +03:00
|
|
|
|
2005-02-15 11:39:12 +02:00
|
|
|
cat > "$NIX_CONF_DIR"/nix.conf <<EOF
|
2014-05-02 20:02:10 +03:00
|
|
|
build-users-group =
|
2017-08-31 15:28:25 +03:00
|
|
|
keep-derivations = false
|
2018-11-07 18:08:28 +02:00
|
|
|
sandbox = false
|
2023-10-25 12:39:18 +03:00
|
|
|
experimental-features = nix-command
|
2020-07-02 17:37:30 +03:00
|
|
|
gc-reserved-space = 0
|
2020-12-09 15:53:45 +02:00
|
|
|
substituters =
|
2020-01-28 17:34:37 +02:00
|
|
|
flake-registry = $TEST_ROOT/registry.json
|
2021-02-05 13:11:50 +02:00
|
|
|
show-trace = true
|
2018-02-13 15:16:32 +02:00
|
|
|
include nix.conf.extra
|
2021-07-26 07:54:55 +03:00
|
|
|
trusted-users = $(whoami)
|
2018-02-13 15:16:32 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF
|
2010-02-24 15:12:57 +02:00
|
|
|
fsync-metadata = false
|
2023-10-25 12:39:18 +03:00
|
|
|
extra-experimental-features = flakes
|
2018-02-13 15:16:32 +02:00
|
|
|
!include nix.conf.extra.not-there
|
2005-02-15 11:39:12 +02:00
|
|
|
EOF
|
|
|
|
|
2004-05-04 15:15:30 +03:00
|
|
|
# Initialise the database.
|
2024-05-06 16:42:49 +03:00
|
|
|
# The flag itself does nothing, but running the command touches the store
|
2011-10-11 00:32:34 +03:00
|
|
|
nix-store --init
|
2024-05-06 16:42:49 +03:00
|
|
|
# Sanity check
|
2016-07-27 18:14:41 +03:00
|
|
|
test -e "$NIX_STATE_DIR"/db/db.sqlite
|
2024-06-16 13:13:07 +03:00
|
|
|
|
|
|
|
fi # !isTestOnNixOS
|