Skip to content

Commit dfa7b2a

Browse files
committed
libstore/unix/derivation-builder: error earlier when sandbox path is inaccessible
1 parent 2a96ae2 commit dfa7b2a

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/libstore/unix/build/derivation-builder.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,21 @@ void DerivationBuilderImpl::startBuilder()
992992
i.pop_back();
993993
}
994994
size_t p = i.find('=');
995-
if (p == std::string::npos)
996-
pathsInChroot[i] = {i, optional};
997-
else
998-
pathsInChroot[i.substr(0, p)] = {i.substr(p + 1), optional};
995+
996+
std::string inside, outside;
997+
if (p == std::string::npos) {
998+
inside = i;
999+
outside = i;
1000+
} else {
1001+
inside = i.substr(0, p);
1002+
outside = i.substr(p + 1);
1003+
}
1004+
1005+
if (!optional && !maybeLstat(outside)) {
1006+
throw SysError("path '%s' is configured as part of the `sandbox-paths` option, but is inaccessible", outside);
1007+
}
1008+
1009+
pathsInChroot[inside] = {outside, optional};
9991010
}
10001011
if (hasPrefix(store.storeDir, tmpDirInSandbox))
10011012
{

tests/functional/linux-sandbox.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,8 @@ nix-sandbox-build symlink-derivation.nix -A test_sandbox_paths \
9696
--option extra-sandbox-paths "/dir=$TEST_ROOT" \
9797
--option extra-sandbox-paths "/symlinkDir=$symlinkDir" \
9898
--option extra-sandbox-paths "/symlink=$symlinkcert"
99+
100+
# Nonexistent sandbox paths should error early in the build process
101+
expectStderr 1 nix-sandbox-build --option extra-sandbox-paths '/does-not-exist' \
102+
-E 'with import '"${config_nix}"'; mkDerivation { name = "trivial"; buildCommand = "echo > $out"; }' |
103+
grepQuiet "path '/does-not-exist' is configured as part of the \`sandbox-paths\` option, but is inaccessible"

0 commit comments

Comments
 (0)