1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 04:56:01 +01:00

Merge pull request #88 from DeterminateSystems/fh-846-improve-nix-error-when-sandbox-path-doesnt-exist

libstore/unix/derivation-builder: error earlier when sandbox path is inaccessible
This commit is contained in:
Cole Helbling 2025-06-04 19:27:59 +00:00 committed by GitHub
commit e98cad60b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View file

@ -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))
{

View file

@ -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"