Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

libstore: check additionalSandboxProfile #10652

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libstore/unix/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ void LocalDerivationGoal::killSandbox(bool getStats)

void LocalDerivationGoal::tryLocalBuild()
{
#if __APPLE__
additionalSandboxProfile = parsedDrv->getStringAttr("__sandboxProfile").value_or("");
#endif

unsigned int curBuilds = worker.getNrLocalBuilds();
if (curBuilds >= settings.maxBuildJobs) {
state = &DerivationGoal::tryToBuild;
Expand Down Expand Up @@ -495,10 +499,6 @@ void LocalDerivationGoal::startBuilder()
settings.thisSystem,
concatStringsSep<StringSet>(", ", worker.store.systemFeatures));

#if __APPLE__
additionalSandboxProfile = parsedDrv->getStringAttr("__sandboxProfile").value_or("");
#endif

/* Create a temporary directory where the build will take
place. */
tmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), false, false, 0700);
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/extra-sandbox-profile.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ destFile, seed }:

with import ./config.nix;

mkDerivation {
name = "simple";
__sandboxProfile = ''
# Allow writing any file in the filesystem
(allow file*)
'';
inherit seed;
buildCommand = ''
(
set -x
touch ${destFile}
touch $out
)
'';
}
23 changes: 23 additions & 0 deletions tests/functional/extra-sandbox-profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
source common.sh

if [[ $(uname) != Darwin ]]; then skipTest "Need Darwin"; fi

DEST_FILE="${TEST_ROOT}/foo"

testSandboxProfile () (
set -e

sandboxMode="$1"

rm -f "${DEST_FILE}"
nix-build --no-out-link ./extra-sandbox-profile.nix \
--option sandbox "$sandboxMode" \
--argstr seed "$RANDOM" \
--argstr destFile "${DEST_FILE}"

ls -l "${DEST_FILE}"
)

testSandboxProfile "false"
expectStderr 2 testSandboxProfile "true"
testSandboxProfile "relaxed"
1 change: 1 addition & 0 deletions tests/functional/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ nix_tests = \
nested-sandboxing.sh \
impure-env.sh \
debugger.sh \
extra-sandbox-profile.sh \
help.sh

ifeq ($(HAVE_LIBCPUID), 1)
Expand Down