Skip to content

Commit

Permalink
Merge pull request #3429 from LnL7/darwin-sandbox
Browse files Browse the repository at this point in the history
darwin sandbox
  • Loading branch information
edolstra authored Mar 23, 2020
2 parents 7bc1961 + 2e9bc12 commit 5885e20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
14 changes: 6 additions & 8 deletions src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ namespace nix {
must be deleted and recreated on startup.) */
#define DEFAULT_SOCKET_PATH "/daemon-socket/socket"

/* chroot-like behavior from Apple's sandbox */
#if __APPLE__
#define DEFAULT_ALLOWED_IMPURE_PREFIXES "/System/Library /usr/lib /dev /bin/sh"
#else
#define DEFAULT_ALLOWED_IMPURE_PREFIXES ""
#endif

Settings settings;

static GlobalConfig::Register r1(&settings);
Expand Down Expand Up @@ -68,7 +61,12 @@ Settings::Settings()
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
#endif

allowedImpureHostPrefixes = tokenizeString<StringSet>(DEFAULT_ALLOWED_IMPURE_PREFIXES);

/* chroot-like behavior from Apple's sandbox */
#if __APPLE__
sandboxPaths = tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib");
allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh");
#endif
}

void loadConfFile()
Expand Down
7 changes: 1 addition & 6 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,7 @@ public:
Setting<bool> printMissing{this, true, "print-missing",
"Whether to print what paths need to be built or downloaded."};

Setting<std::string> preBuildHook{this,
#if __APPLE__
nixLibexecDir + "/nix/resolve-system-dependencies",
#else
"",
#endif
Setting<std::string> preBuildHook{this, "",
"pre-build-hook",
"A program to run just before a build to set derivation-specific build settings."};

Expand Down
10 changes: 10 additions & 0 deletions src/libstore/sandbox-defaults.sb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
(literal "/dev/zero")
(subpath "/dev/fd"))

; Allow pseudo-terminals.
(allow file*
(literal "/dev/ptmx")
(regex #"^/dev/pty[a-z]+")
(regex #"^/dev/ttys[0-9]+"))

; Does nothing, but reduces build noise.
(allow file* (literal "/dev/dtracehelper"))

Expand All @@ -85,3 +91,7 @@
(literal "/etc")
(literal "/var")
(literal "/private/var/tmp"))

; This is used by /bin/sh on macOS 10.15 and later.
(allow file*
(literal "/private/var/select/sh"))

0 comments on commit 5885e20

Please sign in to comment.