2024-05-28 19:43:04 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2006-03-01 14:15:33 +02:00
|
|
|
source common.sh
|
|
|
|
|
2009-03-28 00:40:22 +02:00
|
|
|
clearStore
|
2008-08-14 12:26:30 +03:00
|
|
|
|
2020-07-02 16:43:35 +03:00
|
|
|
lockFifo1=$TEST_ROOT/test1.fifo
|
|
|
|
mkfifo "$lockFifo1"
|
|
|
|
|
|
|
|
drvPath1=$(nix-instantiate gc-concurrent.nix -A test1 --argstr lockFifo "$lockFifo1")
|
2011-10-11 00:32:34 +03:00
|
|
|
outPath1=$(nix-store -q $drvPath1)
|
2005-02-01 00:01:55 +02:00
|
|
|
|
2011-10-11 00:32:34 +03:00
|
|
|
drvPath2=$(nix-instantiate gc-concurrent.nix -A test2)
|
|
|
|
outPath2=$(nix-store -q $drvPath2)
|
2005-01-28 22:36:46 +02:00
|
|
|
|
2011-10-11 00:32:34 +03:00
|
|
|
drvPath3=$(nix-instantiate simple.nix)
|
|
|
|
outPath3=$(nix-store -r $drvPath3)
|
2008-12-12 19:03:18 +02:00
|
|
|
|
2014-08-21 22:50:19 +03:00
|
|
|
(! test -e $outPath3.lock)
|
2008-12-12 19:03:18 +02:00
|
|
|
touch $outPath3.lock
|
|
|
|
|
|
|
|
rm -f "$NIX_STATE_DIR"/gcroots/foo*
|
2024-06-12 19:42:38 +03:00
|
|
|
ln -s $drvPath2 "$NIX_STATE_DIR/gcroots/foo"
|
|
|
|
ln -s $outPath3 "$NIX_STATE_DIR/gcroots/foo2"
|
2005-02-01 00:23:49 +02:00
|
|
|
|
2005-02-01 00:01:55 +02:00
|
|
|
# Start build #1 in the background. It starts immediately.
|
2011-10-11 00:32:34 +03:00
|
|
|
nix-store -rvv "$drvPath1" &
|
2005-02-01 00:01:55 +02:00
|
|
|
pid1=$!
|
2005-01-28 22:36:46 +02:00
|
|
|
|
2020-07-02 16:43:35 +03:00
|
|
|
# Wait for the build of $drvPath1 to start
|
|
|
|
cat $lockFifo1
|
2005-01-28 22:36:46 +02:00
|
|
|
|
2008-08-14 12:26:30 +03:00
|
|
|
# Run the garbage collector while the build is running.
|
2011-10-11 00:32:34 +03:00
|
|
|
nix-collect-garbage
|
2005-02-01 00:01:55 +02:00
|
|
|
|
2020-07-02 16:43:35 +03:00
|
|
|
# Unlock the build of $drvPath1
|
|
|
|
echo "" > $lockFifo1
|
2005-02-01 00:01:55 +02:00
|
|
|
echo waiting for pid $pid1 to finish...
|
|
|
|
wait $pid1
|
2005-01-28 22:36:46 +02:00
|
|
|
|
2005-02-01 00:01:55 +02:00
|
|
|
# Check that the root of build #1 and its dependencies haven't been
|
2008-08-14 12:26:30 +03:00
|
|
|
# deleted. The should not be deleted by the GC because they were
|
|
|
|
# being built during the GC.
|
2005-02-01 00:01:55 +02:00
|
|
|
cat $outPath1/foobar
|
|
|
|
cat $outPath1/input-2/bar
|
2005-01-28 22:36:46 +02:00
|
|
|
|
2020-07-02 16:43:35 +03:00
|
|
|
# Check that the build build $drvPath2 succeeds.
|
|
|
|
# It should succeed because the derivation is a GC root.
|
|
|
|
nix-store -rvv "$drvPath2"
|
2005-02-01 00:01:55 +02:00
|
|
|
cat $outPath2/foobar
|
2006-03-01 15:25:08 +02:00
|
|
|
|
2008-12-12 19:03:18 +02:00
|
|
|
rm -f "$NIX_STATE_DIR"/gcroots/foo*
|
|
|
|
|
|
|
|
# The collector should have deleted lock files for paths that have
|
|
|
|
# been built previously.
|
2014-08-21 22:50:19 +03:00
|
|
|
(! test -e $outPath3.lock)
|
2008-12-12 19:03:18 +02:00
|
|
|
|
|
|
|
# If we run the collector now, it should delete outPath1/2.
|
2011-10-11 00:32:34 +03:00
|
|
|
nix-collect-garbage
|
2014-08-21 22:50:19 +03:00
|
|
|
(! test -e $outPath1)
|
|
|
|
(! test -e $outPath2)
|