From 3aee0ebfee1a154c69a9fc59c4240382a760f90f Mon Sep 17 00:00:00 2001 From: Xin Huang Date: Tue, 4 Nov 2025 18:24:00 -0800 Subject: [PATCH 1/4] fix: Add policies.json support for macOS (Darwin) Previously, policies.json was only installed for Linux builds, causing browser policies (including ExtensionSettings) to be ignored on macOS. This resulted in extensions not being automatically installed on macOS systems. This fix adds the policies.json installation to the Darwin install phase, mirroring the Linux behavior and ensuring policy enforcement works correctly on macOS. Fixes extension auto-installation and other policy-based features on macOS. --- package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.nix b/package.nix index 526fe80f..83518361 100644 --- a/package.nix +++ b/package.nix @@ -67,6 +67,10 @@ cp -r *.app "$out/Applications/${applicationName}.app" ln -s zen "$out/Applications/${applicationName}.app/Contents/MacOS/${binaryName}" + # Install policies.json for macOS + mkdir -p "$out/Applications/${applicationName}.app/Contents/Resources/distribution" + ln -s ${policiesJson} "$out/Applications/${applicationName}.app/Contents/Resources/distribution/policies.json" + cat > "$out/bin/${binaryName}" << EOF #!/bin/bash exec /usr/bin/open -na "$out/Applications/${applicationName}.app" --args "\$@" From 344a995aa32e54dfc02da19b62afba1536a4529f Mon Sep 17 00:00:00 2001 From: Xin Huang Date: Tue, 4 Nov 2025 20:53:04 -0800 Subject: [PATCH 2/4] fix(darwin): use stable app path to prevent installs.ini accumulation Problem: - Zen Browser creates install IDs based on the application path - Wrapper script uses Nix store path which changes on every rebuild - Each new path creates a new install ID entry in installs.ini - Results in: multiple Dock icons, empty profiles, data loss Solution: - Use the stable Home Manager symlink path (~/.../Home Manager Apps/...) - This path remains constant across Nix rebuilds - Zen Browser sees the same path every time, reuses existing install ID - Falls back to store path if symlink doesn't exist yet Benefits: - No activation scripts or workarounds needed - Fixes root cause instead of symptoms - Maintains profile continuity naturally - Clean, elegant solution --- package.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/package.nix b/package.nix index 83518361..dae16616 100644 --- a/package.nix +++ b/package.nix @@ -71,9 +71,18 @@ mkdir -p "$out/Applications/${applicationName}.app/Contents/Resources/distribution" ln -s ${policiesJson} "$out/Applications/${applicationName}.app/Contents/Resources/distribution/policies.json" + # Use symlink path to avoid installs.ini accumulation on Nix rebuilds + # The symlink is created by home-manager and remains stable across rebuilds cat > "$out/bin/${binaryName}" << EOF #!/bin/bash - exec /usr/bin/open -na "$out/Applications/${applicationName}.app" --args "\$@" + # Use stable path from home-manager to avoid creating new install IDs + STABLE_PATH="\$HOME/Applications/Home Manager Apps/${applicationName}.app" + if [[ -e "\$STABLE_PATH" ]]; then + exec /usr/bin/open -na "\$STABLE_PATH" --args "\$@" + else + # Fallback to nix store path if symlink doesn't exist yet + exec /usr/bin/open -na "$out/Applications/${applicationName}.app" --args "\$@" + fi EOF chmod +x "$out/bin/${binaryName}" From 3d8a33f2577986d7015d8f1aaa8b325d08e8f732 Mon Sep 17 00:00:00 2001 From: Xin Huang Date: Tue, 4 Nov 2025 21:38:22 -0800 Subject: [PATCH 3/4] fix: force WAL checkpoint after updating places.sqlite Problem: - SQLite WAL mode writes changes to .sqlite-wal file first - Changes aren't visible until WAL is checkpointed to main file - Zen Browser reads stale data from main file on startup - User needs to wait or manually trigger checkpoint to see updates Solution: - Execute PRAGMA wal_checkpoint(FULL) after all updates - Forces immediate merge of WAL changes to main database file - Ensures spaces/pins updates are visible on next Zen startup This fixes the delay between home-manager rebuild and seeing configuration changes in Zen Browser. --- hm-module.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hm-module.nix b/hm-module.nix index 39fa158d..1396e3b3 100644 --- a/hm-module.nix +++ b/hm-module.nix @@ -612,6 +612,9 @@ in { ${optionalString (profile.spacesForce) deleteSpaces} ${optionalString (profile.pins != {}) insertPins} ${optionalString (profile.pinsForce) deletePins} + + # Force WAL checkpoint to ensure changes are visible immediately + ${sqlite3} "${placesFile}" "PRAGMA wal_checkpoint(FULL);" || exit 1 } error="$(update_places 2>&1 1>/dev/null)" From 0df526b96d5cf45c24ada60234aff3efcca9b37b Mon Sep 17 00:00:00 2001 From: Xin Huang Date: Tue, 4 Nov 2025 22:44:13 -0800 Subject: [PATCH 4/4] fix(darwin): preserve correct bundle identifier in code signature Problem: - AdGuard recognizes apps by code signing identifier, not CFBundleIdentifier - Nix's adhoc re-signing changes identifier from 'app.zen-browser.zen' to 'zen' - This breaks AdGuard's app filtering for Nix-built Zen Browser Solution: - Explicitly set --identifier flag when re-signing with codesign - Maintains 'app.zen-browser.zen' identifier for AdGuard compatibility - Ensures proper ad-blocking and app recognition This allows AdGuard and other security tools to correctly identify Zen Browser even when built through Nix. --- package.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.nix b/package.nix index dae16616..7e272883 100644 --- a/package.nix +++ b/package.nix @@ -71,6 +71,12 @@ mkdir -p "$out/Applications/${applicationName}.app/Contents/Resources/distribution" ln -s ${policiesJson} "$out/Applications/${applicationName}.app/Contents/Resources/distribution/policies.json" + # Re-sign with correct identifier to maintain AdGuard compatibility + # AdGuard uses code signing identifier (not CFBundleIdentifier) to recognize apps + /usr/bin/codesign --force --deep --sign - \ + --identifier "app.zen-browser.zen" \ + "$out/Applications/${applicationName}.app" + # Use symlink path to avoid installs.ini accumulation on Nix rebuilds # The symlink is created by home-manager and remains stable across rebuilds cat > "$out/bin/${binaryName}" << EOF