diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/local.mk | 1 | ||||
-rw-r--r-- | tests/text-hashed-output.nix | 29 | ||||
-rw-r--r-- | tests/text-hashed-output.sh | 29 |
3 files changed, 59 insertions, 0 deletions
diff --git a/tests/local.mk b/tests/local.mk index b100e7f15..067ece24d 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -44,6 +44,7 @@ nix_tests = \ recursive.sh \ describe-stores.sh \ flakes.sh \ + text-hashed-output.sh \ build.sh \ compute-levels.sh \ repl.sh \ diff --git a/tests/text-hashed-output.nix b/tests/text-hashed-output.nix new file mode 100644 index 000000000..23434c0a1 --- /dev/null +++ b/tests/text-hashed-output.nix @@ -0,0 +1,29 @@ +with import ./config.nix; + +# A simple content-addressed derivation. +# The derivation can be arbitrarily modified by passing a different `seed`, +# but the output will always be the same +rec { + root = mkDerivation { + name = "text-hashed-root"; + buildCommand = '' + set -x + echo "Building a CA derivation" + mkdir -p $out + echo "Hello World" > $out/hello + ''; + __contentAddressed = true; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + }; + dependent = mkDerivation { + name = "text-hashed-root.drv"; + buildCommand = '' + echo "Copying the derivation" + cp ${root.drvPath} $out + ''; + __contentAddressed = true; + outputHashMode = "text"; + outputHashAlgo = "sha256"; + }; +} diff --git a/tests/text-hashed-output.sh b/tests/text-hashed-output.sh new file mode 100644 index 000000000..1c4d3a438 --- /dev/null +++ b/tests/text-hashed-output.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +source common.sh + +# Globally enable the ca derivations experimental flag +sed -i 's/experimental-features = .*/& ca-derivations ca-references/' "$NIX_CONF_DIR/nix.conf" + +# In the corresponding nix file, we have two derivations: the first, named root, +# is a normal recursive derivation, while the second, named dependent, has the +# new outputHashMode "text". Note that in "dependent", we don't refer to the +# build output of root, but only to the path of the drv file. For this reason, +# we only need to: +# +# - instantiate the root derivation +# - build the dependent derivation +# - check that the path of the output coincides with that of the original derivation + +drv=$(nix-instantiate --experimental-features ca-derivations ./text-hashed-output.nix -A root) +nix show-derivation --derivation "$drv" + +drvDep=$(nix-instantiate --experimental-features ca-derivations ./text-hashed-output.nix -A dependent) +nix show-derivation --derivation "$drvDep" + +out1=$(nix-build --experimental-features ca-derivations ./text-hashed-output.nix -A dependent --no-out-link) + +nix path-info $drv --derivation --json | jq +nix path-info $out1 --derivation --json | jq + +test $out1 == $drv |