1Nix may already sandbox the build, in which case sandbox_apply will fail.
2
3--- a/Sources/Basics/Sandbox.swift
4+++ b/Sources/Basics/Sandbox.swift
5@@ -33,12 +33,14 @@ public enum Sandbox {
6 readOnlyDirectories: [AbsolutePath] = []
7 ) throws -> [String] {
8 #if os(macOS)
9+ let env = ProcessInfo.processInfo.environment
10+ if env["NIX_BUILD_TOP"] == nil || env["IN_NIX_SHELL"] != nil {
11 let profile = try macOSSandboxProfile(strictness: strictness, writableDirectories: writableDirectories, readOnlyDirectories: readOnlyDirectories)
12 return ["/usr/bin/sandbox-exec", "-p", profile] + command
13- #else
14+ }
15+ #endif
16 // rdar://40235432, rdar://75636874 tracks implementing sandboxes for other platforms.
17 return command
18- #endif
19 }
20
21 /// Basic strictness level of a sandbox applied to a command line.