1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-09 12:03:55 +02:00

Merge branch 'master' into fix-sandbox-escape

This commit is contained in:
John Ericson 2024-06-26 18:11:39 -04:00
commit 8a420162ab
274 changed files with 3295 additions and 900 deletions

View file

@ -31,7 +31,7 @@ test "$hash1" = "sha256:$hash2"
#### New style commands
clearStore
clearStoreIfPossible
(
path1=$(nix store add ./dummy)

View file

@ -2,7 +2,9 @@
source common.sh
clearStore
TODO_NixOS
clearStoreIfPossible
clearCacheCache
# Fails without remote builders

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
needLocalStore "'--no-require-sigs' cant be used with the daemon"
# We can produce drvs directly into the binary cache

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
clearCache

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
# https://github.com/NixOS/nix/issues/6572
issue_6572_independent_outputs() {

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
###################################################
# Check that --dry-run isn't confused with read-only mode
# https://github.com/NixOS/nix/issues/1795

View file

@ -23,7 +23,7 @@ EOF
chmod +x "$TEST_ROOT/post-build-hook.sh"
rm -f "$TEST_ROOT/post-hook-counter"
echo "post-build-hook = $TEST_ROOT/post-build-hook.sh" >> "$NIX_CONF_DIR/nix.conf"
echo "post-build-hook = $TEST_ROOT/post-build-hook.sh" >> "$test_nix_conf"
}
registerBuildHook

View file

@ -4,6 +4,7 @@ source common.sh
enableFeatures "daemon-trust-override"
TODO_NixOS
restartDaemon
requireSandboxSupport

View file

@ -4,6 +4,8 @@ source common.sh
enableFeatures "daemon-trust-override"
TODO_NixOS
restartDaemon
# Remote doesn't trust us

View file

@ -4,6 +4,7 @@ source common.sh
enableFeatures "daemon-trust-override"
TODO_NixOS
restartDaemon
# Remote doesn't trusts us, but this is fine because we are only

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
# Make sure that 'nix build' returns all outputs by default.
nix build -f multiple-outputs.nix --json a b --no-link | jq --exit-status '

View file

@ -2,4 +2,6 @@ source ../common.sh
enableFeatures "ca-derivations"
TODO_NixOS
restartDaemon

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
rm -rf "$TEST_ROOT/case"

View file

@ -3,7 +3,7 @@
# Test the function for lang.sh
source common.sh
source lang/framework.sh
source characterisation/framework.sh
# We are testing this, so don't want outside world to affect us.
unset _NIX_TEST_ACCEPT

View file

@ -0,0 +1,77 @@
# shellcheck shell=bash
# Golden test support
#
# Test that the output of the given test matches what is expected. If
# `_NIX_TEST_ACCEPT` is non-empty also update the expected output so
# that next time the test succeeds.
function diffAndAcceptInner() {
local -r testName=$1
local -r got="$2"
local -r expected="$3"
# Absence of expected file indicates empty output expected.
if test -e "$expected"; then
local -r expectedOrEmpty="$expected"
else
local -r expectedOrEmpty=characterisation/empty
fi
# Diff so we get a nice message
if ! diff --color=always --unified "$expectedOrEmpty" "$got"; then
echo "FAIL: evaluation result of $testName not as expected"
# shellcheck disable=SC2034
badDiff=1
fi
# Update expected if `_NIX_TEST_ACCEPT` is non-empty.
if test -n "${_NIX_TEST_ACCEPT-}"; then
cp "$got" "$expected"
# Delete empty expected files to avoid bloating the repo with
# empty files.
if ! test -s "$expected"; then
rm "$expected"
fi
fi
}
function characterisationTestExit() {
# Make sure shellcheck knows all these will be defined by the caller
: "${badDiff?} ${badExitCode?}"
if test -n "${_NIX_TEST_ACCEPT-}"; then
if (( "$badDiff" )); then
set +x
echo 'Output did mot match, but accepted output as the persisted expected output.'
echo 'That means the next time the tests are run, they should pass.'
set -x
else
set +x
echo 'NOTE: Environment variable _NIX_TEST_ACCEPT is defined,'
echo 'indicating the unexpected output should be accepted as the expected output going forward,'
echo 'but no tests had unexpected output so there was no expected output to update.'
set -x
fi
if (( "$badExitCode" )); then
exit "$badExitCode"
else
skipTest "regenerating golden masters"
fi
else
if (( "$badDiff" )); then
set +x
echo ''
echo 'You can rerun this test with:'
echo ''
echo " _NIX_TEST_ACCEPT=1 make tests/functional/${TEST_NAME}.test"
echo ''
echo 'to regenerate the files containing the expected output,'
echo 'and then view the git diff to decide whether a change is'
echo 'good/intentional or bad/unintentional.'
echo 'If the diff contains arbitrary or impure information,'
echo 'please improve the normalization that the test applies to the output.'
set -x
fi
exit $(( "$badExitCode" + "$badDiff" ))
fi
}

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
RESULT=$TEST_ROOT/result
@ -43,13 +45,18 @@ nix-build -o "$RESULT" check-refs.nix -A test7
# test10 should succeed (no disallowed references).
nix-build -o "$RESULT" check-refs.nix -A test10
if isDaemonNewer 2.12pre20230103; then
if ! isDaemonNewer 2.16.0; then
enableFeatures discard-references
restartDaemon
if ! isTestOnNixOS; then
# If we have full control over our store, we can test some more things.
if isDaemonNewer 2.12pre20230103; then
if ! isDaemonNewer 2.16.0; then
enableFeatures discard-references
restartDaemon
fi
# test11 should succeed.
test11=$(nix-build -o "$RESULT" check-refs.nix -A test11)
[[ -z $(nix-store -q --references "$test11") ]]
fi
# test11 should succeed.
test11=$(nix-build -o "$RESULT" check-refs.nix -A test11)
[[ -z $(nix-store -q --references "$test11") ]]
fi

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
RESULT=$TEST_ROOT/result

View file

@ -15,6 +15,8 @@ checkBuildTempDirRemoved ()
# written to build temp directories to verify created by this instance
checkBuildId=$(date +%s%N)
TODO_NixOS
clearStore
nix-build dependencies.nix --no-out-link
@ -79,6 +81,8 @@ grep 'may not be deterministic' $TEST_ROOT/log
[ "$status" = "104" ]
if checkBuildTempDirRemoved $TEST_ROOT/log; then false; fi
TODO_NixOS
clearStore
path=$(nix-build check.nix -A fetchurl --no-out-link)

View file

@ -39,6 +39,8 @@ EOF
cp simple.nix shell.nix simple.builder.sh config.nix "$flakeDir/"
TODO_NixOS
outPath=$(nix build --print-out-paths --no-link --sandbox-paths '/nix? /bin? /lib? /lib64? /usr?' --store "$TEST_ROOT/x" path:"$flakeDir")
[[ $outPath =~ ^/nix2/store/.*-simple$ ]]

View file

@ -1,5 +1,31 @@
# shellcheck shell=bash
# 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"
! test -e "$test_nix_conf"
cat > "$test_nix_conf_dir/nix.conf" <<EOF
# TODO: this is not needed for all tests and prevents stable commands from be tested in isolation
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
test -n "$TEST_ROOT"
# We would delete any daemon socket, so let's stop the daemon first.
killDaemon
@ -41,3 +67,5 @@ EOF
nix-store --init
# Sanity check
test -e "$NIX_STATE_DIR"/db/db.sqlite
fi # !isTestOnNixOS

View file

@ -0,0 +1,20 @@
# shellcheck shell=bash
commonDir="$(readlink -f "$(dirname "${BASH_SOURCE[0]-$0}")")"
# Since this is a generated file
# shellcheck disable=SC1091
source "$commonDir/subst-vars.sh"
# Make sure shellcheck knows this will be defined by the above generated snippet
: "${bindir?}"
export PATH="$bindir:$PATH"
if [[ -n "${NIX_CLIENT_PACKAGE:-}" ]]; then
export PATH="$NIX_CLIENT_PACKAGE/bin":$PATH
fi
DAEMON_PATH="$PATH"
if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
DAEMON_PATH="${NIX_DAEMON_PACKAGE}/bin:$DAEMON_PATH"
fi

View file

@ -1,11 +1,14 @@
# NOTE: instances of @variable@ are substituted as defined in /mk/templates.mk
export PATH=@bindir@:$PATH
if [[ -z "${COMMON_SUBST_VARS_SH_SOURCED-}" ]]; then
COMMON_SUBST_VARS_SH_SOURCED=1
bindir=@bindir@
export coreutils=@coreutils@
#lsof=@lsof@
export dot=@dot@
export SHELL="@bash@"
export PAGER=cat
export busybox="@sandbox_shell@"
@ -13,3 +16,10 @@ export version=@PACKAGE_VERSION@
export system=@system@
export BUILD_SHARED_LIBS=@BUILD_SHARED_LIBS@
if ! isTestOnNixOS; then
export SHELL="@bash@"
export PATH=@bindir@:$PATH
fi
fi

View file

@ -0,0 +1,4 @@
# shellcheck shell=bash
TEST_ROOT=$(realpath "${TMPDIR:-/tmp}/nix-test")/${TEST_NAME:-default/tests\/functional//}
export TEST_ROOT

View file

@ -6,36 +6,55 @@ if [[ -z "${COMMON_VARS_AND_FUNCTIONS_SH_SOURCED-}" ]]; then
COMMON_VARS_AND_FUNCTIONS_SH_SOURCED=1
isTestOnNixOS() {
[[ "${isTestOnNixOS:-}" == 1 ]]
}
die() {
echo "unexpected fatal error: $*" >&2
exit 1
}
set +x
commonDir="$(readlink -f "$(dirname "${BASH_SOURCE[0]-$0}")")"
source "$commonDir/subst-vars.sh"
# Make sure shellcheck knows all these will be defined by the above generated snippet
: "${PATH?} ${coreutils?} ${dot?} ${SHELL?} ${PAGER?} ${busybox?} ${version?} ${system?} ${BUILD_SHARED_LIBS?}"
: "${bindir?} ${coreutils?} ${dot?} ${SHELL?} ${PAGER?} ${busybox?} ${version?} ${system?} ${BUILD_SHARED_LIBS?}"
source "$commonDir/paths.sh"
source "$commonDir/test-root.sh"
test_nix_conf_dir=$TEST_ROOT/etc
test_nix_conf=$test_nix_conf_dir/nix.conf
export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/${TEST_NAME:-default/tests\/functional//}
export NIX_STORE_DIR
if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
# Maybe the build directory is symlinked.
export NIX_IGNORE_SYMLINK_STORE=1
NIX_STORE_DIR=$TEST_ROOT/store
fi
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_DAEMON_SOCKET_PATH=$TEST_ROOT/dSocket
unset NIX_USER_CONF_FILES
export _NIX_TEST_SHARED=$TEST_ROOT/shared
if [[ -n $NIX_STORE ]]; then
export _NIX_TEST_NO_SANDBOX=1
fi
export _NIX_IN_TEST=$TEST_ROOT/shared
export _NIX_TEST_NO_LSOF=1
export NIX_REMOTE=${NIX_REMOTE_-}
unset NIX_PATH
export TEST_HOME=$TEST_ROOT/test-home
if ! isTestOnNixOS; then
export NIX_STORE_DIR
if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
# Maybe the build directory is symlinked.
export NIX_IGNORE_SYMLINK_STORE=1
NIX_STORE_DIR=$TEST_ROOT/store
fi
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_CONF_DIR=$test_nix_conf_dir
export NIX_DAEMON_SOCKET_PATH=$TEST_ROOT/dSocket
unset NIX_USER_CONF_FILES
export _NIX_TEST_SHARED=$TEST_ROOT/shared
if [[ -n $NIX_STORE ]]; then
export _NIX_TEST_NO_SANDBOX=1
fi
export _NIX_IN_TEST=$TEST_ROOT/shared
export _NIX_TEST_NO_LSOF=1
export NIX_REMOTE=${NIX_REMOTE_-}
fi # ! isTestOnNixOS
unset NIX_PATH
export HOME=$TEST_HOME
unset XDG_STATE_HOME
unset XDG_DATA_HOME
@ -43,14 +62,6 @@ unset XDG_CONFIG_HOME
unset XDG_CONFIG_DIRS
unset XDG_CACHE_HOME
if [[ -n "${NIX_CLIENT_PACKAGE:-}" ]]; then
export PATH="$NIX_CLIENT_PACKAGE/bin":$PATH
fi
DAEMON_PATH="$PATH"
if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
DAEMON_PATH="${NIX_DAEMON_PACKAGE}/bin:$DAEMON_PATH"
fi
export IMPURE_VAR1=foo
export IMPURE_VAR2=bar
@ -65,7 +76,25 @@ clearProfiles() {
rm -rf "$profiles"
}
# Clear the store, but do not fail if we're in an environment where we can't.
# This allows the test to run in a NixOS test environment, where we use the system store.
# See doc/manual/src/contributing/testing.md / Running functional tests on NixOS.
clearStoreIfPossible() {
if isTestOnNixOS; then
echo "clearStoreIfPossible: Not clearing store, because we're on NixOS. Moving on."
else
doClearStore
fi
}
clearStore() {
if isTestOnNixOS; then
die "clearStore: not supported when testing on NixOS. If not essential, call clearStoreIfPossible. If really needed, add conditionals; e.g. if ! isTestOnNixOS; then ..."
fi
doClearStore
}
doClearStore() {
echo "clearing store..."
chmod -R +w "$NIX_STORE_DIR"
rm -rf "$NIX_STORE_DIR"
@ -84,6 +113,10 @@ clearCacheCache() {
}
startDaemon() {
if isTestOnNixOS; then
die "startDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
fi
# Dont start the daemon twice, as this would just make it loop indefinitely
if [[ "${_NIX_TEST_DAEMON_PID-}" != '' ]]; then
return
@ -110,6 +143,10 @@ startDaemon() {
}
killDaemon() {
if isTestOnNixOS; then
die "killDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
fi
# Dont fail trying to stop a non-existant daemon twice
if [[ "${_NIX_TEST_DAEMON_PID-}" == '' ]]; then
return
@ -130,6 +167,10 @@ killDaemon() {
}
restartDaemon() {
if isTestOnNixOS; then
die "restartDaemon: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
fi
[[ -z "${_NIX_TEST_DAEMON_PID:-}" ]] && return 0
killDaemon
@ -152,6 +193,12 @@ skipTest () {
exit 99
}
TODO_NixOS() {
if isTestOnNixOS; then
skipTest "This test has not been adapted for NixOS yet"
fi
}
requireDaemonNewerThan () {
isDaemonNewer "$1" || skipTest "Daemon is too old"
}
@ -169,7 +216,7 @@ requireGit() {
}
fail() {
echo "$1" >&2
echo "test failed: $*" >&2
exit 1
}
@ -234,7 +281,7 @@ buggyNeedLocalStore() {
enableFeatures() {
local features="$1"
sed -i 's/experimental-features .*/& '"$features"'/' "$NIX_CONF_DIR"/nix.conf
sed -i 's/experimental-features .*/& '"$features"'/' "$test_nix_conf_dir"/nix.conf
}
set -x

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
clearCache
outPath=$(nix-build dependencies.nix --no-out-link)

View file

@ -28,6 +28,8 @@ nix registry remove userhome-with-xdg
# Assert the .config folder hasn't been created.
[ ! -e "$HOME/.config" ]
TODO_NixOS # Very specific test setup not compatible with the NixOS test environment?
# Test that files are loaded from XDG by default
export XDG_CONFIG_HOME=$TEST_ROOT/confighome
export XDG_CONFIG_DIRS=$TEST_ROOT/dir1:$TEST_ROOT/dir2

View file

@ -10,6 +10,8 @@ if [[ -z "${NIX_DAEMON_PACKAGE-}" ]]; then
skipTest "not using the Nix daemon"
fi
TODO_NixOS
killDaemon
# Fill the db using the older Nix

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
# regression #9932
echo ":env" | expect 1 nix eval --debugger --expr '(_: throw "oh snap") 42'

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
drvPath=$(nix-instantiate dependencies.nix)
@ -65,6 +65,8 @@ drvPath2=$(nix-instantiate dependencies.nix --argstr hashInvalidator yay)
# now --valid-derivers returns both
test "$(nix-store -q --valid-derivers "$outPath" | sort)" = "$(sort <<< "$drvPath"$'\n'"$drvPath2")"
TODO_NixOS # The following --delete fails, because it seems to be still alive. This might be caused by a different test using the same path. We should try make the derivations unique, e.g. naming after tests, and adding a timestamp that's constant for that test script run.
# check that nix-store --valid-derivers only returns existing drv
nix-store --delete "$drvPath"
test "$(nix-store -q --valid-derivers "$outPath")" = "$drvPath2"

View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
source common/test-root.sh
source common/paths.sh
set -o pipefail
source characterisation/framework.sh
badDiff=0
badExitCode=0
store="$TEST_ROOT/store"
for nixFile in derivation/*.nix; do
drvPath=$(nix-instantiate --store "$store" --pure-eval --expr "$(< "$nixFile")")
testName=$(basename "$nixFile" .nix)
got="${store}${drvPath}"
expected="derivation/$testName.drv"
diffAndAcceptInner "$testName" "$got" "$expected"
done
characterisationTestExit

View file

@ -0,0 +1 @@
Derive([("out","/nix/store/1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults","","")],[],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("builder","/bin/bash"),("name","advanced-attributes-defaults"),("out","/nix/store/1qsc7svv43m4dw2prh6mvyf7cai5czji-advanced-attributes-defaults"),("system","my-system")])

View file

@ -0,0 +1,6 @@
derivation {
name = "advanced-attributes-defaults";
system = "my-system";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
}

View file

@ -0,0 +1 @@
Derive([("dev","/nix/store/8bazivnbipbyi569623skw5zm91z6kc2-advanced-attributes-structured-attrs-defaults-dev","",""),("out","/nix/store/f8f8nvnx32bxvyxyx2ff7akbvwhwd9dw-advanced-attributes-structured-attrs-defaults","","")],[],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__json","{\"builder\":\"/bin/bash\",\"name\":\"advanced-attributes-structured-attrs-defaults\",\"outputs\":[\"out\",\"dev\"],\"system\":\"my-system\"}"),("dev","/nix/store/8bazivnbipbyi569623skw5zm91z6kc2-advanced-attributes-structured-attrs-defaults-dev"),("out","/nix/store/f8f8nvnx32bxvyxyx2ff7akbvwhwd9dw-advanced-attributes-structured-attrs-defaults")])

View file

@ -0,0 +1,8 @@
derivation {
name = "advanced-attributes-structured-attrs-defaults";
system = "my-system";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
outputs = [ "out" "dev" ];
__structuredAttrs = true;
}

View file

@ -0,0 +1 @@
Derive([("bin","/nix/store/pbzb48v0ycf80jgligcp4n8z0rblna4n-advanced-attributes-structured-attrs-bin","",""),("dev","/nix/store/7xapi8jv7flcz1qq8jhw55ar8ag8hldh-advanced-attributes-structured-attrs-dev","",""),("out","/nix/store/mpq3l1l1qc2yr50q520g08kprprwv79f-advanced-attributes-structured-attrs","","")],[("/nix/store/4xm4wccqsvagz9gjksn24s7rip2fdy7v-foo.drv",["out"]),("/nix/store/plsq5jbr5nhgqwcgb2qxw7jchc09dnl8-bar.drv",["out"])],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__json","{\"__darwinAllowLocalNetworking\":true,\"__impureHostDeps\":[\"/usr/bin/ditto\"],\"__noChroot\":true,\"__sandboxProfile\":\"sandcastle\",\"allowSubstitutes\":false,\"builder\":\"/bin/bash\",\"impureEnvVars\":[\"UNICORN\"],\"name\":\"advanced-attributes-structured-attrs\",\"outputChecks\":{\"bin\":{\"disallowedReferences\":[\"/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar\"],\"disallowedRequisites\":[\"/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar\"]},\"dev\":{\"maxClosureSize\":5909,\"maxSize\":789},\"out\":{\"allowedReferences\":[\"/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo\"],\"allowedRequisites\":[\"/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo\"]}},\"outputs\":[\"out\",\"bin\",\"dev\"],\"preferLocalBuild\":true,\"requiredSystemFeatures\":[\"rainbow\",\"uid-range\"],\"system\":\"my-system\"}"),("bin","/nix/store/pbzb48v0ycf80jgligcp4n8z0rblna4n-advanced-attributes-structured-attrs-bin"),("dev","/nix/store/7xapi8jv7flcz1qq8jhw55ar8ag8hldh-advanced-attributes-structured-attrs-dev"),("out","/nix/store/mpq3l1l1qc2yr50q520g08kprprwv79f-advanced-attributes-structured-attrs")])

View file

@ -0,0 +1,45 @@
let
system = "my-system";
foo = derivation {
inherit system;
name = "foo";
builder = "/bin/bash";
args = ["-c" "echo foo > $out"];
};
bar = derivation {
inherit system;
name = "bar";
builder = "/bin/bash";
args = ["-c" "echo bar > $out"];
};
in
derivation {
inherit system;
name = "advanced-attributes-structured-attrs";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
__sandboxProfile = "sandcastle";
__noChroot = true;
__impureHostDeps = ["/usr/bin/ditto"];
impureEnvVars = ["UNICORN"];
__darwinAllowLocalNetworking = true;
outputs = [ "out" "bin" "dev" ];
__structuredAttrs = true;
outputChecks = {
out = {
allowedReferences = [foo];
allowedRequisites = [foo];
};
bin = {
disallowedReferences = [bar];
disallowedRequisites = [bar];
};
dev = {
maxSize = 789;
maxClosureSize = 5909;
};
};
requiredSystemFeatures = ["rainbow" "uid-range"];
preferLocalBuild = true;
allowSubstitutes = false;
}

View file

@ -0,0 +1 @@
Derive([("out","/nix/store/33a6fdmn8q9ih9d7npbnrxn2q56a4l8q-advanced-attributes","","")],[("/nix/store/4xm4wccqsvagz9gjksn24s7rip2fdy7v-foo.drv",["out"]),("/nix/store/plsq5jbr5nhgqwcgb2qxw7jchc09dnl8-bar.drv",["out"])],[],"my-system","/bin/bash",["-c","echo hello > $out"],[("__darwinAllowLocalNetworking","1"),("__impureHostDeps","/usr/bin/ditto"),("__noChroot","1"),("__sandboxProfile","sandcastle"),("allowSubstitutes",""),("allowedReferences","/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo"),("allowedRequisites","/nix/store/3c08bzb71z4wiag719ipjxr277653ynp-foo"),("builder","/bin/bash"),("disallowedReferences","/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar"),("disallowedRequisites","/nix/store/7rhsm8i393hm1wcsmph782awg1hi2f7x-bar"),("impureEnvVars","UNICORN"),("name","advanced-attributes"),("out","/nix/store/33a6fdmn8q9ih9d7npbnrxn2q56a4l8q-advanced-attributes"),("preferLocalBuild","1"),("requiredSystemFeatures","rainbow uid-range"),("system","my-system")])

View file

@ -0,0 +1,33 @@
let
system = "my-system";
foo = derivation {
inherit system;
name = "foo";
builder = "/bin/bash";
args = ["-c" "echo foo > $out"];
};
bar = derivation {
inherit system;
name = "bar";
builder = "/bin/bash";
args = ["-c" "echo bar > $out"];
};
in
derivation {
inherit system;
name = "advanced-attributes";
builder = "/bin/bash";
args = [ "-c" "echo hello > $out" ];
__sandboxProfile = "sandcastle";
__noChroot = true;
__impureHostDeps = ["/usr/bin/ditto"];
impureEnvVars = ["UNICORN"];
__darwinAllowLocalNetworking = true;
allowedReferences = [foo];
allowedRequisites = [foo];
disallowedReferences = [bar];
disallowedRequisites = [bar];
requiredSystemFeatures = ["rainbow" "uid-range"];
preferLocalBuild = true;
allowSubstitutes = false;
}

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
needLocalStore "--dump-db requires a local store"
clearStore

View file

@ -5,4 +5,6 @@ requireDaemonNewerThan "2.16.0pre20230419"
enableFeatures "ca-derivations dynamic-derivations"
TODO_NixOS
restartDaemon

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
# Using `--eval-store` with the daemon will eventually copy everything
# to the build store, invalidating most of the tests here
needLocalStore "“--eval-store” doesn't achieve much with the daemon"

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
testStdinHeredoc=$(nix eval -f - <<EOF
{

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
clearProfiles

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
outPath=$(nix-build dependencies.nix --no-out-link)

View file

@ -4,6 +4,8 @@ source common.sh
enableFeatures "fetch-closure"
TODO_NixOS
clearStore
clearCacheCache

View file

@ -4,7 +4,7 @@ source common.sh
requireGit
clearStore
clearStoreIfPossible
# Intentionally not in a canonical form
# See https://github.com/NixOS/nix/issues/6195

View file

@ -4,7 +4,7 @@ source common.sh
requireGit
clearStore
clearStoreIfPossible
repo="$TEST_ROOT/git"

View file

@ -6,7 +6,7 @@ set -u
requireGit
clearStore
clearStoreIfPossible
rootRepo=$TEST_ROOT/gitSubmodulesRoot
subRepo=$TEST_ROOT/gitSubmodulesSub

View file

@ -7,7 +7,7 @@ requireGit
enableFeatures "verified-fetches"
clearStore
clearStoreIfPossible
repo="$TEST_ROOT/git"

View file

@ -4,6 +4,8 @@ source common.sh
[[ $(type -p hg) ]] || skipTest "Mercurial not installed"
TODO_NixOS
clearStore
# Intentionally not in a canonical form

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
cd "$TEST_ROOT"

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
# Test fetching a flat file.

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
path=$(nix-store -q $(nix-instantiate fixed.nix -A good.0))

View file

@ -28,6 +28,7 @@ EOF
# Without --accept-flake-config, the post hook should not run.
nix build < /dev/null
(! [[ -f post-hook-ran ]])
TODO_NixOS
clearStore
nix build --accept-flake-config

View file

@ -2,6 +2,8 @@
source ../common.sh
TODO_NixOS
clearStore
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local

View file

@ -15,6 +15,8 @@ source common.sh
requireGit
TODO_NixOS
clearStore
# Submodules can't be fetched locally by default.

View file

@ -2,6 +2,8 @@
source ./common.sh
TODO_NixOS
requireGit
clearStore

View file

@ -2,6 +2,8 @@
source ../common.sh
TODO_NixOS
clearStore
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
cp ../shell-hello.nix ../config.nix $TEST_HOME

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
writeSimpleFlake "$TEST_HOME"
cd "$TEST_HOME"

View file

@ -2,7 +2,9 @@
source common.sh
clearStore
TODO_NixOS # Provide a `shell` variable. Try not to `export` it, perhaps.
clearStoreIfPossible
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
cp ./simple.nix ./simple.builder.sh ./fmt.simple.sh ./config.nix $TEST_HOME
@ -31,5 +33,3 @@ EOF
nix fmt ./file ./folder | grep 'Formatting: ./file ./folder'
nix flake check
nix flake show | grep -P "package 'formatter'"
clearStore

View file

@ -4,6 +4,8 @@ source common.sh
needLocalStore "“min-free” and “max-free” are daemon options"
TODO_NixOS
clearStore
garbage1=$(nix store add-path --name garbage1 ./nar-access.sh)

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
lockFifo1=$TEST_ROOT/test1.fifo

View file

@ -4,6 +4,8 @@
# parallel with it.
source common.sh
TODO_NixOS
needLocalStore "the GC test needs a synchronisation point"
clearStore

View file

@ -11,6 +11,8 @@ esac
set -m # enable job control, needed for kill
TODO_NixOS
profiles="$NIX_STATE_DIR"/profiles
rm -rf "$profiles"

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
drvPath=$(nix-instantiate dependencies.nix)

View file

@ -1,5 +1,7 @@
source ../common.sh
TODO_NixOS # Need to enable git hashing feature and make sure test is ok for store we don't clear
clearStore
clearCache

View file

@ -2,8 +2,6 @@
source common.sh
clearStore
# test help output
nix-build --help

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
if nix-instantiate --readonly-mode ./import-derivation.nix; then
echo "read-only evaluation of an imported derivation unexpectedly failed"

View file

@ -4,10 +4,12 @@ source common.sh
requireDaemonNewerThan "2.8pre20220311"
TODO_NixOS
enableFeatures "ca-derivations impure-derivations"
restartDaemon
clearStore
clearStoreIfPossible
# Basic test of impure derivations: building one a second time should not use the previous result.
printf 0 > $TEST_ROOT/counter

View file

@ -5,6 +5,8 @@ source common.sh
# Needs the config option 'impure-env' to work
requireDaemonNewerThan "2.19.0"
TODO_NixOS
enableFeatures "configurable-impure-env"
restartDaemon
@ -20,13 +22,13 @@ startDaemon
varTest env_name value --impure-env env_name=value
echo 'impure-env = set_in_config=config_value' >> "$NIX_CONF_DIR/nix.conf"
echo 'impure-env = set_in_config=config_value' >> "$test_nix_conf"
set_in_config=daemon_value restartDaemon
varTest set_in_config config_value
varTest set_in_config client_value --impure-env set_in_config=client_value
sed -i -e '/^trusted-users =/d' "$NIX_CONF_DIR/nix.conf"
sed -i -e '/^trusted-users =/d' "$test_nix_conf"
env_name=daemon_value restartDaemon

View file

@ -4,7 +4,7 @@ source common.sh
set -o pipefail
source lang/framework.sh
source characterisation/framework.sh
# specialize function a bit
function diffAndAccept() {
@ -138,32 +138,4 @@ for i in lang/eval-okay-*.nix; do
fi
done
if test -n "${_NIX_TEST_ACCEPT-}"; then
if (( "$badDiff" )); then
echo 'Output did mot match, but accepted output as the persisted expected output.'
echo 'That means the next time the tests are run, they should pass.'
else
echo 'NOTE: Environment variable _NIX_TEST_ACCEPT is defined,'
echo 'indicating the unexpected output should be accepted as the expected output going forward,'
echo 'but no tests had unexpected output so there was no expected output to update.'
fi
if (( "$badExitCode" )); then
exit "$badExitCode"
else
skipTest "regenerating golden masters"
fi
else
if (( "$badDiff" )); then
echo ''
echo 'You can rerun this test with:'
echo ''
echo ' _NIX_TEST_ACCEPT=1 make tests/functional/lang.sh.test'
echo ''
echo 'to regenerate the files containing the expected output,'
echo 'and then view the git diff to decide whether a change is'
echo 'good/intentional or bad/unintentional.'
echo 'If the diff contains arbitrary or impure information,'
echo 'please improve the normalization that the test applies to the output.'
fi
exit $(( "$badExitCode" + "$badDiff" ))
fi
characterisationTestExit

View file

@ -0,0 +1,26 @@
error:
… while evaluating the attribute 'outPath'
at <nix/derivation-internal.nix>:19:9:
18| value = commonAttrs // {
19| outPath = builtins.getAttr outputName strict;
| ^
20| drvPath = strict.drvPath;
… while calling the 'getAttr' builtin
at <nix/derivation-internal.nix>:19:19:
18| value = commonAttrs // {
19| outPath = builtins.getAttr outputName strict;
| ^
20| drvPath = strict.drvPath;
… while calling the 'derivationStrict' builtin
at <nix/derivation-internal.nix>:9:12:
8|
9| strict = derivationStrict drvAttrs;
| ^
10|
… while evaluating derivation '~jiggle~'
whose name attribute is located at /pwd/lang/eval-fail-derivation-name.nix:2:3
error: invalid derivation name: name '~jiggle~' contains illegal character '~'. Please pass a different 'name'.

View file

@ -0,0 +1,5 @@
derivation {
name = "~jiggle~";
system = "some-system";
builder = "/dontcare";
}

View file

@ -0,0 +1,8 @@
error:
… while calling the 'fetchurl' builtin
at /pwd/lang/eval-fail-fetchurl-baseName-attrs-name.nix:1:1:
1| builtins.fetchurl { url = "https://example.com/foo.tar.gz"; name = "~wobble~"; }
| ^
2|
error: invalid store path name when fetching URL 'https://example.com/foo.tar.gz': name '~wobble~' contains illegal character '~'. Please change the value for the 'name' attribute passed to 'fetchurl', so that it can create a valid store path.

View file

@ -0,0 +1 @@
builtins.fetchurl { url = "https://example.com/foo.tar.gz"; name = "~wobble~"; }

View file

@ -0,0 +1,8 @@
error:
… while calling the 'fetchurl' builtin
at /pwd/lang/eval-fail-fetchurl-baseName-attrs.nix:1:1:
1| builtins.fetchurl { url = "https://example.com/~wiggle~"; }
| ^
2|
error: invalid store path name when fetching URL 'https://example.com/~wiggle~': name '~wiggle~' contains illegal character '~'. Please add a valid 'name' attribute to the argument for 'fetchurl', so that it can create a valid store path.

View file

@ -0,0 +1 @@
builtins.fetchurl { url = "https://example.com/~wiggle~"; }

View file

@ -0,0 +1,8 @@
error:
… while calling the 'fetchurl' builtin
at /pwd/lang/eval-fail-fetchurl-baseName.nix:1:1:
1| builtins.fetchurl "https://example.com/~wiggle~"
| ^
2|
error: invalid store path name when fetching URL 'https://example.com/~wiggle~': name '~wiggle~' contains illegal character '~'. Please pass an attribute set with 'url' and 'name' attributes to 'fetchurl', so that it can create a valid store path.

View file

@ -0,0 +1 @@
builtins.fetchurl "https://example.com/~wiggle~"

View file

@ -0,0 +1,6 @@
warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'allowedReferences'; use 'outputChecks.<output>.allowedReferences' instead
warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'allowedRequisites'; use 'outputChecks.<output>.allowedRequisites' instead
warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'disallowedReferences'; use 'outputChecks.<output>.disallowedReferences' instead
warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'disallowedRequisites'; use 'outputChecks.<output>.disallowedRequisites' instead
warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'maxClosureSize'; use 'outputChecks.<output>.maxClosureSize' instead
warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'maxSize'; use 'outputChecks.<output>.maxSize' instead

View file

@ -0,0 +1 @@
"/nix/store/mzgwvrjjir216ra58mwwizi8wj6y9ddr-eval-okay-derivation-legacy"

View file

@ -0,0 +1,12 @@
(builtins.derivationStrict {
name = "eval-okay-derivation-legacy";
system = "x86_64-linux";
builder = "/dontcare";
__structuredAttrs = true;
allowedReferences = [ ];
disallowedReferences = [ ];
allowedRequisites = [ ];
disallowedRequisites = [ ];
maxSize = 1234;
maxClosureSize = 12345;
}).out

View file

@ -1,33 +0,0 @@
# Golden test support
#
# Test that the output of the given test matches what is expected. If
# `_NIX_TEST_ACCEPT` is non-empty also update the expected output so
# that next time the test succeeds.
function diffAndAcceptInner() {
local -r testName=$1
local -r got="$2"
local -r expected="$3"
# Absence of expected file indicates empty output expected.
if test -e "$expected"; then
local -r expectedOrEmpty="$expected"
else
local -r expectedOrEmpty=lang/empty.exp
fi
# Diff so we get a nice message
if ! diff --color=always --unified "$expectedOrEmpty" "$got"; then
echo "FAIL: evaluation result of $testName not as expected"
badDiff=1
fi
# Update expected if `_NIX_TEST_ACCEPT` is non-empty.
if test -n "${_NIX_TEST_ACCEPT-}"; then
cp "$got" "$expected"
# Delete empty expected files to avoid bloating the repo with
# empty files.
if ! test -s "$expected"; then
rm "$expected"
fi
fi
}

View file

@ -4,6 +4,8 @@ source common.sh
needLocalStore "the sandbox only runs on the builder side, so it makes no sense to test it with the daemon"
TODO_NixOS
clearStore
requireSandboxSupport

View file

@ -15,6 +15,8 @@ declare -a storesBad=(
"$storeBadRoot" "$storeBadLower" "$storeBadUpper"
)
TODO_NixOS
for i in "${storesBad[@]}"; do
echo $i
unshare --mount --map-root-user bash <<EOF

View file

@ -1,5 +1,7 @@
source ../common/vars-and-functions.sh
TODO_NixOS
# The new Linux mount interface does not seem to support remounting
# OverlayFS mount points.
#
@ -31,7 +33,7 @@ requireEnvironment () {
}
addConfig () {
echo "$1" >> "$NIX_CONF_DIR/nix.conf"
echo "$1" >> "$test_nix_conf"
}
setupConfig () {

View file

@ -23,7 +23,7 @@ nix_tests = \
remote-store.sh \
legacy-ssh-store.sh \
lang.sh \
lang-test-infra.sh \
characterisation-test-infra.sh \
experimental-features.sh \
fetchMercurial.sh \
gc-auto.sh \
@ -106,6 +106,7 @@ nix_tests = \
eval-store.sh \
why-depends.sh \
derivation-json.sh \
derivation-advanced-attributes.sh \
import-derivation.sh \
nix_path.sh \
case-hack.sh \

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
path=$(nix-build dependencies.nix --no-out-link)

View file

@ -2,7 +2,9 @@
source common.sh
clearStore
TODO_NixOS
clearStoreIfPossible
rm -f $TEST_ROOT/result*

View file

@ -27,6 +27,8 @@ diff -u baz.cat-nar $storePath/foo/baz
nix store cat $storePath/foo/baz > baz.cat-nar
diff -u baz.cat-nar $storePath/foo/baz
TODO_NixOS
# Check that 'nix store cat' fails on invalid store paths.
invalidPath="$(dirname $storePath)/99999999999999999999999999999999-foo"
cp -r $storePath $invalidPath

View file

@ -4,6 +4,8 @@ source common.sh
# This test is run by `tests/functional/nested-sandboxing/runner.nix` in an extra layer of sandboxing.
[[ -d /nix/store ]] || skipTest "running this test without Nix's deps being drawn from /nix/store is not yet supported"
TODO_NixOS
requireSandboxSupport
source ./nested-sandboxing/command.sh

View file

@ -2,7 +2,9 @@
source common.sh
clearStore
TODO_NixOS
clearStoreIfPossible
outPath=$(nix-build dependencies.nix -o $TEST_ROOT/result)
test "$(cat $TEST_ROOT/result/foobar)" = FOOBAR

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
## Test `nix-collect-garbage -d`

View file

@ -2,6 +2,8 @@ proto=$1
shift
(( $# == 0 ))
TODO_NixOS
clearStore
clearCache

View file

@ -4,6 +4,8 @@ source common.sh
source nix-copy-ssh-common.sh "ssh-ng"
TODO_NixOS
clearStore
clearRemoteStore

View file

@ -2,6 +2,8 @@
source common.sh
TODO_NixOS
clearStore
clearProfiles

View file

@ -2,7 +2,7 @@
source common.sh
clearStore
clearStoreIfPossible
if [[ -n ${CONTENT_ADDRESSED:-} ]]; then
shellDotNix="$PWD/ca-shell.nix"

View file

@ -2,11 +2,14 @@
source common.sh
clearStore
clearStoreIfPossible
outPath1=$(echo 'with import ./config.nix; mkDerivation { name = "foo1"; builder = builtins.toFile "builder" "mkdir $out; echo hello > $out/foo"; }' | nix-build - --no-out-link --auto-optimise-store)
outPath2=$(echo 'with import ./config.nix; mkDerivation { name = "foo2"; builder = builtins.toFile "builder" "mkdir $out; echo hello > $out/foo"; }' | nix-build - --no-out-link --auto-optimise-store)
TODO_NixOS # ignoring the client-specified setting 'auto-optimise-store', because it is a restricted setting and you are not a trusted user
# TODO: only continue when trusted user or root
inode1="$(stat --format=%i $outPath1/foo)"
inode2="$(stat --format=%i $outPath2/foo)"
if [ "$inode1" != "$inode2" ]; then

View file

@ -3,6 +3,7 @@
source common.sh
testNormalization () {
TODO_NixOS
clearStore
outPath=$(nix-build ./simple.nix --no-out-link)
test "$(stat -c %Y $outPath)" -eq 1

Some files were not shown because too many files have changed in this diff Show more