From c3090bc6fdf6e052cd4c56fce6aeb11ddeb5dd6f Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 24 Mar 2021 14:44:20 +0100 Subject: tests/*: show when tests are skipped --- tests/build-remote.sh | 4 ++-- tests/gc-runtime.sh | 2 +- tests/linux-sandbox.sh | 4 ++-- tests/recursive.sh | 2 +- tests/shell.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/build-remote.sh b/tests/build-remote.sh index 04848e4b5..70f82e939 100644 --- a/tests/build-remote.sh +++ b/tests/build-remote.sh @@ -1,5 +1,5 @@ -if ! canUseSandbox; then exit; fi -if ! [[ $busybox =~ busybox ]]; then exit; fi +if ! canUseSandbox; then exit 99; fi +if ! [[ $busybox =~ busybox ]]; then exit 99; fi unset NIX_STORE_DIR unset NIX_STATE_DIR diff --git a/tests/gc-runtime.sh b/tests/gc-runtime.sh index 4c5028005..6094959cb 100644 --- a/tests/gc-runtime.sh +++ b/tests/gc-runtime.sh @@ -4,7 +4,7 @@ case $system in *linux*) ;; *) - exit 0; + exit 99; esac set -m # enable job control, needed for kill diff --git a/tests/linux-sandbox.sh b/tests/linux-sandbox.sh index 70a90a907..eac62d461 100644 --- a/tests/linux-sandbox.sh +++ b/tests/linux-sandbox.sh @@ -2,13 +2,13 @@ source common.sh clearStore -if ! canUseSandbox; then exit; fi +if ! canUseSandbox; then exit 99; fi # Note: we need to bind-mount $SHELL into the chroot. Currently we # only support the case where $SHELL is in the Nix store, because # otherwise things get complicated (e.g. if it's in /bin, do we need # /lib as well?). -if [[ ! $SHELL =~ /nix/store ]]; then exit; fi +if [[ ! $SHELL =~ /nix/store ]]; then exit 99; fi chmod -R u+w $TEST_ROOT/store0 || true rm -rf $TEST_ROOT/store0 diff --git a/tests/recursive.sh b/tests/recursive.sh index b020ec710..a55b061b5 100644 --- a/tests/recursive.sh +++ b/tests/recursive.sh @@ -1,7 +1,7 @@ source common.sh # FIXME -if [[ $(uname) != Linux ]]; then exit; fi +if [[ $(uname) != Linux ]]; then exit 99; fi clearStore diff --git a/tests/shell.sh b/tests/shell.sh index 7a9ee8ab0..2b85bb337 100644 --- a/tests/shell.sh +++ b/tests/shell.sh @@ -6,7 +6,7 @@ clearCache nix shell -f shell-hello.nix hello -c hello | grep 'Hello World' nix shell -f shell-hello.nix hello -c hello NixOS | grep 'Hello NixOS' -if ! canUseSandbox; then exit; fi +if ! canUseSandbox; then exit 99; fi chmod -R u+w $TEST_ROOT/store0 || true rm -rf $TEST_ROOT/store0 -- cgit v1.2.3 From c2dfda007e777a33cd487a5631f0d143f915dd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Fri, 9 Apr 2021 23:13:08 +0200 Subject: add tests for zstd compression --- tests/local.mk | 1 + tests/zstd.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/zstd.sh (limited to 'tests') diff --git a/tests/local.mk b/tests/local.mk index aa8b4f9bf..82894af78 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -27,6 +27,7 @@ nix_tests = \ signing.sh \ shell.sh \ brotli.sh \ + zstd.sh \ pure-eval.sh \ check.sh \ plugins.sh \ diff --git a/tests/zstd.sh b/tests/zstd.sh new file mode 100644 index 000000000..ba7c20501 --- /dev/null +++ b/tests/zstd.sh @@ -0,0 +1,28 @@ +source common.sh + +clearStore +clearCache + +cacheURI="file://$cacheDir?compression=zstd" + +outPath=$(nix-build dependencies.nix --no-out-link) + +nix copy --to $cacheURI $outPath + +HASH=$(nix hash path $outPath) + +clearStore +clearCacheCache + +nix copy --from $cacheURI $outPath --no-check-sigs + +if ls $cacheDir/nar/*.zst &> /dev/null; then + echo "files do exist" +else + echo "nars do not exist" + exit 1 +fi + +HASH2=$(nix hash path $outPath) + +[[ $HASH = $HASH2 ]] -- cgit v1.2.3 From b1711071d1a22a1c28448823634b0dc7212e4fe5 Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 22 Apr 2021 17:54:02 +0200 Subject: Add a regression test for #4725 --- tests/ca/substitute.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh index b44fe499a..5d0fc6a87 100644 --- a/tests/ca/substitute.sh +++ b/tests/ca/substitute.sh @@ -8,7 +8,8 @@ sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_D rm -rf $TEST_ROOT/binary_cache -export REMOTE_STORE=file://$TEST_ROOT/binary_cache +export REMOTE_STORE_DIR=$TEST_ROOT/binary_cache +export REMOTE_STORE=file://$REMOTE_STORE_DIR buildDrvs () { nix build --file ./content-addressed.nix -L --no-link "$@" @@ -22,3 +23,20 @@ buildDrvs --post-build-hook ../push-to-store.sh clearStore buildDrvs --substitute --substituters $REMOTE_STORE --no-require-sigs -j0 +# Same thing, but +# 1. With non-ca derivations +# 2. Erasing the realisations on the remote store +# +# Even in that case, realising the derivations should still produce the right +# realisations on the local store +# +# Regression test for #4725 +clearStore +nix build --file ../simple.nix -L --no-link --post-build-hook ../push-to-store.sh +clearStore +rm -r "$REMOTE_STORE_DIR/realisations" +nix build --file ../simple.nix -L --no-link --substitute --substituters "$REMOTE_STORE" --no-require-sigs -j0 +if [[ $(sqlite3 "$NIX_STATE_DIR/db/db.sqlite" 'select count(*) from Realisations') -eq 0 ]]; then + echo "Realisations not rebuilt" + exit 1 +fi -- cgit v1.2.3 From 6ea9c65aece0b65825c99738340ea4944d083234 Mon Sep 17 00:00:00 2001 From: regnat Date: Fri, 23 Apr 2021 09:34:16 +0200 Subject: fixup! Add a regression test for #4725 --- tests/ca/substitute.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh index 5d0fc6a87..737c851a5 100644 --- a/tests/ca/substitute.sh +++ b/tests/ca/substitute.sh @@ -36,7 +36,12 @@ nix build --file ../simple.nix -L --no-link --post-build-hook ../push-to-store.s clearStore rm -r "$REMOTE_STORE_DIR/realisations" nix build --file ../simple.nix -L --no-link --substitute --substituters "$REMOTE_STORE" --no-require-sigs -j0 -if [[ $(sqlite3 "$NIX_STATE_DIR/db/db.sqlite" 'select count(*) from Realisations') -eq 0 ]]; then +# There's no easy way to check whether a realisation is present on the local +# store − short of manually querying the db, but the build environment doesn't +# have the sqlite binary − so we instead push things again, and check that the +# realisations have correctly been pushed to the remote store +nix copy --to "$REMOTE_STORE" --file ../simple.nix +if [[ -z "$(ls "$REMOTE_STORE_DIR/realisations")" ]]; then echo "Realisations not rebuilt" exit 1 fi -- cgit v1.2.3 From bf485dcf460cd0df113c33f36c9f1f29d6e3a2d5 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 5 May 2021 21:00:08 +0200 Subject: Properly normalize the content-addressed paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that their timestamp are always normalized. Otherwise, strange − and non-deterministic − things might happen, like https://github.com/NixOS/nixpkgs/issues/121813 Fix #4775 --- tests/build.sh | 7 +++++++ tests/ca/build.sh | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/build.sh b/tests/build.sh index aa54b88eb..ce9d6602c 100644 --- a/tests/build.sh +++ b/tests/build.sh @@ -10,3 +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) + test "$(stat -c %Y $outPath)" -eq 1 +} +testNormalization diff --git a/tests/ca/build.sh b/tests/ca/build.sh index 35bf1dcf7..c8877f87f 100644 --- a/tests/ca/build.sh +++ b/tests/ca/build.sh @@ -59,9 +59,17 @@ testNixCommand () { nix build --experimental-features 'nix-command ca-derivations' --file ./content-addressed.nix --no-link } +# Regression test for https://github.com/NixOS/nix/issues/4775 +testNormalization () { + clearStore + outPath=$(buildAttr rootCA 1) + test "$(stat -c %Y $outPath)" -eq 1 +} + # Disabled until we have it properly working # testRemoteCache clearStore +testNormalization testDeterministicCA clearStore testCutoff -- cgit v1.2.3 From b66234134fadc720d6c177d62e6ce4c9f4093a89 Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 6 May 2021 16:45:09 +0200 Subject: Add a realisations disk cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to the nar-info disk cache (and using the same db). This makes rebuilds muuch faster. - This works regardless of the ca-derivations experimental feature. I could modify the logic to not touch the db if the flag isn’t there, but given that this is a trash-able local cache, it doesn’t seem to be really worth it. - We could unify the `NARs` and `Realisation` tables to only have one generic kv table. This is left as an exercise to the reader. - I didn’t update the cache db version number as the new schema just adds a new table to the previous one, so the db will be transparently migrated and is backwards-compatible. Fix #4746 --- tests/ca/substitute.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh index 737c851a5..dfc4ea68e 100644 --- a/tests/ca/substitute.sh +++ b/tests/ca/substitute.sh @@ -45,3 +45,16 @@ if [[ -z "$(ls "$REMOTE_STORE_DIR/realisations")" ]]; then echo "Realisations not rebuilt" exit 1 fi + +# Test the local realisation disk cache +buildDrvs --post-build-hook ../push-to-store.sh +clearStore +# Add the realisations of rootCA to the cachecache +clearCacheCache +export _NIX_FORCE_HTTP=1 +buildDrvs --substitute --substituters $REMOTE_STORE --no-require-sigs -j0 +# Try rebuilding, but remove the realisations from the remote cache to force +# using the cachecache +clearStore +rm $REMOTE_STORE_DIR/realisations/* +buildDrvs --substitute --substituters $REMOTE_STORE --no-require-sigs -j0 -- cgit v1.2.3 From 7f7f99f3505ba9bc3d330fe32d3e697a2ad45446 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 10 May 2021 11:47:00 +0200 Subject: Implement `builtins.floor` and `builtins.ceil` using the C library functions internally Closes #4782 Note: even though the type is internally called `NixFloat`, it's actually a `double`. --- tests/lang/eval-okay-floor-ceil.exp | 1 + tests/lang/eval-okay-floor-ceil.nix | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/lang/eval-okay-floor-ceil.exp create mode 100644 tests/lang/eval-okay-floor-ceil.nix (limited to 'tests') diff --git a/tests/lang/eval-okay-floor-ceil.exp b/tests/lang/eval-okay-floor-ceil.exp new file mode 100644 index 000000000..81f80420b --- /dev/null +++ b/tests/lang/eval-okay-floor-ceil.exp @@ -0,0 +1 @@ +"23;24;23;23" diff --git a/tests/lang/eval-okay-floor-ceil.nix b/tests/lang/eval-okay-floor-ceil.nix new file mode 100644 index 000000000..d76a0d86e --- /dev/null +++ b/tests/lang/eval-okay-floor-ceil.nix @@ -0,0 +1,9 @@ +with import ./lib.nix; + +let + n1 = builtins.floor 23.5; + n2 = builtins.ceil 23.5; + n3 = builtins.floor 23; + n4 = builtins.ceil 23; +in + builtins.concatStringsSep ";" (map toString [ n1 n2 n3 n4 ]) -- cgit v1.2.3 From f46adb783c939c61a087cdfd8af964f4ad6f9816 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 11 May 2021 10:52:17 +0200 Subject: Add a test for `nix run` with CA derivations --- tests/ca/config.nix.in | 1 + tests/ca/content-addressed.nix | 34 ++++++++++++++++++++-------------- tests/ca/flake.nix | 3 +++ tests/ca/nix-run.sh | 9 +++++++++ tests/local.mk | 5 +++-- 5 files changed, 36 insertions(+), 16 deletions(-) create mode 120000 tests/ca/config.nix.in create mode 100644 tests/ca/flake.nix create mode 100755 tests/ca/nix-run.sh (limited to 'tests') diff --git a/tests/ca/config.nix.in b/tests/ca/config.nix.in new file mode 120000 index 000000000..af24ddb30 --- /dev/null +++ b/tests/ca/config.nix.in @@ -0,0 +1 @@ +../config.nix.in \ No newline at end of file diff --git a/tests/ca/content-addressed.nix b/tests/ca/content-addressed.nix index e5b1c4de3..d328fc92c 100644 --- a/tests/ca/content-addressed.nix +++ b/tests/ca/content-addressed.nix @@ -1,4 +1,11 @@ -with import ../config.nix; +with import ./config.nix; + +let mkCADerivation = args: mkDerivation ({ + __contentAddressed = true; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; +} // args); +in { seed ? 0 }: # A simple content-addressed derivation. @@ -14,7 +21,7 @@ rec { echo "Hello World" > $out/hello ''; }; - rootCA = mkDerivation { + rootCA = mkCADerivation { name = "rootCA"; outputs = [ "out" "dev" "foo"]; buildCommand = '' @@ -27,11 +34,8 @@ rec { ln -s $out $dev ln -s $out $foo ''; - __contentAddressed = true; - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; }; - dependentCA = mkDerivation { + dependentCA = mkCADerivation { name = "dependent"; buildCommand = '' echo "building a dependent derivation" @@ -39,20 +43,14 @@ rec { cat ${rootCA}/self/dep echo ${rootCA}/self/dep > $out/dep ''; - __contentAddressed = true; - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; }; - transitivelyDependentCA = mkDerivation { + transitivelyDependentCA = mkCADerivation { name = "transitively-dependent"; buildCommand = '' echo "building transitively-dependent" cat ${dependentCA}/dep echo ${dependentCA} > $out ''; - __contentAddressed = true; - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; }; dependentNonCA = mkDerivation { name = "dependent-non-ca"; @@ -72,6 +70,14 @@ rec { cat ${dependentCA}/dep echo foo > $out ''; - + }; + runnable = mkCADerivation rec { + name = "runnable-thing"; + buildCommand = '' + mkdir -p $out/bin + echo ${rootCA} # Just to make it depend on it + echo "" > $out/bin/${name} + chmod +x $out/bin/${name} + ''; }; } diff --git a/tests/ca/flake.nix b/tests/ca/flake.nix new file mode 100644 index 000000000..332c92a67 --- /dev/null +++ b/tests/ca/flake.nix @@ -0,0 +1,3 @@ +{ + outputs = { self }: import ./content-addressed.nix {}; +} diff --git a/tests/ca/nix-run.sh b/tests/ca/nix-run.sh new file mode 100755 index 000000000..81402af10 --- /dev/null +++ b/tests/ca/nix-run.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +source common.sh + +sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf + +FLAKE_PATH=path:$PWD + +nix run --no-write-lock-file $FLAKE_PATH#runnable diff --git a/tests/local.mk b/tests/local.mk index e2c94dde6..542be6b7e 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -46,6 +46,7 @@ nix_tests = \ ca/build.sh \ ca/substitute.sh \ ca/signatures.sh \ + ca/nix-run.sh \ ca/nix-copy.sh # parallel.sh @@ -53,6 +54,6 @@ install-tests += $(foreach x, $(nix_tests), tests/$(x)) tests-environment = NIX_REMOTE= $(bash) -e -clean-files += $(d)/common.sh $(d)/config.nix +clean-files += $(d)/common.sh $(d)/config.nix $(d)/ca/config.nix -test-deps += tests/common.sh tests/config.nix tests/plugins/libplugintest.$(SO_EXT) +test-deps += tests/common.sh tests/config.nix tests/ca/config.nix tests/plugins/libplugintest.$(SO_EXT) -- cgit v1.2.3 From a22755721b51949dbf03bc1eb156d6f37dc10bac Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 19 May 2021 14:51:34 +0200 Subject: Recursively substitute the realisations Make sure that whenever we substitute a realisation, we also substitute its entire closure --- tests/ca/substitute.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh index dfc4ea68e..c80feaacf 100644 --- a/tests/ca/substitute.sh +++ b/tests/ca/substitute.sh @@ -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 -- cgit v1.2.3 From 4da9ec772c54f17ac04bbc5bcb75140d13a29500 Mon Sep 17 00:00:00 2001 From: Timothy Klim Date: Sat, 29 May 2021 16:03:26 +0700 Subject: Add .tar.zst support for TarballInputScheme --- tests/lang/parse-okay-url.nix | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/lang/parse-okay-url.nix b/tests/lang/parse-okay-url.nix index fce3b13ee..08de27d0a 100644 --- a/tests/lang/parse-okay-url.nix +++ b/tests/lang/parse-okay-url.nix @@ -3,5 +3,6 @@ http://www2.mplayerhq.hu/MPlayer/releases/fonts/font-arial-iso-8859-1.tar.bz2 http://losser.st-lab.cs.uu.nl/~armijn/.nix/gcc-3.3.4-static-nix.tar.gz http://fpdownload.macromedia.com/get/shockwave/flash/english/linux/7.0r25/install_flash_player_7_linux.tar.gz + https://ftp5.gwdg.de/pub/linux/archlinux/extra/os/x86_64/unzip-6.0-14-x86_64.pkg.tar.zst ftp://ftp.gtk.org/pub/gtk/v1.2/gtk+-1.2.10.tar.gz ] -- cgit v1.2.3 From 5985b8b5275605ddd5e92e2f0a7a9f494ac6e35d Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 27 May 2021 13:25:25 +0200 Subject: Check the CA hash when importing stuff in the local store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When adding a path to the local store (via `LocalStore::addToStore`), ensure that the `ca` field of the provided `ValidPathInfo` does indeed correspond to the content of the path. Otherwise any untrusted user (or any binary cache) can add arbitrary content-addressed paths to the store (as content-addressed paths don’t need a signature). --- tests/local.mk | 1 + tests/substitute-with-invalid-ca.sh | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/substitute-with-invalid-ca.sh (limited to 'tests') diff --git a/tests/local.mk b/tests/local.mk index 542be6b7e..59eb4eb0f 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -11,6 +11,7 @@ nix_tests = \ timeout.sh secure-drv-outputs.sh nix-channel.sh \ multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \ binary-cache.sh \ + substitute-with-invalid-ca.sh \ binary-cache-build-remote.sh \ nix-profile.sh repair.sh dump-db.sh case-hack.sh \ check-reqs.sh pass-as-file.sh tarball.sh restricted.sh \ diff --git a/tests/substitute-with-invalid-ca.sh b/tests/substitute-with-invalid-ca.sh new file mode 100644 index 000000000..4d0b01e0f --- /dev/null +++ b/tests/substitute-with-invalid-ca.sh @@ -0,0 +1,38 @@ +source common.sh + +BINARY_CACHE=file://$cacheDir + +getHash() { + basename "$1" | cut -d '-' -f 1 +} +getRemoteNarInfo () { + echo "$cacheDir/$(getHash "$1").narinfo" +} + +cat < $TEST_HOME/good.txt +I’m a good path +EOF + +cat < $TEST_HOME/bad.txt +I’m a bad path +EOF + +good=$(nix-store --add $TEST_HOME/good.txt) +bad=$(nix-store --add $TEST_HOME/bad.txt) +nix copy --to "$BINARY_CACHE" "$good" +nix copy --to "$BINARY_CACHE" "$bad" +nix-collect-garbage >/dev/null 2>&1 + +# Falsifying the narinfo file for '$good' +goodPathNarInfo=$(getRemoteNarInfo "$good") +badPathNarInfo=$(getRemoteNarInfo "$bad") +for fieldName in URL FileHash FileSize NarHash NarSize; do + sed -i "/^$fieldName/d" "$goodPathNarInfo" + grep -E "^$fieldName" "$badPathNarInfo" >> "$goodPathNarInfo" +done + +# Copying back '$good' from the binary cache. This should fail as it is +# corrupted +if nix copy --from "$BINARY_CACHE" "$good"; then + fail "Importing a path with a wrong CA field should fail" +fi -- cgit v1.2.3 From d12b12a15ba5cda49baacd22fbf7f9f526ed74e4 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 2 Jun 2021 10:36:33 +0200 Subject: Let `nix flake check` keep going when keep-going is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the `keep-going` option is set to `true`, make `nix flake check` continue as much as it can before failing. The UI isn’t perfect as-it-is as all the lines currently start with a mostly useless `error (ignored): error:` prefix, but I’m not sure what the best output would be, so I’ll leave it as-it-is for the time being (This is a bit hijacking the `keep-going` flag as it’s supposed to be a build-time only thing. But I think it’s faire to reuse it here). Fix https://github.com/NixOS/nix/issues/4450 --- tests/flakes.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index e78e4a39d..9764e1a6c 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -535,6 +535,21 @@ EOF (! nix flake check $flake3Dir) +cat > $flake3Dir/flake.nix <&1 && fail "nix flake check should have failed" || true) +echo "$checkRes" | grep -q "defaultPackage.system-1" +echo "$checkRes" | grep -q "defaultPackage.system-2" + # Test 'follows' inputs. cat > $flake3Dir/flake.nix < Date: Fri, 11 Jun 2021 08:37:59 +0200 Subject: Add a ca-derivations required machine feature Make ca-derivations require a `ca-derivations` machine feature, and ca-aware builders expose it. That way, a network of builders can mix ca-aware and non-ca-aware machines, and the scheduler will send them in the right place. --- tests/build-remote-content-addressed-floating.sh | 2 ++ tests/build-remote.sh | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'tests') 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 -- cgit v1.2.3 From 56605b468868b834e44a9700907b734428cb120a Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 20 May 2021 13:55:00 +0200 Subject: Make `nix-shell` support content-addressed derivations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolve the derivation before trying to load its environment − essentially reproducing what the build loop does − so that we can effectively access our dependencies (and not just their placeholders). Fix #4821 --- tests/ca/nix-shell.sh | 10 ++++++++++ tests/local.mk | 1 + tests/nix-shell.sh | 14 ++++++++++---- tests/shell.nix | 16 ++++++++++++++-- 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100755 tests/ca/nix-shell.sh (limited to 'tests') 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/local.mk b/tests/local.mk index 59eb4eb0f..d640bdd3c 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -47,6 +47,7 @@ nix_tests = \ ca/build.sh \ ca/substitute.sh \ ca/signatures.sh \ + ca/nix-shell.sh \ ca/nix-run.sh \ ca/nix-copy.sh # parallel.sh diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index 4775bafb9..e3174dac1 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -2,6 +2,12 @@ source common.sh clearStore +if [[ -n ${CONTENT_ADDRESSED:-} ]]; then + nix-shell () { + command nix-shell --arg contentAddressed true "$@" + } +fi + # Test nix-shell -A export IMPURE_VAR=foo export SELECTED_IMPURE_VAR=baz @@ -41,7 +47,7 @@ output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo bar --run 'echo "$(f [ "$output" = "foo bar" ] # 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 +55,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 +64,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,7 +72,7 @@ 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) diff --git a/tests/shell.nix b/tests/shell.nix index 24ebcc04c..53759f99a 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -1,6 +1,18 @@ -{ inNixShell ? false }: +{ inNixShell ? false, contentAddressed ? false }: -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" '' -- cgit v1.2.3 From 2cf591a134f3ec6f634b47eeb522f422c64a9d33 Mon Sep 17 00:00:00 2001 From: regnat Date: Fri, 11 Jun 2021 13:31:19 +0200 Subject: Make `nix develop` work with CA derivations Fix #4823 --- tests/nix-shell.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index e3174dac1..3481c2c69 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -6,6 +6,14 @@ 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 @@ -79,13 +87,13 @@ 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'. source <(nix print-dev-env -f shell.nix shellDrv) -- cgit v1.2.3 From a3ce88725b44a30184cbe8706fc3a53a8610cc47 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 15 Jun 2021 12:11:31 +0200 Subject: Add a test for the gc with CA derivations Also add a small architecture to easily run CA-enabled tests --- tests/ca/gc.sh | 12 ++++++++++++ tests/config.nix.in | 11 ++++++++++- tests/local.mk | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 tests/ca/gc.sh (limited to 'tests') diff --git a/tests/ca/gc.sh b/tests/ca/gc.sh new file mode 100755 index 000000000..e4f9857d6 --- /dev/null +++ b/tests/ca/gc.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Ensure that garbage collection works properly with ca derivations + +source common.sh + +sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf + +export NIX_TESTS_CA_BY_DEFAULT=1 + +cd .. +source gc.sh diff --git a/tests/config.nix.in b/tests/config.nix.in index a57a8c596..9b00d9ddb 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@"; @@ -15,4 +24,4 @@ rec { PATH = path; } // removeAttrs args ["builder" "meta"]) // { meta = args.meta or {}; }; -} +} // caArgs diff --git a/tests/local.mk b/tests/local.mk index 59eb4eb0f..e40178b80 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 \ -- cgit v1.2.3 From 769ca4e26d973660756de85b51efdb7fc36a00fd Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 17 Jun 2021 12:00:26 -0600 Subject: libfetchers/git: fetch submodules by default --- tests/fetchGitSubmodules.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/fetchGitSubmodules.sh b/tests/fetchGitSubmodules.sh index 5f104355f..03d46088e 100644 --- a/tests/fetchGitSubmodules.sh +++ b/tests/fetchGitSubmodules.sh @@ -42,8 +42,8 @@ r1=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \ r2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath") r3=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") -[[ $r1 == $r2 ]] -[[ $r2 != $r3 ]] +[[ $r1 == $r3 ]] +[[ $r2 != $r1 ]] r4=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; }).outPath") r5=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = false; }).outPath") @@ -52,13 +52,13 @@ r7=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; ref = \"master r8=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).outPath") [[ $r1 == $r4 ]] -[[ $r4 == $r5 ]] +[[ $r4 == $r6 ]] [[ $r3 == $r6 ]] [[ $r6 == $r7 ]] [[ $r7 == $r8 ]] have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; }).submodules") -[[ $have_submodules == false ]] +[[ $have_submodules == true ]] have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = false; }).submodules") [[ $have_submodules == false ]] @@ -66,8 +66,8 @@ have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \ have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).submodules") [[ $have_submodules == true ]] -pathWithoutSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath") -pathWithSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") +pathWithoutSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath") +pathWithSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath") pathWithSubmodulesAgain=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath") -- cgit v1.2.3 From 3784c66a46aea2cc3e26b8cff94b3a1f477888f1 Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 21 Jun 2021 15:17:31 +0200 Subject: Remove a possible existing store path when building CA derivations In case a previous interrupted build left a garbage path laying around, remove it before trying to move the path to its final location. Fix #4858 --- tests/ca/build-with-garbage-path.sh | 20 ++++++++++++++++++++ tests/local.mk | 1 + 2 files changed, 21 insertions(+) create mode 100755 tests/ca/build-with-garbage-path.sh (limited to 'tests') diff --git a/tests/ca/build-with-garbage-path.sh b/tests/ca/build-with-garbage-path.sh new file mode 100755 index 000000000..e6f878702 --- /dev/null +++ b/tests/ca/build-with-garbage-path.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Regression test for https://github.com/NixOS/nix/issues/4858 + +source common.sh +sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf + +# 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/local.mk b/tests/local.mk index 59eb4eb0f..663b8c8bc 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -45,6 +45,7 @@ nix_tests = \ build.sh \ compute-levels.sh \ ca/build.sh \ + ca/build-with-garbage-path.sh \ ca/substitute.sh \ ca/signatures.sh \ ca/nix-run.sh \ -- cgit v1.2.3 From 3b5429aec110a22f8fe0d92b72faf1921b8ede2d Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 2 May 2021 17:24:14 +0200 Subject: Source complete env in `nix-shell` with `__structuredAttrs = true;` This is needed to push the adoption of structured attrs[1] forward. It's now checked if a `__json` exists in the environment-map of the derivation to be openend in a `nix-shell`. Derivations with structured attributes enabled also make use of a file named `.attrs.json` containing every environment variable represented as JSON which is useful for e.g. `exportReferencesGraph`[2]. To provide an environment similar to the build sandbox, `nix-shell` now adds a `.attrs.json` to `cwd` (which is mostly equal to the one in the build sandbox) and removes it using an exit hook when closing the shell. To avoid leaking internals of the build-process to the `nix-shell`, the entire logic to generate JSON and shell code for structured attrs was moved into the `ParsedDerivation` class. [1] https://nixos.mayflower.consulting/blog/2020/01/20/structured-attrs/ [2] https://nixos.org/manual/nix/unstable/expressions/advanced-attributes.html#advanced-attributes --- tests/structured-attrs-shell.nix | 19 +++++++++++++++++++ tests/structured-attrs.sh | 6 ++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/structured-attrs-shell.nix (limited to 'tests') diff --git a/tests/structured-attrs-shell.nix b/tests/structured-attrs-shell.nix new file mode 100644 index 000000000..0c01c2568 --- /dev/null +++ b/tests/structured-attrs-shell.nix @@ -0,0 +1,19 @@ +with import ./config.nix; +let + dep = mkDerivation { + name = "dep"; + buildCommand = '' + mkdir $out; echo bla > $out/bla + ''; + }; +in +mkDerivation { + name = "structured2"; + __structuredAttrs = true; + outputs = [ "out" "dev" ]; + my.list = [ "a" "b" "c" ]; + exportReferencesGraph.refs = [ dep ]; + buildCommand = '' + touch ''${outputs[out]}; touch ''${outputs[dev]} + ''; +} diff --git a/tests/structured-attrs.sh b/tests/structured-attrs.sh index dcfe6d580..c0fcb021a 100644 --- a/tests/structured-attrs.sh +++ b/tests/structured-attrs.sh @@ -8,3 +8,9 @@ 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 +[[ ! -e '.attrs.json' ]] +env NIX_PATH=nixpkgs=shell.nix nix-shell structured-attrs-shell.nix \ + --run 'test -e .attrs.json; test "3" = "$(jq ".my.list|length" < .attrs.json)"' +[[ ! -e '.attrs.json' ]] -- cgit v1.2.3 From 3944a120ec6986c723bf36bfade9b331dd4af68a Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 9 May 2021 17:46:16 +0200 Subject: Set environment variables for .attrs.json & .attrs.sh This way no derivation has to expect that these files are in the `cwd` during the build. This is problematic for `nix-shell` where these files would have to be inserted into the nix-shell's `cwd` which can become problematic with e.g. recursive `nix-shell`. To remain backwards-compatible, the location inside the build sandbox will be kept, however using these files directly should be deprecated from now on. --- tests/structured-attrs.nix | 2 +- tests/structured-attrs.sh | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/structured-attrs.nix b/tests/structured-attrs.nix index c39c3a346..f69ee45e9 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 $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 c0fcb021a..241835539 100644 --- a/tests/structured-attrs.sh +++ b/tests/structured-attrs.sh @@ -10,7 +10,5 @@ nix-build structured-attrs.nix -A all -o $TEST_ROOT/result [[ $(cat $TEST_ROOT/result-dev/foo) = foo ]] export NIX_BUILD_SHELL=$SHELL -[[ ! -e '.attrs.json' ]] env NIX_PATH=nixpkgs=shell.nix nix-shell structured-attrs-shell.nix \ - --run 'test -e .attrs.json; test "3" = "$(jq ".my.list|length" < .attrs.json)"' -[[ ! -e '.attrs.json' ]] + --run 'test -e .attrs.json; test "3" = "$(jq ".my.list|length" < $ATTRS_JSON_FILE)"' -- cgit v1.2.3 From 3504c811a55ecd58e0712cf24829c67c192f5e80 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 18 May 2021 15:07:30 +0200 Subject: Add testcase for `nix develop` with `__structuredAttrs` --- tests/shell.nix | 8 ++++++++ tests/structured-attrs-shell.nix | 2 ++ tests/structured-attrs.sh | 5 +++++ 3 files changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/shell.nix b/tests/shell.nix index 24ebcc04c..53a32059b 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -8,6 +8,14 @@ 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 "''${ATTRS_SH_FILE}" ]; then + for o in "''${!outputs[@]}"; do + eval "''${o}=''${outputs[$o]}" + export "''${o}" + done + fi ''; stdenv = mkDerivation { diff --git a/tests/structured-attrs-shell.nix b/tests/structured-attrs-shell.nix index 0c01c2568..57c1e6bd2 100644 --- a/tests/structured-attrs-shell.nix +++ b/tests/structured-attrs-shell.nix @@ -6,10 +6,12 @@ let 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 ]; diff --git a/tests/structured-attrs.sh b/tests/structured-attrs.sh index 241835539..f851b3cbb 100644 --- a/tests/structured-attrs.sh +++ b/tests/structured-attrs.sh @@ -12,3 +12,8 @@ nix-build structured-attrs.nix -A all -o $TEST_ROOT/result 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" < $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"' -- cgit v1.2.3 From 27ce722638eeabb987bc9b4a1234c2818c5bf401 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 22 Jun 2021 19:45:08 +0200 Subject: Prefix env vars for attrs.* files with NIX_ --- tests/shell.nix | 2 +- tests/structured-attrs.nix | 2 +- tests/structured-attrs.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/shell.nix b/tests/shell.nix index 53a32059b..4581fa40a 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -10,7 +10,7 @@ let pkgs = rec { done # mimic behavior of stdenv for `$out` etc. for structured attrs. - if [ -n "''${ATTRS_SH_FILE}" ]; then + if [ -n "''${NIX_ATTRS_SH_FILE}" ]; then for o in "''${!outputs[@]}"; do eval "''${o}=''${outputs[$o]}" export "''${o}" diff --git a/tests/structured-attrs.nix b/tests/structured-attrs.nix index f69ee45e9..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_FILE) + 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 f851b3cbb..9612020b8 100644 --- a/tests/structured-attrs.sh +++ b/tests/structured-attrs.sh @@ -11,7 +11,7 @@ nix-build structured-attrs.nix -A all -o $TEST_ROOT/result 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" < $ATTRS_JSON_FILE)"' + --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` -- cgit v1.2.3 From a5df669bc685834b16de0ab57723ff734c10d2f7 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 19 May 2021 13:35:46 +0200 Subject: =?UTF-8?q?Add=20a=20test=20for=20the=20=E2=80=9Ctwo=20glibc?= =?UTF-8?q?=E2=80=9D=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/ca/duplicate-realisation-in-closure.sh | 26 +++++++++++++++++++++ tests/ca/nondeterministic.nix | 35 ++++++++++++++++++++++++++++ tests/local.mk | 1 + 3 files changed, 62 insertions(+) create mode 100644 tests/ca/duplicate-realisation-in-closure.sh create mode 100644 tests/ca/nondeterministic.nix (limited to 'tests') diff --git a/tests/ca/duplicate-realisation-in-closure.sh b/tests/ca/duplicate-realisation-in-closure.sh new file mode 100644 index 000000000..bfe2a4e08 --- /dev/null +++ b/tests/ca/duplicate-realisation-in-closure.sh @@ -0,0 +1,26 @@ +source ./common.sh + +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 + +# 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 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/local.mk b/tests/local.mk index 0d594cda0..e7161d298 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -47,6 +47,7 @@ nix_tests = \ compute-levels.sh \ ca/build.sh \ ca/build-with-garbage-path.sh \ + ca/duplicate-realisation-in-closure.sh \ ca/substitute.sh \ ca/signatures.sh \ ca/nix-run.sh \ -- cgit v1.2.3 From fd3f5e9085737734d8769c21559461c26dc5a165 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 23 Jun 2021 17:36:50 +0200 Subject: Make the CA tests actuall test CA derivations Fix a mistake in config.nix that was preventing `NIX_TESTS_CA_BY_DEFAULT` from having any meaningful effect --- tests/config.nix.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/config.nix.in b/tests/config.nix.in index 9b00d9ddb..7facbdcbc 100644 --- a/tests/config.nix.in +++ b/tests/config.nix.in @@ -22,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 {}; }; -} // caArgs +} -- cgit v1.2.3 From 01a3f4d7ec79d434dc34b64a761ddf681fe63a48 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 23 Jun 2021 17:37:29 +0200 Subject: Fix the CA gc test Broken by https://github.com/NixOS/nix/issues/4936 --- tests/gc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') 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 -- cgit v1.2.3 From be7a4a6a1303ddbd1f8942f02c04f69016c51da0 Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 24 Jun 2021 11:41:51 +0200 Subject: Make the post-build-hook also run for unresolved CA derivations Fix #4837 --- tests/ca/post-hook.sh | 11 +++++++++++ tests/local.mk | 1 + tests/post-hook.sh | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100755 tests/ca/post-hook.sh (limited to 'tests') diff --git a/tests/ca/post-hook.sh b/tests/ca/post-hook.sh new file mode 100755 index 000000000..4b8da4cd8 --- /dev/null +++ b/tests/ca/post-hook.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +source common.sh + +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/local.mk b/tests/local.mk index 82cec1df3..35ee9e271 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -39,6 +39,7 @@ nix_tests = \ search.sh \ nix-copy-ssh.sh \ post-hook.sh \ + ca/post-hook.sh \ function-trace.sh \ recursive.sh \ describe-stores.sh \ diff --git a/tests/post-hook.sh b/tests/post-hook.sh index aa3e6a574..238a8f826 100644 --- a/tests/post-hook.sh +++ b/tests/post-hook.sh @@ -4,7 +4,7 @@ clearStore rm -f $TEST_ROOT/result -export REMOTE_STORE=$TEST_ROOT/remote_store +export REMOTE_STORE=file:$TEST_ROOT/remote_store # 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 -- cgit v1.2.3 From 7746cb13dc4e644c9792b3e3666cd49635d694e0 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 23 Jun 2021 17:27:18 +0200 Subject: Make CA derivations compatible with recursive Nix Add an access-control list to the realisations in recursive-nix (similar to the already existing one for store paths), so that we can build content-addressed derivations in the restricted store. Fix #4353 --- tests/ca/recursive.sh | 11 +++++++++++ tests/local.mk | 1 + tests/recursive.sh | 17 +++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100755 tests/ca/recursive.sh (limited to 'tests') diff --git a/tests/ca/recursive.sh b/tests/ca/recursive.sh new file mode 100755 index 000000000..d9281d91f --- /dev/null +++ b/tests/ca/recursive.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +source common.sh + +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/local.mk b/tests/local.mk index 82cec1df3..4d9d314cc 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -52,6 +52,7 @@ nix_tests = \ ca/signatures.sh \ ca/nix-shell.sh \ ca/nix-run.sh \ + ca/recursive.sh \ ca/nix-copy.sh # parallel.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" ]; } '\'' -- cgit v1.2.3 From bf68c693dc5157c2be1f3a9f407dd1ce3761df78 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 25 Jun 2021 11:17:19 +0200 Subject: tests: Get rid of some result symlinks Fixes error: cannot create symlink '/home/eelco/Dev/nix/tests/result'; already exists --- tests/build.sh | 6 +++--- tests/ca/duplicate-realisation-in-closure.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') 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/duplicate-realisation-in-closure.sh b/tests/ca/duplicate-realisation-in-closure.sh index bfe2a4e08..ca9099641 100644 --- a/tests/ca/duplicate-realisation-in-closure.sh +++ b/tests/ca/duplicate-realisation-in-closure.sh @@ -17,10 +17,10 @@ sleep 2 # To make sure that `$(date)` will be different # 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 +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 +nix build --substituters "$REMOTE_STORE" -f nondeterministic.nix toplevel --no-require-sigs --no-link -- cgit v1.2.3 From d8ad6f1c108ec253b307c30aadee460cf602dbd1 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Fri, 2 Jul 2021 16:10:57 +0300 Subject: Add tests for --registry and second arg for nix registry pin --- tests/flakes.sh | 80 ++++++++------------------------------------------------- 1 file changed, 10 insertions(+), 70 deletions(-) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index 9764e1a6c..a4e657980 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -90,76 +90,14 @@ EOF git -C $nonFlakeDir add README.md git -C $nonFlakeDir commit -m 'Initial' -cat > $registry < Date: Mon, 5 Jul 2021 12:00:08 +0200 Subject: Fix devShell handling of env values including @ and % --- tests/shell.nix | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/shell.nix b/tests/shell.nix index 53759f99a..f174db583 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -34,6 +34,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"]; -- cgit v1.2.3 From 83615fcf8fe6095b60e33097e2d15fb1a3f56298 Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 5 Jul 2021 13:09:46 +0200 Subject: Allow `fetchGit` to take a `name` argument Fix #3388 --- tests/fetchGit.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') 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$ ]] -- cgit v1.2.3 From a487a652ed2f662782529d8f2bea4cf90a05e0c9 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 6 Jul 2021 08:42:47 +0200 Subject: allow fetchTarball to take a `name` argument --- tests/tarball.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/tarball.sh b/tests/tarball.sh index d53ec8cd9..279ef5672 100644 --- a/tests/tarball.sh +++ b/tests/tarball.sh @@ -30,6 +30,7 @@ test_tarball() { nix-build -o $TEST_ROOT/result -E "import (fetchTree file://$tarball)" nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; })" nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })" + nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; name = \"foo\"; })" nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" 2>&1 | grep 'NAR hash mismatch in input' nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2 -- cgit v1.2.3 From e4b082a52b4cd983b50037783a647cf39cd18bdf Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 6 Jul 2021 08:43:06 +0200 Subject: allow fetchMercurial to take a `name` argument --- tests/fetchMercurial.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') 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$ ]] -- cgit v1.2.3 From 02dd6bb610e55a009cd7a4c83639698d3a7acaa2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 7 Jul 2021 10:48:47 +0200 Subject: tests/check.sh: Fix a race Fixes this random failure: error: hash mismatch in fixed-output derivation '/tmp/nix-shell.EUgAVU/nix-test/tests/check/store/sfps3l3c5n7dabpx34kigxnfhmrwk2h6-dummy.drv': specified: sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU= got: sha256-0qhPS4tlCTfsj3PNi+LHSt1akRumTfJ0WO2CKdqASiY= which happens because multiple tests were writing to ./dummy. --- tests/add.sh | 2 +- tests/check.nix | 2 +- tests/check.sh | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'tests') 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/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 { - url = "file://" + toString ./dummy; + url = "file://" + builtins.getEnv "TMPDIR" + "/dummy"; sha256 = "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73"; }; diff --git a/tests/check.sh b/tests/check.sh index 5f4997e28..d26d4d8fc 100644 --- a/tests/check.sh +++ b/tests/check.sh @@ -74,12 +74,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" ] -- cgit v1.2.3 From 6060ea1b0e4346a632b218d74b68ab18c20e100e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 7 Jul 2021 11:30:35 +0200 Subject: Add tests/dummy --- tests/dummy | 1 + tests/init.sh | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 tests/dummy (limited to 'tests') 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/init.sh b/tests/init.sh index 1a6ccb6fe..6e45a939f 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -35,5 +35,3 @@ nix-store --init # Did anything happen? test -e "$NIX_STATE_DIR"/db/db.sqlite - -echo 'Hello World' > ./dummy -- cgit v1.2.3 From 7e5c79a2d210e7b986803d5fe5c7ebb504b3e74e Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 8 Jul 2021 13:29:58 +0200 Subject: Forbid the `name` attribute for fetchTree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to support it for the “old” fetch* functions for backwards compatibility, but we don’t need it for fetchTree (as it’s a new function). Given that changing the `name` messes-up the content hashing, we can just forbid passing a custom `name` argument to it --- tests/tarball.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tarball.sh b/tests/tarball.sh index 279ef5672..1301922a5 100644 --- a/tests/tarball.sh +++ b/tests/tarball.sh @@ -30,7 +30,6 @@ test_tarball() { nix-build -o $TEST_ROOT/result -E "import (fetchTree file://$tarball)" nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; })" nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })" - nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; name = \"foo\"; })" nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" 2>&1 | grep 'NAR hash mismatch in input' nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2 @@ -41,6 +40,11 @@ test_tarball() { (! nix-instantiate --eval -E ' 1' -I fnord=file://no-such-tarball$ext) nix-instantiate --eval -E '' -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 -- cgit v1.2.3 From b1cfe8f984145c836c1dab229c1117d6396a4305 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 8 Jul 2021 17:12:01 +0200 Subject: nix develop: Add a test for arrays --- tests/nix-shell.sh | 1 + tests/shell.nix | 1 + 2 files changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index 3481c2c69..aae7cbcde 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -98,3 +98,4 @@ nix_develop -f shell.nix shellDrv -c echo foo |& grep -q foo # Test 'nix print-dev-env'. source <(nix print-dev-env -f shell.nix shellDrv) [[ -n $stdenv ]] +[[ ${arr1[2]} = "3 4" ]] diff --git a/tests/shell.nix b/tests/shell.nix index f174db583..42d2d2033 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -20,6 +20,7 @@ let pkgs = rec { for pkg in $buildInputs; do export PATH=$PATH:$pkg/bin done + declare -a arr1=(1 2 "3 4" 5) ''; stdenv = mkDerivation { -- cgit v1.2.3 From 9fc7da1e08d83378f8b0d66a060d92929c1468cf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 9 Jul 2021 01:16:55 +0200 Subject: Add test for #4992 --- tests/nix-shell.sh | 2 ++ tests/shell.nix | 1 + 2 files changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index aae7cbcde..728313a8a 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -99,3 +99,5 @@ nix_develop -f shell.nix shellDrv -c echo foo |& grep -q foo source <(nix print-dev-env -f shell.nix shellDrv) [[ -n $stdenv ]] [[ ${arr1[2]} = "3 4" ]] +[[ ${arr2[1]} = $'\n' ]] +[[ ${arr2[2]} = $'x\ny' ]] diff --git a/tests/shell.nix b/tests/shell.nix index 42d2d2033..1f5526253 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -21,6 +21,7 @@ let pkgs = rec { export PATH=$PATH:$pkg/bin done declare -a arr1=(1 2 "3 4" 5) + declare -a arr2=(x $'\n' $'x\ny') ''; stdenv = mkDerivation { -- cgit v1.2.3 From e50408bd3192156e04571a1546d053f998ab4e2c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 9 Jul 2021 01:17:32 +0200 Subject: nix develop: Add a test for bash functions --- tests/nix-shell.sh | 1 + tests/shell.nix | 3 +++ 2 files changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index 728313a8a..ec43db349 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -101,3 +101,4 @@ source <(nix print-dev-env -f shell.nix shellDrv) [[ ${arr1[2]} = "3 4" ]] [[ ${arr2[1]} = $'\n' ]] [[ ${arr2[2]} = $'x\ny' ]] +[[ $(fun) = blabla ]] diff --git a/tests/shell.nix b/tests/shell.nix index 1f5526253..70c60276c 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -22,6 +22,9 @@ let pkgs = rec { done declare -a arr1=(1 2 "3 4" 5) declare -a arr2=(x $'\n' $'x\ny') + fun() { + echo blabla + } ''; stdenv = mkDerivation { -- cgit v1.2.3 From 86fb01c4bee0c4f451504c0f6fd2066d2adc8fc2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 9 Jul 2021 12:10:48 +0200 Subject: nix print-dev-env: Add --json flag --- tests/nix-shell.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index ec43db349..f60102f9c 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -96,6 +96,8 @@ echo foo | nix develop -f shell.nix shellDrv -c cat | 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" ]] -- cgit v1.2.3 From c05bdef020d99da1204629bba7b775553c5d6005 Mon Sep 17 00:00:00 2001 From: regnat Date: Thu, 15 Jul 2021 18:17:18 +0200 Subject: Forward the whole Nix config to the repl subprocesses Fill `NIX_CONFIG` with the value of the current Nix configuration before calling the nix subprocesses in the repl That way the whole configuration (including the possible `experimental-features`, a possibly `--store` option or whatever) will be made available. This is required for example to make `nix repl` work with a custom `--store` --- tests/local.mk | 1 + tests/repl.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/repl.sh (limited to 'tests') diff --git a/tests/local.mk b/tests/local.mk index cbdf4efdb..ce9725543 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -46,6 +46,7 @@ nix_tests = \ flakes.sh \ build.sh \ compute-levels.sh \ + repl.sh \ ca/build.sh \ ca/build-with-garbage-path.sh \ ca/duplicate-realisation-in-closure.sh \ 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" -- cgit v1.2.3 From 3e57e3480b372ed9c5dffc1025eae5773b8691e7 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Fri, 2 Jul 2021 15:36:14 +0300 Subject: Add use-registries config option (and deprecate --no-registries flag) Some people want to avoid using registries at all on their system; Instead of having to add --no-registries to every command, this commit allows to set use-registries = false in the config. --no-registries is still allowed everywhere it was allowed previously, but is now deprecated. Co-authored-by: Eelco Dolstra --- tests/flakes.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index a4e657980..9e1b5b508 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -147,6 +147,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. @@ -170,6 +171,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 @@ -180,6 +182,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 @@ -603,6 +606,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 -- cgit v1.2.3 From 87077739658b35863fb56131fd7099294c181ee5 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 20 Jul 2021 06:57:56 +0200 Subject: Properly lock the builds of CA derivations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that we can’t build the same derivation twice at the same time. Fix https://github.com/NixOS/nix/issues/5029 --- tests/ca/concurrent-builds.sh | 18 ++++++++++++++++++ tests/ca/racy.nix | 15 +++++++++++++++ tests/local.mk | 1 + 3 files changed, 34 insertions(+) create mode 100755 tests/ca/concurrent-builds.sh create mode 100644 tests/ca/racy.nix (limited to 'tests') diff --git a/tests/ca/concurrent-builds.sh b/tests/ca/concurrent-builds.sh new file mode 100755 index 000000000..68441ec76 --- /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 + +sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf + +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/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/local.mk b/tests/local.mk index ce9725543..e16c5a9b7 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -55,6 +55,7 @@ nix_tests = \ ca/nix-shell.sh \ ca/nix-run.sh \ ca/recursive.sh \ + ca/concurrent-builds.sh \ ca/nix-copy.sh # parallel.sh -- cgit v1.2.3 From 29e4913f7947730c468c1d96f150648ec59f572d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 27 Jul 2021 11:17:56 +0200 Subject: Add --eval-store test --- tests/eval-store.sh | 26 ++++++++++++++++++++++++++ tests/local.mk | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/eval-store.sh (limited to 'tests') diff --git a/tests/eval-store.sh b/tests/eval-store.sh new file mode 100644 index 000000000..7bb86d77c --- /dev/null +++ b/tests/eval-store.sh @@ -0,0 +1,26 @@ +source common.sh + +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/local.mk b/tests/local.mk index e16c5a9b7..b100e7f15 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -56,7 +56,8 @@ nix_tests = \ ca/nix-run.sh \ ca/recursive.sh \ ca/concurrent-builds.sh \ - ca/nix-copy.sh + ca/nix-copy.sh \ + eval-store.sh # parallel.sh install-tests += $(foreach x, $(nix_tests), tests/$(x)) -- cgit v1.2.3 From addacfce4a71f33b50b6af321d6a8d67ca44ceed Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 26 Jul 2021 06:54:55 +0200 Subject: Allow running all the tests with the daemon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When `NIX_DAEMON_PACKAGE` is set, make all the tests use the Nix daemon. That way we can test every piece of Nix functionality both with and without the daemon. Tests for which using the daemon isn’t possible or doesn’t make sens can selectively be disabled with `needLocalStore` --- tests/binary-cache.sh | 2 + tests/ca/build-with-garbage-path.sh | 3 +- tests/ca/common.sh | 4 ++ tests/ca/concurrent-builds.sh | 2 +- tests/ca/duplicate-realisation-in-closure.sh | 2 + tests/ca/gc.sh | 2 - tests/ca/post-hook.sh | 2 + tests/ca/recursive.sh | 2 + tests/ca/substitute.sh | 2 +- tests/check.sh | 3 ++ tests/common.sh.in | 57 +++++++++++++++++++++++++++- tests/db-migration.sh | 5 ++- tests/dump-db.sh | 2 + tests/eval-store.sh | 2 + tests/fixed.sh | 3 -- tests/gc-auto.sh | 2 + tests/init.sh | 1 + tests/linux-sandbox.sh | 2 + tests/multiple-outputs.sh | 2 +- tests/optimise-store.sh | 3 +- tests/post-hook.sh | 3 ++ tests/referrers.sh | 2 + tests/repair.sh | 2 + tests/structured-attrs.sh | 4 ++ tests/timeout.sh | 2 + 25 files changed, 103 insertions(+), 13 deletions(-) (limited to 'tests') 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/ca/build-with-garbage-path.sh b/tests/ca/build-with-garbage-path.sh index e6f878702..9aa08a899 100755 --- a/tests/ca/build-with-garbage-path.sh +++ b/tests/ca/build-with-garbage-path.sh @@ -3,7 +3,8 @@ # Regression test for https://github.com/NixOS/nix/issues/4858 source common.sh -sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf + +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)" 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 index 68441ec76..b442619e2 100755 --- a/tests/ca/concurrent-builds.sh +++ b/tests/ca/concurrent-builds.sh @@ -5,7 +5,7 @@ source common.sh -sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf +buggyNeedLocalStore "For some reason, this deadlocks with the daemon" export NIX_TESTS_CA_BY_DEFAULT=1 diff --git a/tests/ca/duplicate-realisation-in-closure.sh b/tests/ca/duplicate-realisation-in-closure.sh index ca9099641..74c5d25fd 100644 --- a/tests/ca/duplicate-realisation-in-closure.sh +++ b/tests/ca/duplicate-realisation-in-closure.sh @@ -1,5 +1,7 @@ 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" diff --git a/tests/ca/gc.sh b/tests/ca/gc.sh index e4f9857d6..e9b6c5ab5 100755 --- a/tests/ca/gc.sh +++ b/tests/ca/gc.sh @@ -4,8 +4,6 @@ source common.sh -sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf - export NIX_TESTS_CA_BY_DEFAULT=1 cd .. diff --git a/tests/ca/post-hook.sh b/tests/ca/post-hook.sh index 4b8da4cd8..1c9d4f700 100755 --- a/tests/ca/post-hook.sh +++ b/tests/ca/post-hook.sh @@ -2,6 +2,8 @@ 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 diff --git a/tests/ca/recursive.sh b/tests/ca/recursive.sh index d9281d91f..648bf0a91 100755 --- a/tests/ca/recursive.sh +++ b/tests/ca/recursive.sh @@ -2,6 +2,8 @@ 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 diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh index c80feaacf..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 diff --git a/tests/check.sh b/tests/check.sh index d26d4d8fc..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) diff --git a/tests/common.sh.in b/tests/common.sh.in index d31d3fbb8..bc2e0931f 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,6 +82,10 @@ 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 @@ -84,20 +95,44 @@ startDaemon() { 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/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/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 index 7bb86d77c..9ab7a87be 100644 --- a/tests/eval-store.sh +++ b/tests/eval-store.sh @@ -1,5 +1,7 @@ source common.sh +requireDaemonNewerThan "2.4pre20210727" + eval_store=$TEST_ROOT/eval-store clearStore 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/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/init.sh b/tests/init.sh index 6e45a939f..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 <> $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/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/structured-attrs.sh b/tests/structured-attrs.sh index 9612020b8..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 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) -- cgit v1.2.3 From c2c0dba792effa4de6ad16950684c1ce80ab6730 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 27 Jul 2021 11:12:32 +0200 Subject: Remove the right socket before starting the daemon For some reason, an old socket occasionally stays here on OSX, causing the subsequent tests to fail --- tests/common.sh.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/common.sh.in b/tests/common.sh.in index bc2e0931f..7daab2460 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -88,10 +88,10 @@ startDaemon() { 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=$! -- cgit v1.2.3 From 6eeb6f9c8494f5d5ef5e4dd228c9121bcbe2c29f Mon Sep 17 00:00:00 2001 From: ldesgoui Date: Sat, 31 Jul 2021 16:55:53 +0200 Subject: nix-shell -p: pass --arg values as nixpkgs params --- tests/nix-shell.sh | 4 ++++ tests/shell.nix | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index f60102f9c..a31d35887 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -54,6 +54,10 @@ 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 chmod a+rx $TEST_ROOT/shell.shebang.sh diff --git a/tests/shell.nix b/tests/shell.nix index 64817ed5c..4912d295a 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -1,4 +1,4 @@ -{ inNixShell ? false, contentAddressed ? false }: +{ inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }: let cfg = import ./config.nix; in with cfg; @@ -62,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 ''; -- cgit v1.2.3 From 624162c72973b2ff63ee4e840c4f20af1e490039 Mon Sep 17 00:00:00 2001 From: Taeer Bar-Yam Date: Fri, 6 Aug 2021 07:06:52 -0400 Subject: add path antiqutations test --- tests/lang/eval-okay-path-antiquotation.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/lang/eval-okay-path-antiquotation.nix (limited to 'tests') 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"}; +} -- cgit v1.2.3 From a6bfda7d956f88f5e38c0848b9dfd8ea0108f26b Mon Sep 17 00:00:00 2001 From: Taeer Bar-Yam Date: Fri, 6 Aug 2021 07:38:52 -0400 Subject: path antiquotations: rename confusing test --- tests/lang/eval-fail-antiquoted-path.nix | 4 ---- tests/lang/eval-fail-nonexist-path.nix | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 tests/lang/eval-fail-antiquoted-path.nix create mode 100644 tests/lang/eval-fail-nonexist-path.nix (limited to 'tests') diff --git a/tests/lang/eval-fail-antiquoted-path.nix b/tests/lang/eval-fail-antiquoted-path.nix deleted file mode 100644 index f2f08107b..000000000 --- a/tests/lang/eval-fail-antiquoted-path.nix +++ /dev/null @@ -1,4 +0,0 @@ -# This must fail to evaluate, since ./fnord doesn't exist. If it did -# exist, it would produce "/nix/store/-fnord/xyzzy" (with an -# appropriate context). -"${./fnord}/xyzzy" diff --git a/tests/lang/eval-fail-nonexist-path.nix b/tests/lang/eval-fail-nonexist-path.nix new file mode 100644 index 000000000..f2f08107b --- /dev/null +++ b/tests/lang/eval-fail-nonexist-path.nix @@ -0,0 +1,4 @@ +# This must fail to evaluate, since ./fnord doesn't exist. If it did +# exist, it would produce "/nix/store/-fnord/xyzzy" (with an +# appropriate context). +"${./fnord}/xyzzy" -- cgit v1.2.3 From d56ddbb99965dc46cb80b05857588624c249aba6 Mon Sep 17 00:00:00 2001 From: Madeline Haraj Date: Fri, 6 Aug 2021 12:36:03 -0400 Subject: Fix disabled case in local store test --- tests/local-store.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/local-store.sh b/tests/local-store.sh index 4ec3d64b0..0247346f1 100644 --- a/tests/local-store.sh +++ b/tests/local-store.sh @@ -15,6 +15,5 @@ PATH1=$(nix path-info --store ./x $CORRECT_PATH) PATH2=$(nix path-info --store "$PWD/x" $CORRECT_PATH) [ $CORRECT_PATH == $PATH2 ] -# FIXME we could also test the query parameter version: -# PATH3=$(nix path-info --store "local?store=$PWD/x" $CORRECT_PATH) -# [ $CORRECT_PATH == $PATH3 ] +PATH3=$(nix path-info --store "local?root=$PWD/x" $CORRECT_PATH) +[ $CORRECT_PATH == $PATH3 ] -- cgit v1.2.3 From 57b9ba0ad0c300e21de3dfe246e8c617b2194bae Mon Sep 17 00:00:00 2001 From: Alex Zero Date: Mon, 12 Jul 2021 02:08:06 +0100 Subject: Add tests for flake follow paths --- tests/flakes.sh | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index 9e1b5b508..f5c7b6804 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -26,10 +26,15 @@ nonFlakeDir=$TEST_ROOT/nonFlake 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" @@ -681,3 +686,89 @@ 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 < $flakeFollowsB/flake.nix < $flakeFollowsC/flake.nix < $flakeFollowsD/flake.nix < $flakeFollowsE/flake.nix < $flakeFollowsA/flake.nix <&1 | grep 'this is a security violation' -- cgit v1.2.3 From ecf9a3e12825b0feaedb130cd6e4b872aae45aaf Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 31 Aug 2021 13:17:01 +0200 Subject: tests/fetchurl.sh: Be verbose to help debug darwin eof bug #2794 --- tests/fetchurl.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') 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 ' --argstr url file://$(pwd)/fetchurl.sh --argstr sha256 $hash --no-out-link) +outPath=$(nix-build -vvvvv --expr 'import ' --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 ' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link) +outPath=$(nix-build -vvvvv --expr 'import ' --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 ' --argstr url file://$(pwd)/fetchurl.sh --argstr hash $hash --no-out-link) +outPath=$(nix-build -vvvvv --expr 'import ' --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 ' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store) +outPath=$(nix-build -vvvvv --expr 'import ' --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 ' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \ +nix-build -vvvvv --expr 'import ' --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 ' --argstr url file://$nar --argstr sha256 $hash \ +outPath=$(nix-build -vvvvv --expr 'import ' --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 ' --argstr url file://$narxz --argstr sha256 $hash \ +outPath=$(nix-build -vvvvv --expr 'import ' --argstr url file://$narxz --argstr sha256 $hash \ --arg unpack true --argstr name xyzzy --no-out-link) test -x $outPath/fetchurl.sh -- cgit v1.2.3 From b2f966f4871cf02c2505afe88a296e429859a7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Mon, 22 Feb 2021 21:05:37 +0100 Subject: Failing test case for flake in store --- tests/flakes.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index f5c7b6804..29f0fe05e 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -23,6 +23,7 @@ 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 @@ -772,3 +773,8 @@ 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 +mkdir $badFlakeDir +echo INVALID > $badFlakeDir/flake.nix +nix store delete $(nix store add-path $badFlakeDir) -- cgit v1.2.3 From b2e8120d25de5303bfb6a99c14d3ecad21f55a05 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Sep 2021 14:01:07 +0200 Subject: parseInstallables(): Parse store paths as store paths If the store path contains a flake, this means that a command like "nix path-info /path" will show info about /path, not about the default output of the flake in /path. If you want the latter, you can explicitly ask for it by doing "nix path-info path:/path". Fixes #4568. --- tests/flakes.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index 29f0fe05e..610bab391 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -775,6 +775,10 @@ 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 ]] -- cgit v1.2.3 From dc25856d7469d8be2ff12a431cd11baedfee72d7 Mon Sep 17 00:00:00 2001 From: Tom Bereknyei Date: Wed, 18 Aug 2021 00:04:55 -0400 Subject: Ensure nix flake show produces valid json --- tests/flakes.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index 9e1b5b508..1bce4e4bd 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -386,12 +386,14 @@ git -C $templatesDir commit -m 'Initial' nix flake check templates nix flake show templates +nix flake show templates --json | jq (cd $flake7Dir && nix flake init) (cd $flake7Dir && nix flake init) # check idempotence git -C $flake7Dir add flake.nix nix flake check $flake7Dir nix flake show $flake7Dir +nix flake show $flake7Dir --json | jq git -C $flake7Dir commit -a -m 'Initial' # Test 'nix flake new'. -- cgit v1.2.3 From 7c8c42dfdcab3bd2c8ab05a806035bf1804285ab Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 13 Sep 2021 14:29:42 +0200 Subject: tests: Fix the recursive test with the daemon Add the `recursive-nix` experimental-feature to the daemon, as the test will otherwise fail --- tests/recursive.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/recursive.sh b/tests/recursive.sh index b6740877d..91518d67d 100644 --- a/tests/recursive.sh +++ b/tests/recursive.sh @@ -1,5 +1,8 @@ source common.sh +sed -i 's/experimental-features .*/& recursive-nix/' "$NIX_CONF_DIR"/nix.conf +restartDaemon + # FIXME if [[ $(uname) != Linux ]]; then exit 99; fi -- cgit v1.2.3 From 5cbb9c5406f3058fcc9f99692490fbc5a4f57876 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 21 Sep 2021 13:19:26 +0200 Subject: path fetcher: Fix relative path check --- tests/flakes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/flakes.sh b/tests/flakes.sh index 2ede7f72c..26cdf27b7 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -766,7 +766,7 @@ cat > $flakeFollowsA/flake.nix <&1 | grep 'this is a security violation' +nix flake lock $flakeFollowsA 2>&1 | grep 'points outside' # Test flake in store does not evaluate rm -rf $badFlakeDir -- cgit v1.2.3 From d1bf7431bbb9c38bdb577661d8511d506a3955c4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 22 Sep 2021 17:25:25 +0200 Subject: Revert "Merge pull request #4922 from nrdxp/default-submodules" This reverts commit 6678e98411cd3bfe8143a4ba1b35d1451babce32, reversing changes made to 90b2dd570cbd8313a8cf45b3cf66ddef2bb06e07. --- tests/fetchGitSubmodules.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/fetchGitSubmodules.sh b/tests/fetchGitSubmodules.sh index 03d46088e..5f104355f 100644 --- a/tests/fetchGitSubmodules.sh +++ b/tests/fetchGitSubmodules.sh @@ -42,8 +42,8 @@ r1=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \ r2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath") r3=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") -[[ $r1 == $r3 ]] -[[ $r2 != $r1 ]] +[[ $r1 == $r2 ]] +[[ $r2 != $r3 ]] r4=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; }).outPath") r5=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = false; }).outPath") @@ -52,13 +52,13 @@ r7=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; ref = \"master r8=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).outPath") [[ $r1 == $r4 ]] -[[ $r4 == $r6 ]] +[[ $r4 == $r5 ]] [[ $r3 == $r6 ]] [[ $r6 == $r7 ]] [[ $r7 == $r8 ]] have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; }).submodules") -[[ $have_submodules == true ]] +[[ $have_submodules == false ]] have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = false; }).submodules") [[ $have_submodules == false ]] @@ -66,8 +66,8 @@ have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \ have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).submodules") [[ $have_submodules == true ]] -pathWithoutSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath") -pathWithSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath") +pathWithoutSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath") +pathWithSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") pathWithSubmodulesAgain=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath") -- cgit v1.2.3 From 9c766a40cbbd3a350a9582d0fd8201e3361a63b2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 27 Sep 2021 14:44:21 +0200 Subject: Fix 'error: reading a line: Input/output error' in startBuilder() With -vvvv, the ProgressBar was polluting the stderr of the child, messing up its \2 message to the parent. --- tests/ca/signatures.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/ca/signatures.sh b/tests/ca/signatures.sh index 4b4e468f7..0c7d974ea 100644 --- a/tests/ca/signatures.sh +++ b/tests/ca/signatures.sh @@ -22,8 +22,8 @@ testOneCopy () { rm -rf "$REMOTE_STORE_DIR" attrPath="$1" - nix copy --to $REMOTE_STORE "$attrPath" --file ./content-addressed.nix \ - --secret-key-files "$TEST_ROOT/sk1" + nix copy -vvvv --to $REMOTE_STORE "$attrPath" --file ./content-addressed.nix \ + --secret-key-files "$TEST_ROOT/sk1" --show-trace ensureCorrectlyCopied "$attrPath" -- cgit v1.2.3 From bb1a851bcf1bf62b5d943ba25d57b680711a64c6 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 26 Sep 2021 15:20:36 +0200 Subject: build: also throw hash-mismatch errors if `buildMode == bmCheck` This actually bit me quite recently in `nixpkgs` because I assumed that `nix-build --check` would also error out if hashes don't match anymore[1] and so I wrongly assumed that I couldn't reproduce the mismatch error. The fix is rather simple, during the output registration a so-called `delayedException` is instantiated e.g. if a FOD hash-mismatch occurs. However, in case of `nix-build --check` (or `--rebuild` in case of `nix build`), the code-path where this exception is thrown will never be reached. By adding that check to the if-clause that causes an early exit in case of `bmCheck`, the issue is gone. Also added a (previously failing) test-case to demonstrate the problem. [1] https://github.com/NixOS/nixpkgs/pull/139238, the underlying issue was that `nix-prefetch-git` returns different hashes than `fetchgit` because the latter one fetches submodules by default. --- tests/fixed.nix | 8 ++++++++ tests/fixed.sh | 5 +++++ 2 files changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/fixed.nix b/tests/fixed.nix index 76580ffa1..babe71504 100644 --- a/tests/fixed.nix +++ b/tests/fixed.nix @@ -21,6 +21,14 @@ rec { (f ./fixed.builder2.sh "recursive" "sha1" "vw46m23bizj4n8afrc0fj19wrp7mj3c0") ]; + # Expression to test that `nix-build --check` also throws an error if the hash of + # fixed-output derivation has changed even if the hash exists in the store (in this + # case the hash exists because of `fixed.builder2.sh`, but building a derivation + # with the same hash and a different result must throw an error). + check = [ + (f ./fixed.builder1.sh "recursive" "md5" "3670af73070fa14077ad74e0f5ea4e42") + ]; + good2 = [ # Yes, this looks fscked up: builder2 doesn't have that result. # But Nix sees that an output with the desired hash already diff --git a/tests/fixed.sh b/tests/fixed.sh index 90c4c8c32..f1e1ce420 100644 --- a/tests/fixed.sh +++ b/tests/fixed.sh @@ -15,6 +15,11 @@ nix path-info --json $path | grep fixed:md5:2qk15sxzzjlnpjk9brn7j8ppcd echo 'testing good...' nix-build fixed.nix -A good --no-out-link +if isDaemonNewer "2.4pre20210927"; then + echo 'testing --check...' + nix-build fixed.nix -A check --check && fail "should fail" +fi + echo 'testing good2...' nix-build fixed.nix -A good2 --no-out-link -- cgit v1.2.3