local-overlay-store: a stale `tmp-*` directory in the upper layer makes every GC fail
Describe the bug
If a tmp-* directory is left behind in a local-overlay store's upper layer, for example by a substitution interrupted by a crash, nix store gc on that store fails:
error: 'tmp-12345-67890' is too short to be a valid store path
It exits 1 and doesn't delete the directory, so every later GC fails the same way until someone removes the directory by hand. A plain local store's GC deletes the same kind of directory without error.
The lower store is never modified in this reproduction, so this is within the documented constraint that the lower store must not change while mounted.
Steps to reproduce
In an unprivileged user namespace:
S=$(mktemp -d); mkdir -p $S/{low,root/nix/store,up/store,up/work,state}
echo hi > $S/f.txt
nix --option build-users-group '' store add-file --store "local?root=$S/low" $S/f.txt
unshare -rm --map-root-user bash -c '
S='"$S"'
mount -t overlay overlay -o lowerdir=$S/low/nix/store,upperdir=$S/up/store,workdir=$S/up/work,userxattr $S/root/nix/store
U="local-overlay://?root=$S/root&state=$S/state&lower-store=$(printf "local?root=%s" $S/low | jq -sRr @uri)&upper-layer=$S/up/store&check-mount=false"
N="nix --option build-users-group \"\" --extra-experimental-features local-overlay-store"
eval $N store gc --store "\"$U\"" # ok
mkdir $S/root/nix/store/tmp-12345-67890 # lands in the upper layer only
eval $N store gc --store "\"$U\""; echo rc=$? # error: ... too short ..., rc=1
ls $S/up/store # tmp-12345-67890 is still there
# For comparison, a plain local store:
mkdir $S/low/nix/store/tmp-99999-1
eval $N store gc --store "\"local?root=$S/low\""; ls $S/low/nix/store | grep -c tmp- # 0: removed
'
Expected behavior
The overlay GC deletes, or at least skips, a non-store-path entry in the upper layer, as LocalStore's GC does, rather than aborting the whole collection.
Cause
collectGarbage passes a directory name that isn't a store path to deleteFromStore(name, false). In LocalOverlayStore::deleteStorePath (src/libstore/local-overlay-store.cc), the name then goes straight into the constructor:
StorePath storePath = {path.filename().string()};
That throws BadStorePath for tmp-* (and any other non-store name), which aborts the GC. A guard along these lines would avoid it. For a name that isn't a store path, it either deletes the upper entry directly, since it can't be a lower store object, or skips it:
auto storePath = maybeParseStorePath(storeDir + "/" + path.filename().string());
if (!storePath) {
// Not a store object (e.g. a stale tmp-* dir): it can only live in the upper layer.
LocalStore::deleteStorePath(path, bytesFreed, isKnownPath);
return;
}
I'm not sure which of the two is preferred, deleting or skipping.
Metadata
- Nix 2.34.9 (reproduced). The same code is on
masteras of 2026-11-10. - Linux, unprivileged user namespace, OverlayFS with
userxattr. - Experimental feature
local-overlay-store.
Additional context
I found no existing issue for this. The open local-overlay issues (#11840, #12399, #10991) are about other things.