Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/libstore/unix/build/derivation-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,21 @@ void DerivationBuilderImpl::startBuilder()
i.pop_back();
}
size_t p = i.find('=');
if (p == std::string::npos)
pathsInChroot[i] = {i, optional};
else
pathsInChroot[i.substr(0, p)] = {i.substr(p + 1), optional};

std::string inside, outside;
if (p == std::string::npos) {
inside = i;
outside = i;
} else {
inside = i.substr(0, p);
outside = i.substr(p + 1);
}

if (!optional && !maybeLstat(outside)) {
throw SysError("path '%s' is configured as part of the `sandbox-paths` option, but is inaccessible", outside);
}

pathsInChroot[inside] = {outside, optional};
}
if (hasPrefix(store.storeDir, tmpDirInSandbox))
{
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/linux-sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ nix-sandbox-build symlink-derivation.nix -A test_sandbox_paths \
--option extra-sandbox-paths "/dir=$TEST_ROOT" \
--option extra-sandbox-paths "/symlinkDir=$symlinkDir" \
--option extra-sandbox-paths "/symlink=$symlinkcert"

# Nonexistent sandbox paths should error early in the build process
expectStderr 1 nix-sandbox-build --option extra-sandbox-paths '/does-not-exist' \
-E 'with import '"${config_nix}"'; mkDerivation { name = "trivial"; buildCommand = "echo > $out"; }' |
grepQuiet "path '/does-not-exist' is configured as part of the \`sandbox-paths\` option, but is inaccessible"