aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ca-shell.nix1
-rwxr-xr-xtests/ca/build-with-garbage-path.sh2
-rw-r--r--tests/ca/repl.sh5
-rw-r--r--tests/common.sh.in5
-rw-r--r--tests/flake-local-settings.sh34
-rw-r--r--tests/flakes.sh40
-rwxr-xr-xtests/function-trace.sh2
-rw-r--r--tests/gc-non-blocking.sh33
-rw-r--r--tests/gc.sh12
-rw-r--r--tests/lang/eval-okay-sort.exp2
-rw-r--r--tests/lang/eval-okay-sort.nix14
-rw-r--r--tests/local.mk9
-rw-r--r--tests/multiple-outputs.sh3
-rw-r--r--tests/nix-shell.sh42
-rw-r--r--tests/pure-eval.sh5
-rw-r--r--tests/repair.sh2
-rw-r--r--tests/repl.sh18
-rw-r--r--tests/shell.nix4
-rw-r--r--tests/simple-failing.nix12
19 files changed, 206 insertions, 39 deletions
diff --git a/tests/ca-shell.nix b/tests/ca-shell.nix
new file mode 100644
index 000000000..ad2ab6aff
--- /dev/null
+++ b/tests/ca-shell.nix
@@ -0,0 +1 @@
+{ ... }@args: import ./shell.nix (args // { contentAddressed = true; })
diff --git a/tests/ca/build-with-garbage-path.sh b/tests/ca/build-with-garbage-path.sh
index 9aa08a899..884cd2802 100755
--- a/tests/ca/build-with-garbage-path.sh
+++ b/tests/ca/build-with-garbage-path.sh
@@ -8,7 +8,7 @@ requireDaemonNewerThan "2.4pre20210621"
# Get the output path of `rootCA`, and put some garbage instead
outPath="$(nix-build ./content-addressed.nix -A rootCA --no-out-link)"
-nix-store --delete "$outPath"
+nix-store --delete $(nix-store -q --referrers-closure "$outPath")
touch "$outPath"
# The build should correctly remove the garbage and put the expected path instead
diff --git a/tests/ca/repl.sh b/tests/ca/repl.sh
new file mode 100644
index 000000000..3808c7cb2
--- /dev/null
+++ b/tests/ca/repl.sh
@@ -0,0 +1,5 @@
+source common.sh
+
+export NIX_TESTS_CA_BY_DEFAULT=1
+
+cd .. && source repl.sh
diff --git a/tests/common.sh.in b/tests/common.sh.in
index 08f5e0a77..61abab1d7 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -36,8 +36,9 @@ 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
- export NIX_DAEMON_COMMAND="$NIX_DAEMON_PACKAGE/bin/nix-daemon"
+ DAEMON_PATH="${NIX_DAEMON_PACKAGE}/bin:$DAEMON_PATH"
fi
coreutils=@coreutils@
@@ -89,7 +90,7 @@ startDaemon() {
# Start the daemon, wait for the socket to appear. !!!
# ‘nix-daemon’ should have an option to fork into the background.
rm -f $NIX_DAEMON_SOCKET_PATH
- ${NIX_DAEMON_COMMAND:-nix daemon} &
+ PATH=$DAEMON_PATH nix daemon &
for ((i = 0; i < 30; i++)); do
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then break; fi
sleep 1
diff --git a/tests/flake-local-settings.sh b/tests/flake-local-settings.sh
new file mode 100644
index 000000000..09f6b4ca8
--- /dev/null
+++ b/tests/flake-local-settings.sh
@@ -0,0 +1,34 @@
+source common.sh
+
+clearStore
+rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
+
+cp ./simple.nix ./simple.builder.sh ./config.nix $TEST_HOME
+
+cd $TEST_HOME
+
+rm -f post-hook-ran
+cat <<EOF > echoing-post-hook.sh
+#!/bin/sh
+
+echo "ThePostHookRan" > $PWD/post-hook-ran
+EOF
+chmod +x echoing-post-hook.sh
+
+cat <<EOF > flake.nix
+{
+ nixConfig.post-build-hook = "$PWD/echoing-post-hook.sh";
+
+ outputs = a: {
+ defaultPackage.$system = import ./simple.nix;
+ };
+}
+EOF
+
+# Without --accept-flake-config, the post hook should not run.
+nix build < /dev/null
+(! [[ -f post-hook-ran ]])
+clearStore
+
+nix build --accept-flake-config
+test -f post-hook-ran || fail "The post hook should have ran"
diff --git a/tests/flakes.sh b/tests/flakes.sh
index 57d1b9aad..20966ab2a 100644
--- a/tests/flakes.sh
+++ b/tests/flakes.sh
@@ -707,10 +707,10 @@ cat > $flakeFollowsA/flake.nix <<EOF
B = {
url = "path:./flakeB";
inputs.foobar.follows = "D";
+ inputs.nonFlake.follows = "D";
};
D.url = "path:./flakeD";
- foobar.url = "path:./flakeE";
};
outputs = { ... }: {};
}
@@ -720,7 +720,9 @@ cat > $flakeFollowsB/flake.nix <<EOF
{
description = "Flake B";
inputs = {
- foobar.url = "path:./../flakeE";
+ foobar.url = "path:$flakeFollowsA/flakeE";
+ nonFlake.url = "path:$nonFlakeDir";
+ goodoo.follows = "C/goodoo";
C = {
url = "path:./flakeC";
inputs.foobar.follows = "foobar";
@@ -734,7 +736,8 @@ cat > $flakeFollowsC/flake.nix <<EOF
{
description = "Flake C";
inputs = {
- foobar.url = "path:./../../flakeE";
+ foobar.url = "path:$flakeFollowsA/flakeE";
+ goodoo.follows = "foobar";
};
outputs = { ... }: {};
}
@@ -759,12 +762,43 @@ EOF
git -C $flakeFollowsA add flake.nix flakeB/flake.nix \
flakeB/flakeC/flake.nix flakeD/flake.nix flakeE/flake.nix
+nix flake update $flakeFollowsA
+
+oldLock="$(cat "$flakeFollowsA/flake.lock")"
+
+# Ensure that locking twice doesn't change anything
+
nix flake lock $flakeFollowsA
+newLock="$(cat "$flakeFollowsA/flake.lock")"
+
+diff <(echo "$newLock") <(echo "$oldLock")
+
[[ $(jq -c .nodes.B.inputs.C $flakeFollowsA/flake.lock) = '"C"' ]]
[[ $(jq -c .nodes.B.inputs.foobar $flakeFollowsA/flake.lock) = '["D"]' ]]
[[ $(jq -c .nodes.C.inputs.foobar $flakeFollowsA/flake.lock) = '["B","foobar"]' ]]
+# Ensure removing follows from flake.nix removes them from the lockfile
+
+cat > $flakeFollowsA/flake.nix <<EOF
+{
+ description = "Flake A";
+ inputs = {
+ B = {
+ url = "path:./flakeB";
+ inputs.nonFlake.follows = "D";
+ };
+ D.url = "path:./flakeD";
+ };
+ outputs = { ... }: {};
+}
+EOF
+
+nix flake lock $flakeFollowsA
+
+[[ $(jq -c .nodes.B.inputs.foobar $flakeFollowsA/flake.lock) = '"foobar"' ]]
+jq -r -c '.nodes | keys | .[]' $flakeFollowsA/flake.lock | grep "^foobar$"
+
# Ensure a relative path is not allowed to go outside the store path
cat > $flakeFollowsA/flake.nix <<EOF
{
diff --git a/tests/function-trace.sh b/tests/function-trace.sh
index 3b7f364e3..0b7f49d82 100755
--- a/tests/function-trace.sh
+++ b/tests/function-trace.sh
@@ -60,8 +60,6 @@ function-trace exited (string):1:1 at
expect_trace '(x: x) 1 2' "
function-trace entered (string):1:1 at
function-trace exited (string):1:1 at
-function-trace entered (string):1:1 at
-function-trace exited (string):1:1 at
"
# Not a function
diff --git a/tests/gc-non-blocking.sh b/tests/gc-non-blocking.sh
new file mode 100644
index 000000000..8b21c6f1c
--- /dev/null
+++ b/tests/gc-non-blocking.sh
@@ -0,0 +1,33 @@
+# Test whether the collector is non-blocking, i.e. a build can run in
+# parallel with it.
+source common.sh
+
+needLocalStore "the GC test needs a synchronisation point"
+
+clearStore
+
+fifo=$TEST_ROOT/test.fifo
+mkfifo "$fifo"
+
+dummy=$(nix store add-path ./simple.nix)
+
+running=$TEST_ROOT/running
+touch $running
+
+(_NIX_TEST_GC_SYNC=$fifo nix-store --gc -vvvvv; rm $running) &
+pid=$!
+
+sleep 2
+
+outPath=$(nix-build -o "$TEST_ROOT/result" -E "
+ with import ./config.nix;
+ mkDerivation {
+ name = \"non-blocking\";
+ buildCommand = \"set -x; test -e $running; mkdir \$out; echo > $fifo\";
+ }")
+
+wait $pid
+
+(! test -e $running)
+(! test -e $dummy)
+test -e $outPath
diff --git a/tests/gc.sh b/tests/gc.sh
index cf0e2c32d..a736b63db 100644
--- a/tests/gc.sh
+++ b/tests/gc.sh
@@ -1,5 +1,7 @@
source common.sh
+clearStore
+
drvPath=$(nix-instantiate dependencies.nix)
outPath=$(nix-store -rvv "$drvPath")
@@ -23,6 +25,12 @@ test -e $inUse
if nix-store --delete $outPath; then false; fi
test -e $outPath
+for i in $NIX_STORE_DIR/*; do
+ if [[ $i =~ /trash ]]; then continue; fi # compat with old daemon
+ touch $i.lock
+ touch $i.chroot
+done
+
nix-collect-garbage
# Check that the root and its dependencies haven't been deleted.
@@ -38,3 +46,7 @@ nix-collect-garbage
# Check that the output has been GC'd.
if test -e $outPath/foobar; then false; fi
+
+# Check that the store is empty.
+rmdir $NIX_STORE_DIR/.links
+rmdir $NIX_STORE_DIR
diff --git a/tests/lang/eval-okay-sort.exp b/tests/lang/eval-okay-sort.exp
index 148b93516..899119e20 100644
--- a/tests/lang/eval-okay-sort.exp
+++ b/tests/lang/eval-okay-sort.exp
@@ -1 +1 @@
-[ [ 42 77 147 249 483 526 ] [ 526 483 249 147 77 42 ] [ "bar" "fnord" "foo" "xyzzy" ] [ { key = 1; value = "foo"; } { key = 1; value = "fnord"; } { key = 2; value = "bar"; } ] ]
+[ [ 42 77 147 249 483 526 ] [ 526 483 249 147 77 42 ] [ "bar" "fnord" "foo" "xyzzy" ] [ { key = 1; value = "foo"; } { key = 1; value = "fnord"; } { key = 2; value = "bar"; } ] [ [ ] [ ] [ 1 ] [ 1 4 ] [ 1 5 ] [ 1 6 ] [ 2 ] [ 2 3 ] [ 3 ] [ 3 ] ] ]
diff --git a/tests/lang/eval-okay-sort.nix b/tests/lang/eval-okay-sort.nix
index 8299c3a4a..50aa78e40 100644
--- a/tests/lang/eval-okay-sort.nix
+++ b/tests/lang/eval-okay-sort.nix
@@ -4,5 +4,17 @@ with builtins;
(sort (x: y: y < x) [ 483 249 526 147 42 77 ])
(sort lessThan [ "foo" "bar" "xyzzy" "fnord" ])
(sort (x: y: x.key < y.key)
- [ { key = 1; value = "foo"; } { key = 2; value = "bar"; } { key = 1; value = "fnord"; } ])
+ [ { key = 1; value = "foo"; } { key = 2; value = "bar"; } { key = 1; value = "fnord"; } ])
+ (sort lessThan [
+ [ 1 6 ]
+ [ ]
+ [ 2 3 ]
+ [ 3 ]
+ [ 1 5 ]
+ [ 2 ]
+ [ 1 ]
+ [ ]
+ [ 1 4 ]
+ [ 3 ]
+ ])
]
diff --git a/tests/local.mk b/tests/local.mk
index d88c3a875..936b72c2a 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -4,6 +4,7 @@ nix_tests = \
gc.sh \
ca/gc.sh \
gc-concurrent.sh \
+ gc-non-blocking.sh \
gc-auto.sh \
referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \
gc-runtime.sh check-refs.sh filter-source.sh \
@@ -45,9 +46,9 @@ nix_tests = \
recursive.sh \
describe-stores.sh \
flakes.sh \
+ flake-local-settings.sh \
build.sh \
- compute-levels.sh \
- repl.sh \
+ repl.sh ca/repl.sh \
ca/build.sh \
ca/build-with-garbage-path.sh \
ca/duplicate-realisation-in-closure.sh \
@@ -61,6 +62,10 @@ nix_tests = \
eval-store.sh
# parallel.sh
+ifeq ($(HAVE_LIBCPUID), 1)
+ nix_tests += compute-levels.sh
+endif
+
install-tests += $(foreach x, $(nix_tests), tests/$(x))
tests-environment = NIX_REMOTE= $(bash) -e
diff --git a/tests/multiple-outputs.sh b/tests/multiple-outputs.sh
index 0bca12b42..0d45ad35b 100644
--- a/tests/multiple-outputs.sh
+++ b/tests/multiple-outputs.sh
@@ -76,7 +76,10 @@ if nix-build multiple-outputs.nix -A cyclic --no-out-link; then
exit 1
fi
+# Do a GC. This should leave an empty store.
echo "collecting garbage..."
rm $TEST_ROOT/result*
nix-store --gc --keep-derivations --keep-outputs
nix-store --gc --print-roots
+rm -rf $NIX_STORE_DIR/.links
+rmdir $NIX_STORE_DIR
diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh
index a31d35887..3241d7a0f 100644
--- a/tests/nix-shell.sh
+++ b/tests/nix-shell.sh
@@ -3,59 +3,53 @@ source common.sh
clearStore
if [[ -n ${CONTENT_ADDRESSED:-} ]]; then
- nix-shell () {
- command nix-shell --arg contentAddressed true "$@"
- }
-
- nix_develop() {
- nix develop --arg contentAddressed true "$@"
- }
+ shellDotNix="$PWD/ca-shell.nix"
else
- nix_develop() {
- nix develop "$@"
- }
+ shellDotNix="$PWD/shell.nix"
fi
+export NIX_PATH=nixpkgs="$shellDotNix"
+
# Test nix-shell -A
export IMPURE_VAR=foo
export SELECTED_IMPURE_VAR=baz
-export NIX_BUILD_SHELL=$SHELL
-output=$(nix-shell --pure shell.nix -A shellDrv --run \
+
+output=$(nix-shell --pure "$shellDotNix" -A shellDrv --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $TEST_inNixShell"')
[ "$output" = " - foo - bar - true" ]
# Test --keep
-output=$(nix-shell --pure --keep SELECTED_IMPURE_VAR shell.nix -A shellDrv --run \
+output=$(nix-shell --pure --keep SELECTED_IMPURE_VAR "$shellDotNix" -A shellDrv --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $SELECTED_IMPURE_VAR"')
[ "$output" = " - foo - bar - baz" ]
# Test nix-shell on a .drv
-[[ $(nix-shell --pure $(nix-instantiate shell.nix -A shellDrv) --run \
+[[ $(nix-shell --pure $(nix-instantiate "$shellDotNix" -A shellDrv) --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $TEST_inNixShell"') = " - foo - bar - false" ]]
-[[ $(nix-shell --pure $(nix-instantiate shell.nix -A shellDrv) --run \
+[[ $(nix-shell --pure $(nix-instantiate "$shellDotNix" -A shellDrv) --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $TEST_inNixShell"') = " - foo - bar - false" ]]
# Test nix-shell on a .drv symlink
# Legacy: absolute path and .drv extension required
-nix-instantiate shell.nix -A shellDrv --add-root $TEST_ROOT/shell.drv
+nix-instantiate "$shellDotNix" -A shellDrv --add-root $TEST_ROOT/shell.drv
[[ $(nix-shell --pure $TEST_ROOT/shell.drv --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"') = " - foo - bar" ]]
# New behaviour: just needs to resolve to a derivation in the store
-nix-instantiate shell.nix -A shellDrv --add-root $TEST_ROOT/shell
+nix-instantiate "$shellDotNix" -A shellDrv --add-root $TEST_ROOT/shell
[[ $(nix-shell --pure $TEST_ROOT/shell --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"') = " - foo - bar" ]]
# Test nix-shell -p
-output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo bar --run 'echo "$(foo) $(bar)"')
+output=$(NIX_PATH=nixpkgs="$shellDotNix" nix-shell --pure -p foo bar --run 'echo "$(foo) $(bar)"')
[ "$output" = "foo bar" ]
# Test nix-shell -p --arg x y
-output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo --argstr fooContents baz --run 'echo "$(foo)"')
+output=$(NIX_PATH=nixpkgs="$shellDotNix" nix-shell --pure -p foo --argstr fooContents baz --run 'echo "$(foo)"')
[ "$output" = "baz" ]
# Test nix-shell shebang mode
@@ -91,18 +85,18 @@ output=$($TEST_ROOT/spaced\ \\\'\"shell.shebang.rb abc ruby)
[ "$output" = '-e load(ARGV.shift) -- '"$TEST_ROOT"'/spaced \'\''"shell.shebang.rb abc ruby' ]
# Test 'nix develop'.
-nix_develop -f shell.nix shellDrv -c bash -c '[[ -n $stdenv ]]'
+nix develop -f "$shellDotNix" shellDrv -c bash -c '[[ -n $stdenv ]]'
# Ensure `nix develop -c` preserves stdin
-echo foo | nix develop -f shell.nix shellDrv -c cat | grep -q foo
+echo foo | nix develop -f "$shellDotNix" shellDrv -c cat | grep -q foo
# Ensure `nix develop -c` actually executes the command if stdout isn't a terminal
-nix_develop -f shell.nix shellDrv -c echo foo |& grep -q foo
+nix develop -f "$shellDotNix" shellDrv -c echo foo |& grep -q foo
# Test 'nix print-dev-env'.
-[[ $(nix print-dev-env -f shell.nix shellDrv --json | jq -r .variables.arr1.value[2]) = '3 4' ]]
+[[ $(nix print-dev-env -f "$shellDotNix" shellDrv --json | jq -r .variables.arr1.value[2]) = '3 4' ]]
-source <(nix print-dev-env -f shell.nix shellDrv)
+source <(nix print-dev-env -f "$shellDotNix" shellDrv)
[[ -n $stdenv ]]
[[ ${arr1[2]} = "3 4" ]]
[[ ${arr2[1]} = $'\n' ]]
diff --git a/tests/pure-eval.sh b/tests/pure-eval.sh
index c994fbb98..cb4b5c5fc 100644
--- a/tests/pure-eval.sh
+++ b/tests/pure-eval.sh
@@ -6,7 +6,10 @@ nix eval --expr 'assert 1 + 2 == 3; true'
[[ $(nix eval --impure --expr 'builtins.readFile ./pure-eval.sh') =~ clearStore ]]
-(! nix eval --expr 'builtins.readFile ./pure-eval.sh')
+missingImpureErrorMsg=$(! nix eval --expr 'builtins.readFile ./pure-eval.sh' 2>&1)
+
+echo "$missingImpureErrorMsg" | grep -q -- --impure || \
+ fail "The error message should mention the “--impure” flag to unblock users"
(! nix eval --expr builtins.currentTime)
(! nix eval --expr builtins.currentSystem)
diff --git a/tests/repair.sh b/tests/repair.sh
index 12dcde8ea..1105b446b 100644
--- a/tests/repair.sh
+++ b/tests/repair.sh
@@ -30,7 +30,7 @@ nix-store --verify-path $path2
chmod u+w $path2
touch $path2/bad
-nix-store --delete $(nix-store -qd $path2)
+nix-store --delete $(nix-store -q --referrers-closure $(nix-store -qd $path2))
(! nix-store --verify --check-contents --repair)
diff --git a/tests/repl.sh b/tests/repl.sh
index 4e3059517..995db869c 100644
--- a/tests/repl.sh
+++ b/tests/repl.sh
@@ -1,15 +1,31 @@
source common.sh
replCmds="
+simple = 1
simple = import ./simple.nix
:b simple
+:log simple
+"
+
+replFailingCmds="
+failing = import ./simple-failing.nix
+:b failing
+:log failing
"
testRepl () {
local nixArgs=("$@")
- local outPath=$(nix repl "${nixArgs[@]}" <<< "$replCmds" |&
+ local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replCmds")"
+ echo "$replOutput"
+ local outPath=$(echo "$replOutput" |&
grep -o -E "$NIX_STORE_DIR/\w*-simple")
nix path-info "${nixArgs[@]}" "$outPath"
+ # simple.nix prints a PATH during build
+ echo "$replOutput" | grep -qs 'PATH=' || fail "nix repl :log doesn't output logs"
+ local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds")"
+ echo "$replOutput"
+ echo "$replOutput" | grep -qs 'This should fail' \
+ || fail "nix repl :log doesn't output logs for a failed derivation"
}
# Simple test, try building a drv
diff --git a/tests/shell.nix b/tests/shell.nix
index 4912d295a..92d94fbc2 100644
--- a/tests/shell.nix
+++ b/tests/shell.nix
@@ -74,6 +74,10 @@ let pkgs = rec {
'';
bash = shell;
+ bashInteractive = runCommand "bash" {} ''
+ mkdir -p $out/bin
+ ln -s ${shell} $out/bin/bash
+ '';
# ruby "interpreter" that outputs "$@"
ruby = runCommand "ruby" {} ''
diff --git a/tests/simple-failing.nix b/tests/simple-failing.nix
new file mode 100644
index 000000000..d176c9c51
--- /dev/null
+++ b/tests/simple-failing.nix
@@ -0,0 +1,12 @@
+with import ./config.nix;
+
+mkDerivation {
+ name = "simple-failing";
+ builder = builtins.toFile "builder.sh"
+ ''
+ echo "This should fail"
+ exit 1
+ '';
+ PATH = "";
+ goodPath = path;
+}