mirror of
https://github.com/NixOS/nix
synced 2025-07-13 17:10:47 +02:00
Move the CA tests to a sub-directory
Requires a slight update to the test infra to work properly, but having the possibility to group tests that way makes the whole thing quite cleaner imho
This commit is contained in:
parent
73b3e6cd46
commit
259d6778ef
8 changed files with 10 additions and 7 deletions
69
tests/ca/build.sh
Normal file
69
tests/ca/build.sh
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source common.sh
|
||||
|
||||
drv=$(nix-instantiate --experimental-features ca-derivations ./content-addressed.nix -A rootCA --arg seed 1)
|
||||
nix --experimental-features 'nix-command ca-derivations' show-derivation --derivation "$drv" --arg seed 1
|
||||
|
||||
buildAttr () {
|
||||
local derivationPath=$1
|
||||
local seedValue=$2
|
||||
shift; shift
|
||||
local args=("--experimental-features" "ca-derivations" "./content-addressed.nix" "-A" "$derivationPath" --arg seed "$seedValue" "--no-out-link")
|
||||
args+=("$@")
|
||||
nix-build "${args[@]}"
|
||||
}
|
||||
|
||||
testRemoteCache () {
|
||||
clearCache
|
||||
local outPath=$(buildAttr dependentNonCA 1)
|
||||
nix copy --to file://$cacheDir $outPath
|
||||
clearStore
|
||||
buildAttr dependentNonCA 1 --option substituters file://$cacheDir --no-require-sigs |& (! grep "building dependent-non-ca")
|
||||
}
|
||||
|
||||
testDeterministicCA () {
|
||||
[[ $(buildAttr rootCA 1) = $(buildAttr rootCA 2) ]]
|
||||
}
|
||||
|
||||
testCutoffFor () {
|
||||
local out1 out2
|
||||
out1=$(buildAttr $1 1)
|
||||
# The seed only changes the root derivation, and not it's output, so the
|
||||
# dependent derivations should only need to be built once.
|
||||
buildAttr rootCA 2
|
||||
out2=$(buildAttr $1 2 -j0)
|
||||
test "$out1" == "$out2"
|
||||
}
|
||||
|
||||
testCutoff () {
|
||||
# Don't directly build depenentCA, that way we'll make sure we dodn't rely on
|
||||
# dependent derivations always being already built.
|
||||
#testDerivation dependentCA
|
||||
testCutoffFor transitivelyDependentCA
|
||||
testCutoffFor dependentNonCA
|
||||
testCutoffFor dependentFixedOutput
|
||||
}
|
||||
|
||||
testGC () {
|
||||
nix-instantiate --experimental-features ca-derivations ./content-addressed.nix -A rootCA --arg seed 5
|
||||
nix-collect-garbage --experimental-features ca-derivations --option keep-derivations true
|
||||
clearStore
|
||||
buildAttr rootCA 1 --out-link $TEST_ROOT/rootCA
|
||||
nix-collect-garbage --experimental-features ca-derivations
|
||||
buildAttr rootCA 1 -j0
|
||||
}
|
||||
|
||||
testNixCommand () {
|
||||
clearStore
|
||||
nix build --experimental-features 'nix-command ca-derivations' --file ./content-addressed.nix --no-link
|
||||
}
|
||||
|
||||
# Disabled until we have it properly working
|
||||
# testRemoteCache
|
||||
clearStore
|
||||
testDeterministicCA
|
||||
clearStore
|
||||
testCutoff
|
||||
testGC
|
||||
testNixCommand
|
1
tests/ca/common.sh
Normal file
1
tests/ca/common.sh
Normal file
|
@ -0,0 +1 @@
|
|||
source ../common.sh
|
77
tests/ca/content-addressed.nix
Normal file
77
tests/ca/content-addressed.nix
Normal file
|
@ -0,0 +1,77 @@
|
|||
with import ../config.nix;
|
||||
|
||||
{ seed ? 0 }:
|
||||
# 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 {
|
||||
rootLegacy = mkDerivation {
|
||||
name = "simple-input-addressed";
|
||||
buildCommand = ''
|
||||
set -x
|
||||
echo "Building a legacy derivation"
|
||||
mkdir -p $out
|
||||
echo "Hello World" > $out/hello
|
||||
'';
|
||||
};
|
||||
rootCA = mkDerivation {
|
||||
name = "rootCA";
|
||||
outputs = [ "out" "dev" "foo"];
|
||||
buildCommand = ''
|
||||
echo "building a CA derivation"
|
||||
echo "The seed is ${toString seed}"
|
||||
mkdir -p $out
|
||||
echo ${rootLegacy}/hello > $out/dep
|
||||
ln -s $out $out/self
|
||||
# test symlinks at root
|
||||
ln -s $out $dev
|
||||
ln -s $out $foo
|
||||
'';
|
||||
__contentAddressed = true;
|
||||
outputHashMode = "recursive";
|
||||
outputHashAlgo = "sha256";
|
||||
};
|
||||
dependentCA = mkDerivation {
|
||||
name = "dependent";
|
||||
buildCommand = ''
|
||||
echo "building a dependent derivation"
|
||||
mkdir -p $out
|
||||
cat ${rootCA}/self/dep
|
||||
echo ${rootCA}/self/dep > $out/dep
|
||||
'';
|
||||
__contentAddressed = true;
|
||||
outputHashMode = "recursive";
|
||||
outputHashAlgo = "sha256";
|
||||
};
|
||||
transitivelyDependentCA = mkDerivation {
|
||||
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";
|
||||
buildCommand = ''
|
||||
echo "Didn't cut-off"
|
||||
echo "building dependent-non-ca"
|
||||
mkdir -p $out
|
||||
echo ${rootCA}/non-ca-hello > $out/dep
|
||||
'';
|
||||
};
|
||||
dependentFixedOutput = mkDerivation {
|
||||
name = "dependent-fixed-output";
|
||||
outputHashMode = "recursive";
|
||||
outputHashAlgo = "sha256";
|
||||
outputHash = "sha256-QvtAMbUl/uvi+LCObmqOhvNOapHdA2raiI4xG5zI5pA=";
|
||||
buildCommand = ''
|
||||
cat ${dependentCA}/dep
|
||||
echo foo > $out
|
||||
'';
|
||||
|
||||
};
|
||||
}
|
34
tests/ca/nix-copy.sh
Executable file
34
tests/ca/nix-copy.sh
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/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"
|
||||
|
||||
export REMOTE_STORE_DIR="$TEST_ROOT/remote_store"
|
||||
export REMOTE_STORE="file://$REMOTE_STORE_DIR"
|
||||
|
||||
ensureCorrectlyCopied () {
|
||||
attrPath="$1"
|
||||
nix build --store "$REMOTE_STORE" --file ./content-addressed.nix "$attrPath"
|
||||
}
|
||||
|
||||
testOneCopy () {
|
||||
clearStore
|
||||
rm -rf "$REMOTE_STORE_DIR"
|
||||
|
||||
attrPath="$1"
|
||||
nix copy --to $REMOTE_STORE "$attrPath" --file ./content-addressed.nix
|
||||
|
||||
ensureCorrectlyCopied "$attrPath"
|
||||
|
||||
# Ensure that we can copy back what we put in the store
|
||||
clearStore
|
||||
nix copy --from $REMOTE_STORE \
|
||||
--file ./content-addressed.nix "$attrPath" \
|
||||
--no-check-sigs
|
||||
}
|
||||
|
||||
for attrPath in rootCA dependentCA transitivelyDependentCA dependentNonCA dependentFixedOutput; do
|
||||
testOneCopy "$attrPath"
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue