diff --git a/src/libstore/local-overlay-store.cc b/src/libstore/local-overlay-store.cc index 8b89f68bc..76c3adf5f 100644 --- a/src/libstore/local-overlay-store.cc +++ b/src/libstore/local-overlay-store.cc @@ -176,6 +176,14 @@ void LocalOverlayStore::registerValidPaths(const ValidPathInfos & infos) } +void LocalOverlayStore::collectGarbage(const GCOptions & options, GCResults & results) +{ + LocalStore::collectGarbage(options, results); + + remountIfNecessary(); +} + + void LocalOverlayStore::deleteStorePath(const Path & path, uint64_t & bytesFreed) { auto mergedDir = realStoreDir.get() + "/"; @@ -224,6 +232,8 @@ void LocalOverlayStore::optimiseStore() done++; act.progress(done, paths.size()); } + + remountIfNecessary(); } @@ -235,6 +245,18 @@ Path LocalOverlayStore::toRealPathForHardLink(const StorePath & path) } +void LocalOverlayStore::remountIfNecessary() +{ + if (remountHook.get().empty()) { + warn("'%s' needs remounting, set remount-hook to do this automatically", realStoreDir.get()); + } else { + runProgram(remountHook, false, {realStoreDir}); + } + + _remountRequired = false; +} + + static RegisterStoreImplementation regLocalOverlayStore; } diff --git a/src/libstore/local-overlay-store.hh b/src/libstore/local-overlay-store.hh index d45f6bfc5..a26392523 100644 --- a/src/libstore/local-overlay-store.hh +++ b/src/libstore/local-overlay-store.hh @@ -118,12 +118,16 @@ private: void queryRealisationUncached(const DrvOutput&, Callback> callback) noexcept override; + void collectGarbage(const GCOptions & options, GCResults & results) override; + void deleteStorePath(const Path & path, uint64_t & bytesFreed) override; void optimiseStore() override; Path toRealPathForHardLink(const StorePath & storePath) override; + void remountIfNecessary(); + bool _remountRequired = false; }; diff --git a/tests/overlay-local-store/delete-inner.sh b/tests/overlay-local-store/delete-inner.sh index 051b59d5f..f3878f657 100644 --- a/tests/overlay-local-store/delete-inner.sh +++ b/tests/overlay-local-store/delete-inner.sh @@ -27,8 +27,7 @@ lowerInode=$(stat -c %i "$storeA/$lowerPath") [[ "$upperInode" != "$lowerInode" ]] # Now delete file via the overlay store -nix-store --store "$storeB" --delete "$upperPath" -remountOverlayfs +nix-store --store "$storeB&remount-hook=$PWD/remount.sh" --delete "$upperPath" # Check there is no longer a file in upper layer expect 1 stat "$storeBTop/${upperPath##/nix/store/}" diff --git a/tests/overlay-local-store/remount.sh b/tests/overlay-local-store/remount.sh new file mode 100755 index 000000000..ee91c6b43 --- /dev/null +++ b/tests/overlay-local-store/remount.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +mount -o remount "$1"