tests/functional: Enable more tests in NixOS VM

This commit is contained in:
Robert Hensing 2024-06-16 17:56:50 +02:00
parent f0abe4d8f0
commit 648302b833
38 changed files with 71 additions and 104 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -45,7 +45,10 @@ nix-build -o "$RESULT" check-refs.nix -A test7
# test10 should succeed (no disallowed references). # test10 should succeed (no disallowed references).
nix-build -o "$RESULT" check-refs.nix -A test10 nix-build -o "$RESULT" check-refs.nix -A test10
if isDaemonNewer 2.12pre20230103; then 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 if ! isDaemonNewer 2.16.0; then
enableFeatures discard-references enableFeatures discard-references
restartDaemon restartDaemon
@ -54,4 +57,6 @@ if isDaemonNewer 2.12pre20230103; then
# test11 should succeed. # test11 should succeed.
test11=$(nix-build -o "$RESULT" check-refs.nix -A test11) test11=$(nix-build -o "$RESULT" check-refs.nix -A test11)
[[ -z $(nix-store -q --references "$test11") ]] [[ -z $(nix-store -q --references "$test11") ]]
fi
fi fi

View file

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

View file

@ -82,11 +82,25 @@ clearProfiles() {
rm -rf "$profiles" 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() { clearStore() {
if isTestOnNixOS; then if isTestOnNixOS; then
die "clearStore: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. 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 fi
doClearStore
}
doClearStore() {
echo "clearing store..." echo "clearing store..."
chmod -R +w "$NIX_STORE_DIR" chmod -R +w "$NIX_STORE_DIR"
rm -rf "$NIX_STORE_DIR" rm -rf "$NIX_STORE_DIR"

View file

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

View file

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

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
drvPath=$(nix-instantiate dependencies.nix) drvPath=$(nix-instantiate dependencies.nix)
@ -67,6 +65,8 @@ drvPath2=$(nix-instantiate dependencies.nix --argstr hashInvalidator yay)
# now --valid-derivers returns both # now --valid-derivers returns both
test "$(nix-store -q --valid-derivers "$outPath" | sort)" = "$(sort <<< "$drvPath"$'\n'"$drvPath2")" 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 # check that nix-store --valid-derivers only returns existing drv
nix-store --delete "$drvPath" nix-store --delete "$drvPath"
test "$(nix-store -q --valid-derivers "$outPath")" = "$drvPath2" test "$(nix-store -q --valid-derivers "$outPath")" = "$drvPath2"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@ TODO_NixOS
enableFeatures "ca-derivations impure-derivations" enableFeatures "ca-derivations impure-derivations"
restartDaemon restartDaemon
clearStore clearStoreIfPossible
# Basic test of impure derivations: building one a second time should not use the previous result. # Basic test of impure derivations: building one a second time should not use the previous result.
printf 0 > $TEST_ROOT/counter printf 0 > $TEST_ROOT/counter

View file

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

View file

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

View file

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

View file

@ -2,13 +2,14 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
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) 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) 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)" inode1="$(stat --format=%i $outPath1/foo)"
inode2="$(stat --format=%i $outPath2/foo)" inode2="$(stat --format=%i $outPath2/foo)"
if [ "$inode1" != "$inode2" ]; then if [ "$inode1" != "$inode2" ]; then

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
outPath=$(nix-build --no-out-link -E " outPath=$(nix-build --no-out-link -E "
with import ./config.nix; with import ./config.nix;

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
nix-build --no-out-link -E ' nix-build --no-out-link -E '
with import ./config.nix; with import ./config.nix;

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
nix eval --expr 'assert 1 + 2 == 3; true' nix eval --expr 'assert 1 + 2 == 3; true'

View file

@ -2,7 +2,7 @@
source common.sh source common.sh
TODO_NixOS TODO_NixOS # NixOS doesn't provide $NIX_STATE_DIR (and shouldn't)
clearStore clearStore

View file

@ -2,7 +2,7 @@
source common.sh source common.sh
TODO_NixOS TODO_NixOS # can't enable a sandbox feature easily
enableFeatures 'recursive-nix' enableFeatures 'recursive-nix'
restartDaemon restartDaemon

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
nix-instantiate --restrict-eval --eval -E '1 + 2' nix-instantiate --restrict-eval --eval -E '1 + 2'
(! nix-instantiate --eval --restrict-eval ./restricted.nix) (! nix-instantiate --eval --restrict-eval ./restricted.nix)

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
clearCache clearCache
(( $(nix search -f search.nix '' hello | wc -l) > 0 )) (( $(nix search -f search.nix '' hello | wc -l) > 0 ))

View file

@ -4,9 +4,7 @@ source common.sh
requireDaemonNewerThan "2.6.0pre20211215" requireDaemonNewerThan "2.6.0pre20211215"
TODO_NixOS clearStoreIfPossible
clearStore
nix-build --no-out-link -E ' nix-build --no-out-link -E '
with import ./config.nix; with import ./config.nix;

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
clearCache clearCache
nix-store --generate-binary-cache-key cache1.example.org $TEST_ROOT/sk1 $TEST_ROOT/pk1 nix-store --generate-binary-cache-key cache1.example.org $TEST_ROOT/sk1 $TEST_ROOT/pk1
@ -18,6 +16,7 @@ outPath=$(nix-build dependencies.nix --no-out-link --secret-key-files "$TEST_ROO
# Verify that the path got signed. # Verify that the path got signed.
info=$(nix path-info --json $outPath) info=$(nix path-info --json $outPath)
echo $info | jq -e '.[] | .ultimate == true' echo $info | jq -e '.[] | .ultimate == true'
TODO_NixOS # looks like an actual bug? Following line fails on NixOS:
echo $info | jq -e '.[] | .signatures.[] | select(startswith("cache1.example.org"))' echo $info | jq -e '.[] | .signatures.[] | select(startswith("cache1.example.org"))'
echo $info | jq -e '.[] | .signatures.[] | select(startswith("cache2.example.org"))' echo $info | jq -e '.[] | .signatures.[] | select(startswith("cache2.example.org"))'

View file

@ -6,9 +6,7 @@ source common.sh
# tests for the older versions # tests for the older versions
requireDaemonNewerThan "2.4pre20210712" requireDaemonNewerThan "2.4pre20210712"
TODO_NixOS clearStoreIfPossible
clearStore
rm -f $TEST_ROOT/result rm -f $TEST_ROOT/result
@ -23,6 +21,8 @@ env NIX_PATH=nixpkgs=shell.nix nix-shell structured-attrs-shell.nix \
nix develop -f structured-attrs-shell.nix -c bash -c 'test "3" = "$(jq ".my.list|length" < $NIX_ATTRS_JSON_FILE)"' nix develop -f structured-attrs-shell.nix -c bash -c 'test "3" = "$(jq ".my.list|length" < $NIX_ATTRS_JSON_FILE)"'
TODO_NixOS # following line fails.
# `nix develop` is a slightly special way of dealing with environment vars, it parses # `nix develop` is a slightly special way of dealing with environment vars, it parses
# these from a shell-file exported from a derivation. This is to test especially `outputs` # these from a shell-file exported from a derivation. This is to test especially `outputs`
# (which is an associative array in thsi case) being fine. # (which is an associative array in thsi case) being fine.

View file

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

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
rm -rf $TEST_HOME rm -rf $TEST_HOME

View file

@ -2,9 +2,7 @@
source common.sh source common.sh
TODO_NixOS clearStoreIfPossible
clearStore
cp ./dependencies.nix ./dependencies.builder0.sh ./config.nix $TEST_HOME cp ./dependencies.nix ./dependencies.builder0.sh ./config.nix $TEST_HOME