Merge remote-tracking branch 'obsidian/single-ca-drv-build' into ca-floating-upstream

Tests also now fail as they should
This commit is contained in:
John Ericson 2020-09-03 22:44:56 +00:00
commit b836662f50
2 changed files with 32 additions and 18 deletions

View file

@ -5,12 +5,11 @@ with import ./config.nix;
# The derivation can be arbitrarily modified by passing a different `seed`, # The derivation can be arbitrarily modified by passing a different `seed`,
# but the output will always be the same # but the output will always be the same
rec { rec {
root = mkDerivation { rootLegacy = mkDerivation {
name = "simple-content-addressed"; name = "simple-input-addressed";
buildCommand = '' buildCommand = ''
set -x set -x
echo "Building a CA derivation" echo "Building a legacy derivation"
echo "The seed is ${toString seed}"
mkdir -p $out mkdir -p $out
echo "Hello World" > $out/hello echo "Hello World" > $out/hello
''; '';
@ -18,23 +17,35 @@ rec {
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
}; };
dependent = mkDerivation { rootCA = mkDerivation {
name = "dependent"; name = "dependent";
buildCommand = '' buildCommand = ''
echo "building a dependent derivation" echo "building a CA derivation"
echo "The seed is ${toString seed}"
mkdir -p $out mkdir -p $out
echo ${root}/hello > $out/dep echo ${rootLegacy}/hello > $out/dep
''; '';
__contentAddressed = true; __contentAddressed = true;
outputHashMode = "recursive"; outputHashMode = "recursive";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
}; };
transitivelyDependent = mkDerivation { dependentCA = mkDerivation {
name = "dependent";
buildCommand = ''
echo "building a dependent derivation"
mkdir -p $out
echo ${rootCA}/hello > $out/dep
'';
__contentAddressed = true;
outputHashMode = "recursive";
outputHashAlgo = "sha256";
};
transitivelyDependentCA = mkDerivation {
name = "transitively-dependent"; name = "transitively-dependent";
buildCommand = '' buildCommand = ''
echo "building transitively-dependent" echo "building transitively-dependent"
cat ${dependent}/dep cat ${dependentCA}/dep
echo ${dependent} > $out echo ${dependentCA} > $out
''; '';
__contentAddressed = true; __contentAddressed = true;
outputHashMode = "recursive"; outputHashMode = "recursive";

View file

@ -2,20 +2,23 @@
source common.sh source common.sh
drv=$(nix-instantiate --experimental-features ca-derivations ./content-addressed.nix -A root --arg seed 1) 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 nix --experimental-features 'nix-command ca-derivations' show-derivation --derivation "$drv" --arg seed 1
testDerivation () { testDerivation () {
local derivationPath=$1 local derivationPath=$1
local commonArgs=("--experimental-features" "ca-derivations" "./content-addressed.nix" "-A" "$derivationPath" "--no-out-link") local commonArgs=("--experimental-features" "ca-derivations" "./content-addressed.nix" "-A" "$derivationPath" "--no-out-link")
local out1=$(nix-build "${commonArgs[@]}" --arg seed 1) local out1 out2
local out2=$(nix-build "${commonArgs[@]}" --arg seed 2 "${extraArgs[@]}") out1=$(set -e; nix-build "${commonArgs[@]}" --arg seed 1)
test $out1 == $out2 out2=$(nix-build "${commonArgs[@]}" --arg seed 2 "${secondSeedArgs[@]}")
test "$out1" == "$out2"
} }
testDerivation root testDerivation rootCA
# The seed only changes the root derivation, and not it's output, so the # The seed only changes the root derivation, and not it's output, so the
# dependent derivations should only need to be built once. # dependent derivations should only need to be built once.
extaArgs=(-j0) secondSeedArgs=(-j0)
testDerivation dependent # Don't directly build depenentCA, that way we'll make sure we dodn't rely on
testDerivation transitivelyDependent # dependent derivations always being already built.
#testDerivation dependentCA
testDerivation transitivelyDependentCA