From c27b2a691ed432b9f9ef7fd42ab74b8f6cff40b5 Mon Sep 17 00:00:00 2001 From: Winter Date: Sat, 19 Apr 2025 02:26:26 -0400 Subject: [PATCH] libstore: skip Spotlight processes when finding GC roots Despite installations of Nix explicitly setting the `nobrowse` mount option on the store, `mdworker` processes continue to run on newly created files within it, which can result in spurious GC/path deletion failures if the stars are aligned right. IMO, the best way to fix this is to simply ignore any processes started by the Spotlight user, so that's exactly what we do here. Fixes: https://github.com/NixOS/nix/issues/6141 Change-Id: I6a6a636c70f3f443f07ba9280d5f1e04b2ed2985 --- src/libstore/gc.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index db91e521328..1048bd39e15 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -414,8 +414,13 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor) if (getEnv("_NIX_TEST_NO_LSOF") != "1") { try { std::regex lsofRegex(R"(^n(/.*)$)"); + + // Despite installations of Nix explicitly setting the `nobrowse` mount + // option on the store, `mdworker` processes continue to run on newly + // created files within it, which can result in spurious GC/path deletion + // failures if the stars are aligned right. auto lsofLines = - tokenizeString>(runProgram(LSOF, true, { "-n", "-w", "-F", "n" }), "\n"); + tokenizeString>(runProgram(LSOF, true, { "-n", "-w", "-F", "n", "-u", "^89", "-g", "^89" }), "\n"); for (const auto & line : lsofLines) { std::smatch match; if (std::regex_match(line, match, lsofRegex))