1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-10 04:43:53 +02:00

Properly lock the builds of CA derivations

Make sure that we can’t build the same derivation twice at the same
time.

Fix https://github.com/NixOS/nix/issues/5029
This commit is contained in:
regnat 2021-07-20 06:57:56 +02:00
parent 1af3f63be5
commit 8707773965
4 changed files with 42 additions and 2 deletions

18
tests/ca/concurrent-builds.sh Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Ensure that we cant 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

15
tests/ca/racy.nix Normal file
View file

@ -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 ]]
'';
}

View file

@ -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