Skip to content

Commit

Permalink
Fix macOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed May 20, 2020
1 parent 8e0bdc0 commit ff44f7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1395,11 +1395,7 @@ void DerivationGoal::tryToBuild()

void DerivationGoal::tryLocalBuild() {

/* If `build-users-group' is not empty, then we have to build as
one of the members of that group. */
static bool useBuildUsers = (settings.buildUsersGroup != "" || settings.startId.get() != 0) && getuid() == 0;
if (useBuildUsers) {
#if defined(__linux__) || defined(__APPLE__)
if (useBuildUsers()) {
if (!buildUser)
buildUser = acquireUserLock();

Expand All @@ -1412,11 +1408,6 @@ void DerivationGoal::tryLocalBuild() {
/* Make sure that no other processes are executing under this
uid. */
buildUser->kill();
#else
/* Don't know how to block the creation of setuid/setgid
binaries on this platform. */
throw Error("build users are not supported on this platform for security reasons");
#endif
}

try {
Expand Down
13 changes: 13 additions & 0 deletions src/libstore/user-lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,17 @@ std::unique_ptr<UserLock> acquireUserLock()
return SimpleUserLock::acquire();
}

bool useBuildUsers()
{
#if __linux__
static bool b = (settings.buildUsersGroup != "" || settings.startId.get() != 0) && getuid() == 0;
return b;
#elif __APPLE__
static bool b = settings.buildUsersGroup != "" && getuid() == 0;
return b;
#else
return false;
#endif
}

}
2 changes: 2 additions & 0 deletions src/libstore/user-lock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ struct UserLock
is available. */
std::unique_ptr<UserLock> acquireUserLock();

bool useBuildUsers();

}

0 comments on commit ff44f7e

Please sign in to comment.