Skip to content

macos: hide /nix from Finder and stop fseventsd journaling#183

Draft
Mic92 wants to merge 1 commit intomainfrom
mac-optimizations
Draft

macos: hide /nix from Finder and stop fseventsd journaling#183
Mic92 wants to merge 1 commit intomainfrom
mac-optimizations

Conversation

@Mic92
Copy link
Copy Markdown
Member

@Mic92 Mic92 commented Apr 14, 2026

Description

On a mature Nix store (>500k entries), Finder and the system open/save panel
XPC service (com.apple.appkit.xpc.openAndSavePanelService) walk the /nix
synthetic firmlink whenever the user browses near / and cache one
_FileCache + NSURL object per store entry inside DesktopServicesPriv.
On a 700k-entry store this leaks ~950 MB RSS in Finder and ~900 MB in the
open-panel service, plus ~50 % CPU re-syncing
TNode::SynchronizeChildren → getattrlistbulk on every fsevent. The existing
fstab nobrowse option hides the volume from the sidebar (and from
Spotlight/mds), but not the firmlink directory entry under / that
DesktopServices enumerates.

Adds a SuppressVolumeIndexing action that, on the mounted /nix volume:

  • runs chflags hidden /nix — sets UF_HIDDEN on the volume root inode so
    Finder/NSOpenPanel skip the firmlink in directory listings; flag persists
    across remounts. This is the load-bearing fix for the RSS leak.
  • creates /nix/.fseventsd/no_log — Apple-documented per-volume fseventsd
    journal opt-out
    (FSEvents Programming Guide); cuts write I/O during builds and
    GC.

Spotlight needs no extra marker: nobrowse (MNT_DONTBROWSE) already opts
the volume out of mds, and .metadata_never_index is undocumented and
reported unreliable on recent macOS, so it is intentionally not written.

Wired into CreateNixVolume after enable_ownership (volume mounted and
owned). Revert is best-effort since uninstall removes the volume anyway.

Evidence (heap / sample on a 700k-entry store)
$ heap Finder
Physical footprint:         952.3M
  686422  219655040  320.0  _FileCache    CFType  CoreServicesInternal
  686673   65919792   96.0  NSURL         ObjC    CoreFoundation
 1609722  129541344   80.5  CFString      ObjC    CoreFoundation

$ lsof -p $(pgrep -x Finder) | grep DIR
Finder  ...  5r  DIR  ...  /nix/store

$ sample Finder 3 | grep -A3 SynchronizeChildren
  TNode::SynchronizeChildren
    TFSInfoSynchronizer::FetchChildren
      TFSIterator::NextRaw → _URLEnumeratorGetNextURL → getattrlistbulk

Object count tracks ls /nix/store | wc -l. Same signature in
openAndSavePanelService.

Checklist
  • Added or updated relevant tests — tests/fixtures/macos/macos.json
  • Added or updated relevant documentation (leave unchecked if not applicable)
  • Linked to related issues (leave unchecked if not applicable)

@Mic92 Mic92 marked this pull request as draft April 14, 2026 07:43
tracing::warn!(?err, path = %metadata_never_index.display(), "Could not remove Spotlight opt-out marker");
}

let no_log = self.mount_point.join(".fseventsd").join("no_log");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to do a bit of research if there is anything that will stop working if we do this.

On a mature Nix store (>500k entries), Finder and the system open/save
panel XPC service (com.apple.appkit.xpc.openAndSavePanelService) walk the
/nix synthetic firmlink whenever the user browses near / and cache one
_FileCache + NSURL object per store entry inside DesktopServicesPriv.
On a 700k-entry store this leaks ~950 MB RSS in Finder and ~900 MB in the
open-panel service, plus ~50% CPU re-syncing TNode::SynchronizeChildren ->
getattrlistbulk on every fsevent. The existing fstab nobrowse option hides
the *volume* from the sidebar and from Spotlight/mds, but not the firmlink
directory entry under / that DesktopServices enumerates.

Add a SuppressVolumeIndexing action that, on the mounted /nix volume:

  - runs chflags hidden /nix      (UF_HIDDEN on the volume root inode hides
                                   the firmlink from Finder/NSOpenPanel
                                   directory listings; persists across
                                   remounts)
  - drops .fseventsd/no_log       (Apple-documented per-volume fseventsd
                                   journal opt-out; cuts write I/O during
                                   builds and GC)

Spotlight needs no extra marker: nobrowse already opts the volume out, and
.metadata_never_index is undocumented and unreliable on recent macOS.

Wire it into CreateNixVolume after enable_ownership, when the volume is
mounted and owned. Revert is best-effort since uninstall removes the
volume anyway.
@Mic92 Mic92 force-pushed the mac-optimizations branch from 5414ba4 to 104134a Compare April 14, 2026 08:08
@Mic92 Mic92 changed the title macos: suppress Spotlight/fseventsd/Finder indexing of /nix macos: hide /nix from Finder and stop fseventsd journaling Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant