Skip to content

Commit 69aa3df

Browse files
authored
macOS: honor stable Nix defaults suite (#12205)
* macOS: honor Nix defaults suite; auto launch in Nix mode Fixes repeated onboarding in Nix deployments by detecting nixMode from the stable defaults suite (ai.openclaw.mac) and bridging key settings into the current defaults domain. Also enables LaunchAgent autostart by default in Nix mode (escape hatch: openclaw.nixAutoLaunchAtLogin=false). * macOS: keep Nix mode fix focused Drop the automatic launch-at-login behavior from the Nix defaults patch; keep this PR scoped to reliable nixMode detection + defaults bridging. * macOS: simplify nixMode fix Remove the defaults-bridging helper and rely on a single, stable defaults suite (ai.openclaw.mac) for nixMode detection when running as an app bundle. This keeps the fix focused on onboarding suppression and rename churn resilience. * macOS: fix nixMode defaults suite churn (#12205)
1 parent 53a1ac3 commit 69aa3df

6 files changed

Lines changed: 76 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Docs: https://docs.openclaw.ai
3636
- State dir: honor `OPENCLAW_STATE_DIR` for default device identity and canvas storage paths. (#4824) Thanks @kossoy.
3737
- Doctor/State dir: suppress repeated legacy migration warnings only for valid symlink mirrors, while keeping warnings for empty or invalid legacy trees. (#11709) Thanks @gumadeiras.
3838
- Tests: harden flaky hotspots by removing timer sleeps, consolidating onboarding provider-auth coverage, and improving memory test realism. (#11598) Thanks @gumadeiras.
39+
- macOS: honor Nix-managed defaults suite (`ai.openclaw.mac`) for nixMode to prevent onboarding from reappearing after bundle-id churn. (#12205) Thanks @joshp123.
3940

4041
## 2026.2.6
4142

‎apps/macos/Sources/OpenClaw/Constants.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Foundation
22

3+
// Stable identifier used for both the macOS LaunchAgent label and Nix-managed defaults suite.
4+
// nix-openclaw writes app defaults into this suite to survive app bundle identifier churn.
35
let launchdLabel = "ai.openclaw.mac"
46
let gatewayLaunchdLabel = "ai.openclaw.gateway"
57
let onboardingVersionKey = "openclaw.onboardingVersion"

‎apps/macos/Sources/OpenClaw/MenuBar.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct OpenClawApp: App {
3333

3434
init() {
3535
OpenClawLogging.bootstrapIfNeeded()
36+
3637
Self.applyAttachOnlyOverrideIfNeeded()
3738
_state = State(initialValue: AppStateStore.shared)
3839
}

‎apps/macos/Sources/OpenClaw/ProcessInfo+OpenClaw.swift‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,32 @@ extension ProcessInfo {
66
return String(cString: raw) == "1"
77
}
88

9+
/// Nix deployments may write defaults into a stable suite (`ai.openclaw.mac`) even if the shipped
10+
/// app bundle identifier changes (and therefore `UserDefaults.standard` domain changes).
11+
static func resolveNixMode(
12+
environment: [String: String],
13+
standard: UserDefaults,
14+
stableSuite: UserDefaults?,
15+
isAppBundle: Bool
16+
) -> Bool {
17+
if environment["OPENCLAW_NIX_MODE"] == "1" { return true }
18+
if standard.bool(forKey: "openclaw.nixMode") { return true }
19+
20+
// Only consult the stable suite when running as a .app bundle.
21+
// This avoids local developer machines accidentally influencing unit tests.
22+
if isAppBundle, let stableSuite, stableSuite.bool(forKey: "openclaw.nixMode") { return true }
23+
24+
return false
25+
}
26+
927
var isNixMode: Bool {
10-
if let raw = getenv("OPENCLAW_NIX_MODE"), String(cString: raw) == "1" { return true }
11-
return UserDefaults.standard.bool(forKey: "openclaw.nixMode")
28+
let isAppBundle = Bundle.main.bundleURL.pathExtension == "app"
29+
let stableSuite = UserDefaults(suiteName: launchdLabel)
30+
return Self.resolveNixMode(
31+
environment: self.environment,
32+
standard: .standard,
33+
stableSuite: stableSuite,
34+
isAppBundle: isAppBundle)
1235
}
1336

1437
var isRunningTests: Bool {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Foundation
2+
import Testing
3+
@testable import OpenClaw
4+
5+
@Suite(.serialized)
6+
struct NixModeStableSuiteTests {
7+
@Test func resolvesFromStableSuiteForAppBundles() {
8+
let suite = UserDefaults(suiteName: launchdLabel)!
9+
let key = "openclaw.nixMode"
10+
let prev = suite.object(forKey: key)
11+
defer {
12+
if let prev { suite.set(prev, forKey: key) } else { suite.removeObject(forKey: key) }
13+
}
14+
15+
suite.set(true, forKey: key)
16+
17+
let standard = UserDefaults(suiteName: "NixModeStableSuiteTests.\(UUID().uuidString)")!
18+
#expect(!standard.bool(forKey: key))
19+
20+
let resolved = ProcessInfo.resolveNixMode(
21+
environment: [:],
22+
standard: standard,
23+
stableSuite: suite,
24+
isAppBundle: true)
25+
#expect(resolved)
26+
}
27+
28+
@Test func ignoresStableSuiteOutsideAppBundles() {
29+
let suite = UserDefaults(suiteName: launchdLabel)!
30+
let key = "openclaw.nixMode"
31+
let prev = suite.object(forKey: key)
32+
defer {
33+
if let prev { suite.set(prev, forKey: key) } else { suite.removeObject(forKey: key) }
34+
}
35+
36+
suite.set(true, forKey: key)
37+
let standard = UserDefaults(suiteName: "NixModeStableSuiteTests.\(UUID().uuidString)")!
38+
39+
let resolved = ProcessInfo.resolveNixMode(
40+
environment: [:],
41+
standard: standard,
42+
stableSuite: suite,
43+
isAppBundle: false)
44+
#expect(!resolved)
45+
}
46+
}

‎apps/macos/Tests/OpenClawIPCTests/WideAreaGatewayDiscoveryTests.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Darwin
12
import Testing
23
@testable import OpenClawDiscovery
34

0 commit comments

Comments
 (0)