aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/add.sh2
-rw-r--r--tests/binary-cache.sh2
-rw-r--r--tests/build-remote-content-addressed-floating.sh2
-rw-r--r--tests/build-remote.sh11
-rw-r--r--tests/build.sh6
-rwxr-xr-xtests/ca/build-with-garbage-path.sh21
-rw-r--r--tests/ca/common.sh4
-rwxr-xr-xtests/ca/concurrent-builds.sh18
-rw-r--r--tests/ca/duplicate-realisation-in-closure.sh28
-rwxr-xr-xtests/ca/gc.sh10
-rwxr-xr-xtests/ca/nix-shell.sh10
-rw-r--r--tests/ca/nondeterministic.nix35
-rwxr-xr-xtests/ca/post-hook.sh13
-rw-r--r--tests/ca/racy.nix15
-rwxr-xr-xtests/ca/recursive.sh13
-rw-r--r--tests/ca/substitute.sh10
-rw-r--r--tests/check.nix2
-rw-r--r--tests/check.sh8
-rw-r--r--tests/common.sh.in61
-rw-r--r--tests/config.nix.in11
-rw-r--r--tests/db-migration.sh5
-rw-r--r--tests/dummy1
-rw-r--r--tests/dump-db.sh2
-rw-r--r--tests/eval-store.sh28
-rw-r--r--tests/fetchGit.sh4
-rw-r--r--tests/fetchMercurial.sh5
-rw-r--r--tests/fetchurl.sh14
-rw-r--r--tests/fixed.sh3
-rw-r--r--tests/flakes.sh189
-rw-r--r--tests/gc-auto.sh2
-rw-r--r--tests/gc.sh2
-rw-r--r--tests/init.sh3
-rw-r--r--tests/lang/eval-fail-nonexist-path.nix (renamed from tests/lang/eval-fail-antiquoted-path.nix)0
-rw-r--r--tests/lang/eval-okay-path-antiquotation.nix12
-rw-r--r--tests/linux-sandbox.sh2
-rw-r--r--tests/local.mk11
-rw-r--r--tests/multiple-outputs.sh2
-rw-r--r--tests/nix-shell.sh36
-rw-r--r--tests/optimise-store.sh3
-rw-r--r--tests/post-hook.sh5
-rw-r--r--tests/recursive.sh17
-rw-r--r--tests/referrers.sh2
-rw-r--r--tests/repair.sh2
-rw-r--r--tests/repl.sh18
-rw-r--r--tests/shell.nix34
-rw-r--r--tests/structured-attrs-shell.nix21
-rw-r--r--tests/structured-attrs.nix2
-rw-r--r--tests/structured-attrs.sh13
-rw-r--r--tests/tarball.sh5
-rw-r--r--tests/timeout.sh2
50 files changed, 601 insertions, 126 deletions
diff --git a/tests/add.sh b/tests/add.sh
index e26e05843..5c3eed793 100644
--- a/tests/add.sh
+++ b/tests/add.sh
@@ -9,7 +9,7 @@ echo $path2
if test "$path1" != "$path2"; then
echo "nix-store --add and --add-fixed mismatch"
exit 1
-fi
+fi
path3=$(nix-store --add-fixed sha256 ./dummy)
echo $path3
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index 6697ce236..d7bc1507b 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -1,5 +1,7 @@
source common.sh
+needLocalStore "“--no-require-sigs” can’t be used with the daemon"
+
# We can produce drvs directly into the binary cache
clearStore
clearCacheCache
diff --git a/tests/build-remote-content-addressed-floating.sh b/tests/build-remote-content-addressed-floating.sh
index 7447d92bd..13ef47d2d 100644
--- a/tests/build-remote-content-addressed-floating.sh
+++ b/tests/build-remote-content-addressed-floating.sh
@@ -4,4 +4,6 @@ file=build-hook-ca-floating.nix
sed -i 's/experimental-features .*/& ca-derivations/' "$NIX_CONF_DIR"/nix.conf
+CONTENT_ADDRESSED=true
+
source build-remote.sh
diff --git a/tests/build-remote.sh b/tests/build-remote.sh
index 70f82e939..27d85a83d 100644
--- a/tests/build-remote.sh
+++ b/tests/build-remote.sh
@@ -6,12 +6,17 @@ unset NIX_STATE_DIR
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
+EXTRA_SYSTEM_FEATURES=()
+if [[ -n "$CONTENT_ADDRESSED" ]]; then
+ EXTRA_SYSTEM_FEATURES=("ca-derivations")
+fi
+
builders=(
# system-features will automatically be added to the outer URL, but not inner
# remote-store URL.
- "ssh://localhost?remote-store=$TEST_ROOT/machine1?system-features=foo - - 1 1 foo"
- "$TEST_ROOT/machine2 - - 1 1 bar"
- "ssh-ng://localhost?remote-store=$TEST_ROOT/machine3?system-features=baz - - 1 1 baz"
+ "ssh://localhost?remote-store=$TEST_ROOT/machine1?system-features=$(join_by "%20" foo ${EXTRA_SYSTEM_FEATURES[@]}) - - 1 1 $(join_by "," foo ${EXTRA_SYSTEM_FEATURES[@]})"
+ "$TEST_ROOT/machine2 - - 1 1 $(join_by "," bar ${EXTRA_SYSTEM_FEATURES[@]})"
+ "ssh-ng://localhost?remote-store=$TEST_ROOT/machine3?system-features=$(join_by "%20" baz ${EXTRA_SYSTEM_FEATURES[@]}) - - 1 1 $(join_by "," baz ${EXTRA_SYSTEM_FEATURES[@]})"
)
chmod -R +w $TEST_ROOT/machine* || true
diff --git a/tests/build.sh b/tests/build.sh
index ce9d6602c..c77f620f7 100644
--- a/tests/build.sh
+++ b/tests/build.sh
@@ -1,7 +1,7 @@
source common.sh
expectedJSONRegex='\[\{"drvPath":".*multiple-outputs-a.drv","outputs":\{"first":".*multiple-outputs-a-first","second":".*multiple-outputs-a-second"}},\{"drvPath":".*multiple-outputs-b.drv","outputs":\{"out":".*multiple-outputs-b"}}]'
-nix build -f multiple-outputs.nix --json a.all b.all | jq --exit-status '
+nix build -f multiple-outputs.nix --json a.all b.all --no-link | jq --exit-status '
(.[0] |
(.drvPath | match(".*multiple-outputs-a.drv")) and
(.outputs.first | match(".*multiple-outputs-a-first")) and
@@ -10,10 +10,10 @@ nix build -f multiple-outputs.nix --json a.all b.all | jq --exit-status '
(.drvPath | match(".*multiple-outputs-b.drv")) and
(.outputs.out | match(".*multiple-outputs-b")))
'
-
testNormalization () {
clearStore
- outPath=$(nix-build ./simple.nix)
+ outPath=$(nix-build ./simple.nix --no-out-link)
test "$(stat -c %Y $outPath)" -eq 1
}
+
testNormalization
diff --git a/tests/ca/build-with-garbage-path.sh b/tests/ca/build-with-garbage-path.sh
new file mode 100755
index 000000000..9aa08a899
--- /dev/null
+++ b/tests/ca/build-with-garbage-path.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+# Regression test for https://github.com/NixOS/nix/issues/4858
+
+source common.sh
+
+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"
+touch "$outPath"
+
+# The build should correctly remove the garbage and put the expected path instead
+nix-build ./content-addressed.nix -A rootCA --no-out-link
+
+# Rebuild it. This shouldn’t overwrite the existing path
+oldInode=$(stat -c '%i' "$outPath")
+nix-build ./content-addressed.nix -A rootCA --no-out-link --arg seed 2
+newInode=$(stat -c '%i' "$outPath")
+[[ "$oldInode" == "$newInode" ]]
diff --git a/tests/ca/common.sh b/tests/ca/common.sh
index e083d873c..c5aa34334 100644
--- a/tests/ca/common.sh
+++ b/tests/ca/common.sh
@@ -1 +1,5 @@
source ../common.sh
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
+
+restartDaemon
diff --git a/tests/ca/concurrent-builds.sh b/tests/ca/concurrent-builds.sh
new file mode 100755
index 000000000..b442619e2
--- /dev/null
+++ b/tests/ca/concurrent-builds.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+# Ensure that we can’t build twice the same derivation concurrently.
+# Regression test for https://github.com/NixOS/nix/issues/5029
+
+source common.sh
+
+buggyNeedLocalStore "For some reason, this deadlocks with the daemon"
+
+export NIX_TESTS_CA_BY_DEFAULT=1
+
+clearStore
+
+for i in {0..5}; do
+ nix build --no-link --file ./racy.nix &
+done
+
+wait
diff --git a/tests/ca/duplicate-realisation-in-closure.sh b/tests/ca/duplicate-realisation-in-closure.sh
new file mode 100644
index 000000000..74c5d25fd
--- /dev/null
+++ b/tests/ca/duplicate-realisation-in-closure.sh
@@ -0,0 +1,28 @@
+source ./common.sh
+
+requireDaemonNewerThan "2.4pre20210625"
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
+
+export REMOTE_STORE_DIR="$TEST_ROOT/remote_store"
+export REMOTE_STORE="file://$REMOTE_STORE_DIR"
+
+rm -rf $REMOTE_STORE_DIR
+clearStore
+
+# Build dep1 and push that to the binary cache.
+# This entails building (and pushing) current-time.
+nix copy --to "$REMOTE_STORE" -f nondeterministic.nix dep1
+clearStore
+sleep 2 # To make sure that `$(date)` will be different
+# Build dep2.
+# As we’ve cleared the cache, we’ll have to rebuild current-time. And because
+# the current time isn’t the same as before, this will yield a new (different)
+# realisation
+nix build -f nondeterministic.nix dep2 --no-link
+
+# Build something that depends both on dep1 and dep2.
+# If everything goes right, we should rebuild dep2 rather than fetch it from
+# the cache (because that would mean duplicating `current-time` in the closure),
+# and have `dep1 == dep2`.
+nix build --substituters "$REMOTE_STORE" -f nondeterministic.nix toplevel --no-require-sigs --no-link
diff --git a/tests/ca/gc.sh b/tests/ca/gc.sh
new file mode 100755
index 000000000..e9b6c5ab5
--- /dev/null
+++ b/tests/ca/gc.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+# Ensure that garbage collection works properly with ca derivations
+
+source common.sh
+
+export NIX_TESTS_CA_BY_DEFAULT=1
+
+cd ..
+source gc.sh
diff --git a/tests/ca/nix-shell.sh b/tests/ca/nix-shell.sh
new file mode 100755
index 000000000..7f1a3a73e
--- /dev/null
+++ b/tests/ca/nix-shell.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+source common.sh
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf
+
+CONTENT_ADDRESSED=true
+cd ..
+source ./nix-shell.sh
+
diff --git a/tests/ca/nondeterministic.nix b/tests/ca/nondeterministic.nix
new file mode 100644
index 000000000..d6d099a3e
--- /dev/null
+++ b/tests/ca/nondeterministic.nix
@@ -0,0 +1,35 @@
+with import ./config.nix;
+
+let mkCADerivation = args: mkDerivation ({
+ __contentAddressed = true;
+ outputHashMode = "recursive";
+ outputHashAlgo = "sha256";
+} // args);
+in
+
+rec {
+ currentTime = mkCADerivation {
+ name = "current-time";
+ buildCommand = ''
+ mkdir $out
+ echo $(date) > $out/current-time
+ '';
+ };
+ dep = seed: mkCADerivation {
+ name = "dep";
+ inherit seed;
+ buildCommand = ''
+ echo ${currentTime} > $out
+ '';
+ };
+ dep1 = dep 1;
+ dep2 = dep 2;
+ toplevel = mkCADerivation {
+ name = "toplevel";
+ buildCommand = ''
+ test ${dep1} == ${dep2}
+ touch $out
+ '';
+ };
+}
+
diff --git a/tests/ca/post-hook.sh b/tests/ca/post-hook.sh
new file mode 100755
index 000000000..1c9d4f700
--- /dev/null
+++ b/tests/ca/post-hook.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+source common.sh
+
+requireDaemonNewerThan "2.4pre20210626"
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf
+
+export NIX_TESTS_CA_BY_DEFAULT=1
+cd ..
+source ./post-hook.sh
+
+
diff --git a/tests/ca/racy.nix b/tests/ca/racy.nix
new file mode 100644
index 000000000..555a15484
--- /dev/null
+++ b/tests/ca/racy.nix
@@ -0,0 +1,15 @@
+# A derivation that would certainly fail if several builders tried to
+# build it at once.
+
+
+with import ./config.nix;
+
+mkDerivation {
+ name = "simple";
+ buildCommand = ''
+ mkdir $out
+ echo bar >> $out/foo
+ sleep 3
+ [[ "$(cat $out/foo)" == bar ]]
+ '';
+}
diff --git a/tests/ca/recursive.sh b/tests/ca/recursive.sh
new file mode 100755
index 000000000..648bf0a91
--- /dev/null
+++ b/tests/ca/recursive.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+source common.sh
+
+requireDaemonNewerThan "2.4pre20210623"
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf
+
+export NIX_TESTS_CA_BY_DEFAULT=1
+cd ..
+source ./recursive.sh
+
+
diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh
index dfc4ea68e..3d9001bb8 100644
--- a/tests/ca/substitute.sh
+++ b/tests/ca/substitute.sh
@@ -4,7 +4,7 @@
source common.sh
-sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
+needLocalStore "“--no-require-sigs” can’t be used with the daemon"
rm -rf $TEST_ROOT/binary_cache
@@ -17,11 +17,15 @@ buildDrvs () {
# Populate the remote cache
clearStore
-buildDrvs --post-build-hook ../push-to-store.sh
+nix copy --to $REMOTE_STORE --file ./content-addressed.nix
# Restart the build on an empty store, ensuring that we don't build
clearStore
-buildDrvs --substitute --substituters $REMOTE_STORE --no-require-sigs -j0
+buildDrvs --substitute --substituters $REMOTE_STORE --no-require-sigs -j0 transitivelyDependentCA
+# Check that the thing we’ve just substituted has its realisation stored
+nix realisation info --file ./content-addressed.nix transitivelyDependentCA
+# Check that its dependencies have it too
+nix realisation info --file ./content-addressed.nix dependentCA rootCA
# Same thing, but
# 1. With non-ca derivations
diff --git a/tests/check.nix b/tests/check.nix
index bca04fdaf..ec455ae2d 100644
--- a/tests/check.nix
+++ b/tests/check.nix
@@ -44,7 +44,7 @@ with import ./config.nix;
};
hashmismatch = import <nix/fetchurl.nix> {
- url = "file://" + toString ./dummy;
+ url = "file://" + builtins.getEnv "TMPDIR" + "/dummy";
sha256 = "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73";
};
diff --git a/tests/check.sh b/tests/check.sh
index 5f4997e28..ab48ff865 100644
--- a/tests/check.sh
+++ b/tests/check.sh
@@ -1,5 +1,8 @@
source common.sh
+# XXX: This shouldn’t be, but #4813 cause this test to fail
+buggyNeedLocalStore "see #4813"
+
checkBuildTempDirRemoved ()
{
buildDir=$(sed -n 's/CHECK_TMPDIR=//p' $1 | head -1)
@@ -74,12 +77,13 @@ nix-build check.nix -A fetchurl --no-out-link --check
nix-build check.nix -A fetchurl --no-out-link --repair
[[ $(cat $path) != foo ]]
+echo 'Hello World' > $TMPDIR/dummy
nix-build check.nix -A hashmismatch --no-out-link || status=$?
[ "$status" = "102" ]
-echo -n > ./dummy
+echo -n > $TMPDIR/dummy
nix-build check.nix -A hashmismatch --no-out-link
-echo 'Hello World' > ./dummy
+echo 'Hello World' > $TMPDIR/dummy
nix-build check.nix -A hashmismatch --no-out-link --check || status=$?
[ "$status" = "102" ]
diff --git a/tests/common.sh.in b/tests/common.sh.in
index d31d3fbb8..7daab2460 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -1,5 +1,9 @@
set -e
+if [[ -z "$COMMON_SH_SOURCED" ]]; then
+
+COMMON_SH_SOURCED=1
+
export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/${TEST_NAME:-default}
export NIX_STORE_DIR
if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
@@ -45,6 +49,9 @@ export busybox="@sandbox_shell@"
export version=@PACKAGE_VERSION@
export system=@system@
+export IMPURE_VAR1=foo
+export IMPURE_VAR2=bar
+
cacheDir=$TEST_ROOT/binary-cache
readLink() {
@@ -75,29 +82,57 @@ clearCacheCache() {
}
startDaemon() {
+ # Don’t start the daemon twice, as this would just make it loop indefinitely
+ if [[ "$NIX_REMOTE" == daemon ]]; then
+ return
+ fi
# Start the daemon, wait for the socket to appear. !!!
# ‘nix-daemon’ should have an option to fork into the background.
- rm -f $NIX_STATE_DIR/daemon-socket/socket
+ rm -f $NIX_DAEMON_SOCKET_PATH
${NIX_DAEMON_COMMAND:-nix daemon} &
for ((i = 0; i < 30; i++)); do
- if [ -e $NIX_DAEMON_SOCKET_PATH ]; then break; fi
+ if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then break; fi
sleep 1
done
pidDaemon=$!
- trap "kill -9 $pidDaemon" EXIT
+ trap "killDaemon" EXIT
export NIX_REMOTE=daemon
}
killDaemon() {
- kill -9 $pidDaemon
+ kill $pidDaemon
+ for i in {0.10}; do
+ kill -0 $pidDaemon || break
+ sleep 1
+ done
+ kill -9 $pidDaemon || true
wait $pidDaemon || true
trap "" EXIT
}
+restartDaemon() {
+ [[ -z "${pidDaemon:-}" ]] && return 0
+
+ killDaemon
+ unset NIX_REMOTE
+ startDaemon
+}
+
if [[ $(uname) == Linux ]] && [[ -L /proc/self/ns/user ]] && unshare --user true; then
_canUseSandbox=1
fi
+isDaemonNewer () {
+ [[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0
+ local requiredVersion="$1"
+ local daemonVersion=$($NIX_DAEMON_PACKAGE/bin/nix-daemon --version | cut -d' ' -f3)
+ return [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''2.4''") -ge 0 ]]
+}
+
+requireDaemonNewerThan () {
+ isDaemonNewer "$1" || exit 99
+}
+
canUseSandbox() {
if [[ ! $_canUseSandbox ]]; then
echo "Sandboxing not supported, skipping this test..."
@@ -123,4 +158,22 @@ expect() {
[[ $res -eq $expected ]]
}
+needLocalStore() {
+ if [[ "$NIX_REMOTE" == "daemon" ]]; then
+ echo "Can’t run through the daemon ($1), skipping this test..."
+ return 99
+ fi
+}
+
+# Just to make it easy to find which tests should be fixed
+buggyNeedLocalStore () {
+ needLocalStore
+}
+
set -x
+
+if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
+ startDaemon
+fi
+
+fi # COMMON_SH_SOURCED
diff --git a/tests/config.nix.in b/tests/config.nix.in
index a57a8c596..7facbdcbc 100644
--- a/tests/config.nix.in
+++ b/tests/config.nix.in
@@ -1,3 +1,12 @@
+let
+ contentAddressedByDefault = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT" == "1";
+ caArgs = if contentAddressedByDefault then {
+ __contentAddressed = true;
+ outputHashMode = "recursive";
+ outputHashAlgo = "sha256";
+ } else {};
+in
+
rec {
shell = "@bash@";
@@ -13,6 +22,6 @@ rec {
builder = shell;
args = ["-e" args.builder or (builtins.toFile "builder-${args.name}.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")];
PATH = path;
- } // removeAttrs args ["builder" "meta"])
+ } // caArgs // removeAttrs args ["builder" "meta"])
// { meta = args.meta or {}; };
}
diff --git a/tests/db-migration.sh b/tests/db-migration.sh
index e0ff7d311..3f9dc8972 100644
--- a/tests/db-migration.sh
+++ b/tests/db-migration.sh
@@ -3,11 +3,14 @@
# Only run this if we have an older Nix available
# XXX: This assumes that the `daemon` package is older than the `client` one
if [[ -z "$NIX_DAEMON_PACKAGE" ]]; then
- exit 0
+ exit 99
fi
source common.sh
+killDaemon
+unset NIX_REMOTE
+
# Fill the db using the older Nix
PATH_WITH_NEW_NIX="$PATH"
export PATH="$NIX_DAEMON_PACKAGE/bin:$PATH"
diff --git a/tests/dummy b/tests/dummy
new file mode 100644
index 000000000..557db03de
--- /dev/null
+++ b/tests/dummy
@@ -0,0 +1 @@
+Hello World
diff --git a/tests/dump-db.sh b/tests/dump-db.sh
index d6eea42aa..48647f403 100644
--- a/tests/dump-db.sh
+++ b/tests/dump-db.sh
@@ -1,5 +1,7 @@
source common.sh
+needLocalStore "--dump-db requires a local store"
+
clearStore
path=$(nix-build dependencies.nix -o $TEST_ROOT/result)
diff --git a/tests/eval-store.sh b/tests/eval-store.sh
new file mode 100644
index 000000000..9ab7a87be
--- /dev/null
+++ b/tests/eval-store.sh
@@ -0,0 +1,28 @@
+source common.sh
+
+requireDaemonNewerThan "2.4pre20210727"
+
+eval_store=$TEST_ROOT/eval-store
+
+clearStore
+rm -rf "$eval_store"
+
+nix build -f dependencies.nix --eval-store "$eval_store" -o "$TEST_ROOT/result"
+[[ -e $TEST_ROOT/result/foobar ]]
+(! ls $NIX_STORE_DIR/*.drv)
+ls $eval_store/nix/store/*.drv
+
+clearStore
+rm -rf "$eval_store"
+
+nix-instantiate dependencies.nix --eval-store "$eval_store"
+(! ls $NIX_STORE_DIR/*.drv)
+ls $eval_store/nix/store/*.drv
+
+clearStore
+rm -rf "$eval_store"
+
+nix-build dependencies.nix --eval-store "$eval_store" -o "$TEST_ROOT/result"
+[[ -e $TEST_ROOT/result/foobar ]]
+(! ls $NIX_STORE_DIR/*.drv)
+ls $eval_store/nix/store/*.drv
diff --git a/tests/fetchGit.sh b/tests/fetchGit.sh
index 88744ee7f..89294d8d2 100644
--- a/tests/fetchGit.sh
+++ b/tests/fetchGit.sh
@@ -189,3 +189,7 @@ path8=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$rep
rev4=$(git -C $repo rev-parse HEAD)
rev4_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).rev")
[[ $rev4 = $rev4_nix ]]
+
+# The name argument should be handled
+path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; name = \"foo\"; }).outPath")
+[[ $path9 =~ -foo$ ]]
diff --git a/tests/fetchMercurial.sh b/tests/fetchMercurial.sh
index d8a4e09d2..726840664 100644
--- a/tests/fetchMercurial.sh
+++ b/tests/fetchMercurial.sh
@@ -94,3 +94,8 @@ hg commit --cwd $repo -m 'Bla3'
path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $path2 = $path4 ]]
+
+echo paris > $repo/hello
+# Passing a `name` argument should be reflected in the output path
+path5=$(nix eval -vvvvv --impure --refresh --raw --expr "(builtins.fetchMercurial { url = \"file://$repo\"; name = \"foo\"; } ).outPath")
+[[ $path5 =~ -foo$ ]]
diff --git a/tests/fetchurl.sh b/tests/fetchurl.sh
index cd84e9a4c..3d1685f43 100644
--- a/tests/fetchurl.sh
+++ b/tests/fetchurl.sh
@@ -5,7 +5,7 @@ clearStore
# Test fetching a flat file.
hash=$(nix-hash --flat --type sha256 ./fetchurl.sh)
-outPath=$(nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha256 $hash --no-out-link)
+outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha256 $hash --no-out-link)
cmp $outPath fetchurl.sh
@@ -14,7 +14,7 @@ clearStore
hash=$(nix hash file --type sha512 --base64 ./fetchurl.sh)
-outPath=$(nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link)
+outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link)
cmp $outPath fetchurl.sh
@@ -25,7 +25,7 @@ hash=$(nix hash file ./fetchurl.sh)
[[ $hash =~ ^sha256- ]]
-outPath=$(nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr hash $hash --no-out-link)
+outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr hash $hash --no-out-link)
cmp $outPath fetchurl.sh
@@ -38,10 +38,10 @@ hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh)
storePath=$(nix --store $other_store store add-file ./fetchurl.sh)
-outPath=$(nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)
+outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)
# Test hashed mirrors with an SRI hash.
-nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
+nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
--no-out-link --substituters $other_store
# Test unpacking a NAR.
@@ -55,7 +55,7 @@ nix-store --dump $TEST_ROOT/archive > $nar
hash=$(nix-hash --flat --type sha256 $nar)
-outPath=$(nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file://$nar --argstr sha256 $hash \
+outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$nar --argstr sha256 $hash \
--arg unpack true --argstr name xyzzy --no-out-link)
echo $outPath | grep -q 'xyzzy'
@@ -69,7 +69,7 @@ nix-store --delete $outPath
narxz=$TEST_ROOT/archive.nar.xz
rm -f $narxz
xz --keep $nar
-outPath=$(nix-build --expr 'import <nix/fetchurl.nix>' --argstr url file://$narxz --argstr sha256 $hash \
+outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$narxz --argstr sha256 $hash \
--arg unpack true --argstr name xyzzy --no-out-link)
test -x $outPath/fetchurl.sh
diff --git a/tests/fixed.sh b/tests/fixed.sh
index 8f51403a7..90c4c8c32 100644
--- a/tests/fixed.sh
+++ b/tests/fixed.sh
@@ -2,9 +2,6 @@ source common.sh
clearStore
-export IMPURE_VAR1=foo
-export IMPURE_VAR2=bar
-
path=$(nix-store -q $(nix-instantiate fixed.nix -A good.0))
echo 'testing bad...'
diff --git a/tests/flakes.sh b/tests/flakes.sh
index 9764e1a6c..610bab391 100644
--- a/tests/flakes.sh
+++ b/tests/flakes.sh
@@ -23,13 +23,19 @@ flake6Dir=$TEST_ROOT/flake6
flake7Dir=$TEST_ROOT/flake7
templatesDir=$TEST_ROOT/templates
nonFlakeDir=$TEST_ROOT/nonFlake
+badFlakeDir=$TEST_ROOT/badFlake
flakeA=$TEST_ROOT/flakeA
flakeB=$TEST_ROOT/flakeB
flakeGitBare=$TEST_ROOT/flakeGitBare
+flakeFollowsA=$TEST_ROOT/follows/flakeA
+flakeFollowsB=$TEST_ROOT/follows/flakeA/flakeB
+flakeFollowsC=$TEST_ROOT/follows/flakeA/flakeB/flakeC
+flakeFollowsD=$TEST_ROOT/follows/flakeA/flakeD
+flakeFollowsE=$TEST_ROOT/follows/flakeA/flakeE
-for repo in $flake1Dir $flake2Dir $flake3Dir $flake7Dir $templatesDir $nonFlakeDir $flakeA $flakeB; do
+for repo in $flake1Dir $flake2Dir $flake3Dir $flake7Dir $templatesDir $nonFlakeDir $flakeA $flakeB $flakeFollowsA; do
rm -rf $repo $repo.tmp
- mkdir $repo
+ mkdir -p $repo
git -C $repo init
git -C $repo config user.email "foobar@example.com"
git -C $repo config user.name "Foobar"
@@ -90,76 +96,14 @@ EOF
git -C $nonFlakeDir add README.md
git -C $nonFlakeDir commit -m 'Initial'
-cat > $registry <<EOF
-{
- "version": 2,
- "flakes": [
- { "from": {
- "type": "indirect",
- "id": "flake1"
- },
- "to": {
- "type": "git",
- "url": "file://$flake1Dir"
- }
- },
- { "from": {
- "type": "indirect",
- "id": "flake2"
- },
- "to": {
- "type": "git",
- "url": "file://$flake2Dir"
- }
- },
- { "from": {
- "type": "indirect",
- "id": "flake3"
- },
- "to": {
- "type": "git",
- "url": "file://$flake3Dir"
- }
- },
- { "from": {
- "type": "indirect",
- "id": "flake4"
- },
- "to": {
- "type": "indirect",
- "id": "flake3"
- }
- },
- { "from": {
- "type": "indirect",
- "id": "flake5"
- },
- "to": {
- "type": "hg",
- "url": "file://$flake5Dir"
- }
- },
- { "from": {
- "type": "indirect",
- "id": "nixpkgs"
- },
- "to": {
- "type": "indirect",
- "id": "flake1"
- }
- },
- { "from": {
- "type": "indirect",
- "id": "templates"
- },
- "to": {
- "type": "git",
- "url": "file://$templatesDir"
- }
- }
- ]
-}
-EOF
+# Construct a custom registry, additionally test the --registry flag
+nix registry add --registry $registry flake1 git+file://$flake1Dir
+nix registry add --registry $registry flake2 git+file://$flake2Dir
+nix registry add --registry $registry flake3 git+file://$flake3Dir
+nix registry add --registry $registry flake4 flake3
+nix registry add --registry $registry flake5 hg+file://$flake5Dir
+nix registry add --registry $registry nixpkgs flake1
+nix registry add --registry $registry templates git+file://$templatesDir
# Test 'nix flake list'.
[[ $(nix registry list | wc -l) == 7 ]]
@@ -209,6 +153,7 @@ nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Di
# Building a flake with an unlocked dependency should fail in pure mode.
(! nix build -o $TEST_ROOT/result flake2#bar --no-registries)
+(! nix build -o $TEST_ROOT/result flake2#bar --no-use-registries)
(! nix eval --expr "builtins.getFlake \"$flake2Dir\"")
# But should succeed in impure mode.
@@ -232,6 +177,7 @@ nix build -o $TEST_ROOT/result $flake2Dir#bar
# Building with a lockfile should not require a fetch of the registry.
nix build -o $TEST_ROOT/result --flake-registry file:///no-registry.json $flake2Dir#bar --refresh
nix build -o $TEST_ROOT/result --no-registries $flake2Dir#bar --refresh
+nix build -o $TEST_ROOT/result --no-use-registries $flake2Dir#bar --refresh
# Updating the flake should not change the lockfile.
nix flake lock $flake2Dir
@@ -242,6 +188,7 @@ nix build -o $TEST_ROOT/result flake2#bar
# Or without a registry.
nix build -o $TEST_ROOT/result --no-registries git+file://$flake2Dir#bar --refresh
+nix build -o $TEST_ROOT/result --no-use-registries git+file://$flake2Dir#bar --refresh
# Test whether indirect dependencies work.
nix build -o $TEST_ROOT/result $flake3Dir#xyzzy
@@ -405,6 +352,8 @@ nix registry add flake1 flake3
[[ $(nix registry list | wc -l) == 8 ]]
nix registry pin flake1
[[ $(nix registry list | wc -l) == 8 ]]
+nix registry pin flake1 flake3
+[[ $(nix registry list | wc -l) == 8 ]]
nix registry remove flake1
[[ $(nix registry list | wc -l) == 7 ]]
@@ -663,6 +612,7 @@ nix flake metadata --json hg+file://$flake5Dir
[[ $(nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revCount) = 1 ]]
nix build -o $TEST_ROOT/result hg+file://$flake5Dir --no-registries --no-allow-dirty
+nix build -o $TEST_ROOT/result hg+file://$flake5Dir --no-use-registries --no-allow-dirty
# Test tarball flakes
tar cfz $TEST_ROOT/flake.tar.gz -C $TEST_ROOT --exclude .hg flake5
@@ -737,3 +687,98 @@ git -C $flakeB commit -a -m 'Foo'
# Test list-inputs with circular dependencies
nix flake metadata $flakeA
+
+# Test flake follow paths
+mkdir -p $flakeFollowsB
+mkdir -p $flakeFollowsC
+mkdir -p $flakeFollowsD
+mkdir -p $flakeFollowsE
+
+cat > $flakeFollowsA/flake.nix <<EOF
+{
+ description = "Flake A";
+ inputs = {
+ B = {
+ url = "path:./flakeB";
+ inputs.foobar.follows = "D";
+ };
+
+ D.url = "path:./flakeD";
+ foobar.url = "path:./flakeE";
+ };
+ outputs = { ... }: {};
+}
+EOF
+
+cat > $flakeFollowsB/flake.nix <<EOF
+{
+ description = "Flake B";
+ inputs = {
+ foobar.url = "path:./../flakeE";
+ C = {
+ url = "path:./flakeC";
+ inputs.foobar.follows = "foobar";
+ };
+ };
+ outputs = { ... }: {};
+}
+EOF
+
+cat > $flakeFollowsC/flake.nix <<EOF
+{
+ description = "Flake C";
+ inputs = {
+ foobar.url = "path:./../../flakeE";
+ };
+ outputs = { ... }: {};
+}
+EOF
+
+cat > $flakeFollowsD/flake.nix <<EOF
+{
+ description = "Flake D";
+ inputs = {};
+ outputs = { ... }: {};
+}
+EOF
+
+cat > $flakeFollowsE/flake.nix <<EOF
+{
+ description = "Flake D";
+ inputs = {};
+ outputs = { ... }: {};
+}
+EOF
+
+git -C $flakeFollowsA add flake.nix flakeB/flake.nix \
+ flakeB/flakeC/flake.nix flakeD/flake.nix flakeE/flake.nix
+
+nix flake lock $flakeFollowsA
+
+[[ $(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 a relative path is not allowed to go outside the store path
+cat > $flakeFollowsA/flake.nix <<EOF
+{
+ description = "Flake A";
+ inputs = {
+ B.url = "path:./../../flakeB";
+ };
+ outputs = { ... }: {};
+}
+EOF
+
+git -C $flakeFollowsA add flake.nix
+
+nix flake lock $flakeFollowsA 2>&1 | grep 'this is a security violation'
+
+# Test flake in store does not evaluate
+rm -rf $badFlakeDir
+mkdir $badFlakeDir
+echo INVALID > $badFlakeDir/flake.nix
+nix store delete $(nix store add-path $badFlakeDir)
+
+[[ $(nix path-info $(nix store add-path $flake1Dir)) =~ flake1 ]]
+[[ $(nix path-info path:$(nix store add-path $flake1Dir)) =~ simple ]]
diff --git a/tests/gc-auto.sh b/tests/gc-auto.sh
index 6867f2eb4..521d9e539 100644
--- a/tests/gc-auto.sh
+++ b/tests/gc-auto.sh
@@ -1,5 +1,7 @@
source common.sh
+needLocalStore "“min-free” and “max-free” are daemon options"
+
clearStore
garbage1=$(nix store add-path --name garbage1 ./nar-access.sh)
diff --git a/tests/gc.sh b/tests/gc.sh
index 8b4f8d282..cf0e2c32d 100644
--- a/tests/gc.sh
+++ b/tests/gc.sh
@@ -12,7 +12,7 @@ ln -sf $outPath "$NIX_STATE_DIR"/gcroots/foo
nix-store --gc --print-roots | grep $outPath
nix-store --gc --print-live | grep $outPath
nix-store --gc --print-dead | grep $drvPath
-if nix-store --gc --print-dead | grep $outPath; then false; fi
+if nix-store --gc --print-dead | grep -E $outPath$; then false; fi
nix-store --gc --print-dead
diff --git a/tests/init.sh b/tests/init.sh
index 1a6ccb6fe..3c6d5917d 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -23,6 +23,7 @@ substituters =
flake-registry = $TEST_ROOT/registry.json
show-trace = true
include nix.conf.extra
+trusted-users = $(whoami)
EOF
cat > "$NIX_CONF_DIR"/nix.conf.extra <<EOF
@@ -35,5 +36,3 @@ nix-store --init
# Did anything happen?
test -e "$NIX_STATE_DIR"/db/db.sqlite
-
-echo 'Hello World' > ./dummy
diff --git a/tests/lang/eval-fail-antiquoted-path.nix b/tests/lang/eval-fail-nonexist-path.nix
index f2f08107b..f2f08107b 100644
--- a/tests/lang/eval-fail-antiquoted-path.nix
+++ b/tests/lang/eval-fail-nonexist-path.nix
diff --git a/tests/lang/eval-okay-path-antiquotation.nix b/tests/lang/eval-okay-path-antiquotation.nix
new file mode 100644
index 000000000..497d7c1c7
--- /dev/null
+++ b/tests/lang/eval-okay-path-antiquotation.nix
@@ -0,0 +1,12 @@
+let
+ foo = "foo";
+in
+{
+ simple = ./${foo};
+ surrounded = ./a-${foo}-b;
+ absolute = /${foo};
+ expr = ./${foo + "/bar"};
+ home = ~/${foo};
+ notfirst = ./bar/${foo};
+ slashes = /${foo}/${"bar"};
+}
diff --git a/tests/linux-sandbox.sh b/tests/linux-sandbox.sh
index eac62d461..3f304ac2f 100644
--- a/tests/linux-sandbox.sh
+++ b/tests/linux-sandbox.sh
@@ -1,5 +1,7 @@
source common.sh
+needLocalStore "the sandbox only runs on the builder side, so it makes no sense to test it with the daemon"
+
clearStore
if ! canUseSandbox; then exit 99; fi
diff --git a/tests/local.mk b/tests/local.mk
index 59eb4eb0f..b100e7f15 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -2,6 +2,7 @@ nix_tests = \
hash.sh lang.sh add.sh simple.sh dependencies.sh \
config.sh \
gc.sh \
+ ca/gc.sh \
gc-concurrent.sh \
gc-auto.sh \
referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \
@@ -38,17 +39,25 @@ nix_tests = \
search.sh \
nix-copy-ssh.sh \
post-hook.sh \
+ ca/post-hook.sh \
function-trace.sh \
recursive.sh \
describe-stores.sh \
flakes.sh \
build.sh \
compute-levels.sh \
+ repl.sh \
ca/build.sh \
+ ca/build-with-garbage-path.sh \
+ ca/duplicate-realisation-in-closure.sh \
ca/substitute.sh \
ca/signatures.sh \
+ ca/nix-shell.sh \
ca/nix-run.sh \
- ca/nix-copy.sh
+ ca/recursive.sh \
+ ca/concurrent-builds.sh \
+ ca/nix-copy.sh \
+ eval-store.sh
# parallel.sh
install-tests += $(foreach x, $(nix_tests), tests/$(x))
diff --git a/tests/multiple-outputs.sh b/tests/multiple-outputs.sh
index de573d4fa..0bca12b42 100644
--- a/tests/multiple-outputs.sh
+++ b/tests/multiple-outputs.sh
@@ -58,7 +58,7 @@ outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-ou
# Delete one of the outputs and rebuild it. This will cause a hash
# rewrite.
-nix store delete $TEST_ROOT/result-second --ignore-liveness
+env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh
index 4775bafb9..a31d35887 100644
--- a/tests/nix-shell.sh
+++ b/tests/nix-shell.sh
@@ -2,6 +2,20 @@ source common.sh
clearStore
+if [[ -n ${CONTENT_ADDRESSED:-} ]]; then
+ nix-shell () {
+ command nix-shell --arg contentAddressed true "$@"
+ }
+
+ nix_develop() {
+ nix develop --arg contentAddressed true "$@"
+ }
+else
+ nix_develop() {
+ nix develop "$@"
+ }
+fi
+
# Test nix-shell -A
export IMPURE_VAR=foo
export SELECTED_IMPURE_VAR=baz
@@ -40,8 +54,12 @@ nix-instantiate shell.nix -A shellDrv --add-root $TEST_ROOT/shell
output=$(NIX_PATH=nixpkgs=shell.nix 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" = "baz" ]
+
# Test nix-shell shebang mode
-sed -e "s|@ENV_PROG@|$(type -p env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh
+sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh
chmod a+rx $TEST_ROOT/shell.shebang.sh
output=$($TEST_ROOT/shell.shebang.sh abc def)
@@ -49,7 +67,7 @@ output=$($TEST_ROOT/shell.shebang.sh abc def)
# Test nix-shell shebang mode again with metacharacters in the filename.
# First word of filename is chosen to not match any file in the test root.
-sed -e "s|@ENV_PROG@|$(type -p env)|" shell.shebang.sh > $TEST_ROOT/spaced\ \\\'\"shell.shebang.sh
+sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/spaced\ \\\'\"shell.shebang.sh
chmod a+rx $TEST_ROOT/spaced\ \\\'\"shell.shebang.sh
output=$($TEST_ROOT/spaced\ \\\'\"shell.shebang.sh abc def)
@@ -58,7 +76,7 @@ output=$($TEST_ROOT/spaced\ \\\'\"shell.shebang.sh abc def)
# Test nix-shell shebang mode for ruby
# This uses a fake interpreter that returns the arguments passed
# This, in turn, verifies the `rc` script is valid and the `load()` script (given using `-e`) is as expected.
-sed -e "s|@SHELL_PROG@|$(type -p nix-shell)|" shell.shebang.rb > $TEST_ROOT/shell.shebang.rb
+sed -e "s|@SHELL_PROG@|$(type -P nix-shell)|" shell.shebang.rb > $TEST_ROOT/shell.shebang.rb
chmod a+rx $TEST_ROOT/shell.shebang.rb
output=$($TEST_ROOT/shell.shebang.rb abc ruby)
@@ -66,21 +84,27 @@ output=$($TEST_ROOT/shell.shebang.rb abc ruby)
# Test nix-shell shebang mode for ruby again with metacharacters in the filename.
# Note: fake interpreter only space-separates args without adding escapes to its output.
-sed -e "s|@SHELL_PROG@|$(type -p nix-shell)|" shell.shebang.rb > $TEST_ROOT/spaced\ \\\'\"shell.shebang.rb
+sed -e "s|@SHELL_PROG@|$(type -P nix-shell)|" shell.shebang.rb > $TEST_ROOT/spaced\ \\\'\"shell.shebang.rb
chmod a+rx $TEST_ROOT/spaced\ \\\'\"shell.shebang.rb
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 shell.nix 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
# 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 shell.nix 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' ]]
+
source <(nix print-dev-env -f shell.nix shellDrv)
[[ -n $stdenv ]]
+[[ ${arr1[2]} = "3 4" ]]
+[[ ${arr2[1]} = $'\n' ]]
+[[ ${arr2[2]} = $'x\ny' ]]
+[[ $(fun) = blabla ]]
diff --git a/tests/optimise-store.sh b/tests/optimise-store.sh
index 61e3df2f9..8c2d05cd5 100644
--- a/tests/optimise-store.sh
+++ b/tests/optimise-store.sh
@@ -26,7 +26,8 @@ if [ "$inode1" = "$inode3" ]; then
exit 1
fi
-nix-store --optimise
+# XXX: This should work through the daemon too
+NIX_REMOTE="" nix-store --optimise
inode1="$(stat --format=%i $outPath1/foo)"
inode3="$(stat --format=%i $outPath3/foo)"
diff --git a/tests/post-hook.sh b/tests/post-hook.sh
index aa3e6a574..049e40749 100644
--- a/tests/post-hook.sh
+++ b/tests/post-hook.sh
@@ -4,7 +4,10 @@ clearStore
rm -f $TEST_ROOT/result
-export REMOTE_STORE=$TEST_ROOT/remote_store
+export REMOTE_STORE=file:$TEST_ROOT/remote_store
+echo 'require-sigs = false' >> $NIX_CONF_DIR/nix.conf
+
+restartDaemon
# Build the dependencies and push them to the remote store
nix-build -o $TEST_ROOT/result dependencies.nix --post-build-hook $PWD/push-to-store.sh
diff --git a/tests/recursive.sh b/tests/recursive.sh
index a55b061b5..b6740877d 100644
--- a/tests/recursive.sh
+++ b/tests/recursive.sh
@@ -9,9 +9,9 @@ rm -f $TEST_ROOT/result
export unreachable=$(nix store add-path ./recursive.sh)
-NIX_BIN_DIR=$(dirname $(type -p nix)) nix --experimental-features 'nix-command recursive-nix' build -o $TEST_ROOT/result -L --impure --expr '
+NIX_BIN_DIR=$(dirname $(type -p nix)) nix --extra-experimental-features 'nix-command recursive-nix' build -o $TEST_ROOT/result -L --impure --expr '
with import ./config.nix;
- mkDerivation {
+ mkDerivation rec {
name = "recursive";
dummy = builtins.toFile "dummy" "bla bla";
SHELL = shell;
@@ -19,11 +19,13 @@ NIX_BIN_DIR=$(dirname $(type -p nix)) nix --experimental-features 'nix-command r
# Note: this is a string without context.
unreachable = builtins.getEnv "unreachable";
+ NIX_TESTS_CA_BY_DEFAULT = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT";
+
requiredSystemFeatures = [ "recursive-nix" ];
buildCommand = '\'\''
mkdir $out
- opts="--experimental-features nix-command"
+ opts="--experimental-features nix-command ${if (NIX_TESTS_CA_BY_DEFAULT == "1") then "--extra-experimental-features ca-derivations" else ""}"
PATH=${builtins.getEnv "NIX_BIN_DIR"}:$PATH
@@ -46,16 +48,15 @@ NIX_BIN_DIR=$(dirname $(type -p nix)) nix --experimental-features 'nix-command r
# Add it to our closure.
ln -s $foobar $out/foobar
- [[ $(nix $opts path-info --all | wc -l) -eq 3 ]]
+ [[ $(nix $opts path-info --all | wc -l) -eq 4 ]]
# Build a derivation.
nix $opts build -L --impure --expr '\''
- derivation {
+ with import ${./config.nix};
+ mkDerivation {
name = "inner1";
- builder = builtins.getEnv "SHELL";
- system = builtins.getEnv "system";
+ buildCommand = "echo $fnord blaat > $out";
fnord = builtins.toFile "fnord" "fnord";
- args = [ "-c" "echo $fnord blaat > $out" ];
}
'\''
diff --git a/tests/referrers.sh b/tests/referrers.sh
index 614dd8f5b..81323c280 100644
--- a/tests/referrers.sh
+++ b/tests/referrers.sh
@@ -1,5 +1,7 @@
source common.sh
+needLocalStore "uses some low-level store manipulations that aren’t available through the daemon"
+
clearStore
max=500
diff --git a/tests/repair.sh b/tests/repair.sh
index ba019028d..12dcde8ea 100644
--- a/tests/repair.sh
+++ b/tests/repair.sh
@@ -1,5 +1,7 @@
source common.sh
+needLocalStore "--repair needs a local store"
+
clearStore
path=$(nix-build dependencies.nix -o $TEST_ROOT/result)
diff --git a/tests/repl.sh b/tests/repl.sh
new file mode 100644
index 000000000..4e3059517
--- /dev/null
+++ b/tests/repl.sh
@@ -0,0 +1,18 @@
+source common.sh
+
+replCmds="
+simple = import ./simple.nix
+:b simple
+"
+
+testRepl () {
+ local nixArgs=("$@")
+ local outPath=$(nix repl "${nixArgs[@]}" <<< "$replCmds" |&
+ grep -o -E "$NIX_STORE_DIR/\w*-simple")
+ nix path-info "${nixArgs[@]}" "$outPath"
+}
+
+# Simple test, try building a drv
+testRepl
+# Same thing (kind-of), but with a remote store.
+testRepl --store "$TEST_ROOT/store?real=$NIX_STORE_DIR"
diff --git a/tests/shell.nix b/tests/shell.nix
index 24ebcc04c..4912d295a 100644
--- a/tests/shell.nix
+++ b/tests/shell.nix
@@ -1,6 +1,18 @@
-{ inNixShell ? false }:
+{ inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }:
-with import ./config.nix;
+let cfg = import ./config.nix; in
+with cfg;
+
+let
+ mkDerivation =
+ if contentAddressed then
+ args: cfg.mkDerivation ({
+ __contentAddressed = true;
+ outputHashMode = "recursive";
+ outputHashAlgo = "sha256";
+ } // args)
+ else cfg.mkDerivation;
+in
let pkgs = rec {
setupSh = builtins.toFile "setup" ''
@@ -8,6 +20,20 @@ let pkgs = rec {
for pkg in $buildInputs; do
export PATH=$PATH:$pkg/bin
done
+
+ # mimic behavior of stdenv for `$out` etc. for structured attrs.
+ if [ -n "''${NIX_ATTRS_SH_FILE}" ]; then
+ for o in "''${!outputs[@]}"; do
+ eval "''${o}=''${outputs[$o]}"
+ export "''${o}"
+ done
+ fi
+
+ declare -a arr1=(1 2 "3 4" 5)
+ declare -a arr2=(x $'\n' $'x\ny')
+ fun() {
+ echo blabla
+ }
'';
stdenv = mkDerivation {
@@ -22,6 +48,8 @@ let pkgs = rec {
name = "shellDrv";
builder = "/does/not/exist";
VAR_FROM_NIX = "bar";
+ ASCII_PERCENT = "%";
+ ASCII_AT = "@";
TEST_inNixShell = if inNixShell then "true" else "false";
inherit stdenv;
outputs = ["dev" "out"];
@@ -34,7 +62,7 @@ let pkgs = rec {
foo = runCommand "foo" {} ''
mkdir -p $out/bin
- echo 'echo foo' > $out/bin/foo
+ echo 'echo ${fooContents}' > $out/bin/foo
chmod a+rx $out/bin/foo
ln -s ${shell} $out/bin/bash
'';
diff --git a/tests/structured-attrs-shell.nix b/tests/structured-attrs-shell.nix
new file mode 100644
index 000000000..57c1e6bd2
--- /dev/null
+++ b/tests/structured-attrs-shell.nix
@@ -0,0 +1,21 @@
+with import ./config.nix;
+let
+ dep = mkDerivation {
+ name = "dep";
+ buildCommand = ''
+ mkdir $out; echo bla > $out/bla
+ '';
+ };
+ inherit (import ./shell.nix { inNixShell = true; }) stdenv;
+in
+mkDerivation {
+ name = "structured2";
+ __structuredAttrs = true;
+ inherit stdenv;
+ outputs = [ "out" "dev" ];
+ my.list = [ "a" "b" "c" ];
+ exportReferencesGraph.refs = [ dep ];
+ buildCommand = ''
+ touch ''${outputs[out]}; touch ''${outputs[dev]}
+ '';
+}
diff --git a/tests/structured-attrs.nix b/tests/structured-attrs.nix
index c39c3a346..e93139a44 100644
--- a/tests/structured-attrs.nix
+++ b/tests/structured-attrs.nix
@@ -36,7 +36,7 @@ mkDerivation {
echo bar > $dest
echo foo > $dest2
- json=$(cat .attrs.json)
+ json=$(cat $NIX_ATTRS_JSON_FILE)
[[ $json =~ '"narHash":"sha256:1r7yc43zqnzl5b0als5vnyp649gk17i37s7mj00xr8kc47rjcybk"' ]]
[[ $json =~ '"narSize":288' ]]
[[ $json =~ '"closureSize":288' ]]
diff --git a/tests/structured-attrs.sh b/tests/structured-attrs.sh
index dcfe6d580..e585ce37f 100644
--- a/tests/structured-attrs.sh
+++ b/tests/structured-attrs.sh
@@ -1,5 +1,9 @@
source common.sh
+# 27ce722638 required some incompatible changes to the nix file, so skip this
+# tests for the older versions
+requireDaemonNewerThan "2.4pre20210622"
+
clearStore
rm -f $TEST_ROOT/result
@@ -8,3 +12,12 @@ nix-build structured-attrs.nix -A all -o $TEST_ROOT/result
[[ $(cat $TEST_ROOT/result/foo) = bar ]]
[[ $(cat $TEST_ROOT/result-dev/foo) = foo ]]
+
+export NIX_BUILD_SHELL=$SHELL
+env NIX_PATH=nixpkgs=shell.nix nix-shell structured-attrs-shell.nix \
+ --run 'test -e .attrs.json; test "3" = "$(jq ".my.list|length" < $NIX_ATTRS_JSON_FILE)"'
+
+# `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`
+# (which is an associative array in thsi case) being fine.
+nix develop -f structured-attrs-shell.nix -c bash -c 'test -n "$out"'
diff --git a/tests/tarball.sh b/tests/tarball.sh
index d53ec8cd9..1301922a5 100644
--- a/tests/tarball.sh
+++ b/tests/tarball.sh
@@ -40,6 +40,11 @@ test_tarball() {
(! nix-instantiate --eval -E '<fnord/xyzzy> 1' -I fnord=file://no-such-tarball$ext)
nix-instantiate --eval -E '<fnord/config.nix>' -I fnord=file://no-such-tarball$ext -I fnord=.
+
+ # Ensure that the `name` attribute isn’t accepted as that would mess
+ # with the content-addressing
+ (! nix-instantiate --eval -E "fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; name = \"foo\"; }")
+
}
test_tarball '' cat
diff --git a/tests/timeout.sh b/tests/timeout.sh
index eea9b5731..e3fb3ebcc 100644
--- a/tests/timeout.sh
+++ b/tests/timeout.sh
@@ -2,6 +2,8 @@
source common.sh
+# XXX: This shouldn’t be, but #4813 cause this test to fail
+needLocalStore "see #4813"
set +e
messages=$(nix-build -Q timeout.nix -A infiniteLoop --timeout 2 2>&1)