aboutsummaryrefslogtreecommitdiff
path: root/tests/ca
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-06-21 15:17:31 +0200
committerregnat <rg@regnat.ovh>2021-06-21 15:29:15 +0200
commit3784c66a46aea2cc3e26b8cff94b3a1f477888f1 (patch)
treeb0bada8ea475ed7758f440ebdc7f401932add39b /tests/ca
parentdb3de0727ec8416e1542f0158d0247a2cbe6e268 (diff)
Remove a possible existing store path when building CA derivations
In case a previous interrupted build left a garbage path laying around, remove it before trying to move the path to its final location. Fix #4858
Diffstat (limited to 'tests/ca')
-rwxr-xr-xtests/ca/build-with-garbage-path.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/ca/build-with-garbage-path.sh b/tests/ca/build-with-garbage-path.sh
new file mode 100755
index 000000000..e6f878702
--- /dev/null
+++ b/tests/ca/build-with-garbage-path.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+# Regression test for https://github.com/NixOS/nix/issues/4858
+
+source common.sh
+sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
+
+# Get the output path of `rootCA`, and put some garbage instead
+outPath="$(nix-build ./content-addressed.nix -A rootCA --no-out-link)"
+nix-store --delete "$outPath"
+touch "$outPath"
+
+# The build should correctly remove the garbage and put the expected path instead
+nix-build ./content-addressed.nix -A rootCA --no-out-link
+
+# Rebuild it. This shouldn’t overwrite the existing path
+oldInode=$(stat -c '%i' "$outPath")
+nix-build ./content-addressed.nix -A rootCA --no-out-link --arg seed 2
+newInode=$(stat -c '%i' "$outPath")
+[[ "$oldInode" == "$newInode" ]]