mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Merge pull request #13297 from NixOS/split-linux-builder
Split LinuxDerivationBuilder
This commit is contained in:
commit
587b5f5361
2 changed files with 26 additions and 19 deletions
|
@ -2147,23 +2147,21 @@ std::unique_ptr<DerivationBuilder> makeDerivationBuilder(
|
|||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (useSandbox) {
|
||||
if (!mountAndPidNamespacesSupported()) {
|
||||
if (!settings.sandboxFallback)
|
||||
throw Error("this system does not support the kernel namespaces that are required for sandboxing; use '--no-sandbox' to disable sandboxing");
|
||||
debug("auto-disabling sandboxing because the prerequisite namespaces are not available");
|
||||
useSandbox = false;
|
||||
}
|
||||
if (useSandbox && !mountAndPidNamespacesSupported()) {
|
||||
if (!settings.sandboxFallback)
|
||||
throw Error("this system does not support the kernel namespaces that are required for sandboxing; use '--no-sandbox' to disable sandboxing");
|
||||
debug("auto-disabling sandboxing because the prerequisite namespaces are not available");
|
||||
useSandbox = false;
|
||||
}
|
||||
|
||||
if (useSandbox)
|
||||
return std::make_unique<LinuxDerivationBuilder>(
|
||||
return std::make_unique<ChrootLinuxDerivationBuilder>(
|
||||
store,
|
||||
std::move(miscMethods),
|
||||
std::move(params));
|
||||
#endif
|
||||
|
||||
if (params.drvOptions.useUidRange(params.drv))
|
||||
if (!useSandbox && params.drvOptions.useUidRange(params.drv))
|
||||
throw Error("feature 'uid-range' is only supported in sandboxed builds");
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -2172,6 +2170,11 @@ std::unique_ptr<DerivationBuilder> makeDerivationBuilder(
|
|||
std::move(miscMethods),
|
||||
std::move(params),
|
||||
useSandbox);
|
||||
#elif defined(__linux__)
|
||||
return std::make_unique<LinuxDerivationBuilder>(
|
||||
store,
|
||||
std::move(miscMethods),
|
||||
std::move(params));
|
||||
#else
|
||||
if (useSandbox)
|
||||
throw Error("sandboxing builds is not supported on this platform");
|
||||
|
|
|
@ -154,6 +154,18 @@ static void doBind(const Path & source, const Path & target, bool optional = fal
|
|||
}
|
||||
|
||||
struct LinuxDerivationBuilder : DerivationBuilderImpl
|
||||
{
|
||||
using DerivationBuilderImpl::DerivationBuilderImpl;
|
||||
|
||||
void enterChroot() override
|
||||
{
|
||||
setupSeccomp();
|
||||
|
||||
linux::setPersonality(drv.platform);
|
||||
}
|
||||
};
|
||||
|
||||
struct ChrootLinuxDerivationBuilder : LinuxDerivationBuilder
|
||||
{
|
||||
/**
|
||||
* Pipe for synchronising updates to the builder namespaces.
|
||||
|
@ -190,11 +202,7 @@ struct LinuxDerivationBuilder : DerivationBuilderImpl
|
|||
*/
|
||||
std::optional<Path> cgroup;
|
||||
|
||||
LinuxDerivationBuilder(
|
||||
Store & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params)
|
||||
: DerivationBuilderImpl(store, std::move(miscMethods), std::move(params))
|
||||
{
|
||||
}
|
||||
using LinuxDerivationBuilder::LinuxDerivationBuilder;
|
||||
|
||||
void deleteTmpDir(bool force) override
|
||||
{
|
||||
|
@ -776,11 +784,7 @@ struct LinuxDerivationBuilder : DerivationBuilderImpl
|
|||
if (rmdir("real-root") == -1)
|
||||
throw SysError("cannot remove real-root directory");
|
||||
|
||||
// FIXME: move to LinuxDerivationBuilder
|
||||
setupSeccomp();
|
||||
|
||||
// FIXME: move to LinuxDerivationBuilder
|
||||
linux::setPersonality(drv.platform);
|
||||
LinuxDerivationBuilder::enterChroot();
|
||||
}
|
||||
|
||||
void setUser() override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue