2022-06-04 13:52:21 +08:00
|
|
|
|
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
|
2023-12-16 13:03:19 +08:00
|
|
|
|
index 64b55ca6a..9b4e52b8e 100644
|
2022-06-04 13:52:21 +08:00
|
|
|
|
--- a/src/libstore/build/local-derivation-goal.cc
|
|
|
|
|
+++ b/src/libstore/build/local-derivation-goal.cc
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -180,6 +180,8 @@ void LocalDerivationGoal::tryLocalBuild()
|
|
|
|
|
|
|
|
|
|
assert(derivationType);
|
2022-06-04 13:52:21 +08:00
|
|
|
|
|
|
|
|
|
+ networked = parsedDrv->getBoolAttr("__networked");
|
|
|
|
|
+
|
|
|
|
|
/* Are we doing a chroot build? */
|
|
|
|
|
{
|
|
|
|
|
auto noChroot = parsedDrv->getBoolAttr("__noChroot");
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -197,7 +199,7 @@ void LocalDerivationGoal::tryLocalBuild()
|
2022-06-04 13:52:21 +08:00
|
|
|
|
else if (settings.sandboxMode == smDisabled)
|
|
|
|
|
useChroot = false;
|
|
|
|
|
else if (settings.sandboxMode == smRelaxed)
|
2023-12-16 13:03:19 +08:00
|
|
|
|
- useChroot = derivationType->isSandboxed() && !noChroot;
|
|
|
|
|
+ useChroot = !networked && derivationType->isSandboxed() && !noChroot;
|
2022-06-04 13:52:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto & localStore = getLocalStore();
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -691,7 +693,7 @@ void LocalDerivationGoal::startBuilder()
|
2022-06-04 13:52:21 +08:00
|
|
|
|
"nogroup:x:65534:\n", sandboxGid()));
|
|
|
|
|
|
|
|
|
|
/* Create /etc/hosts with localhost entry. */
|
2023-12-16 13:03:19 +08:00
|
|
|
|
- if (derivationType->isSandboxed())
|
|
|
|
|
+ if (!networked && derivationType->isSandboxed())
|
2022-06-04 13:52:21 +08:00
|
|
|
|
writeFile(chrootRootDir + "/etc/hosts", "127.0.0.1 localhost\n::1 localhost\n");
|
|
|
|
|
|
|
|
|
|
/* Make the closure of the inputs available in the chroot,
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -895,7 +897,7 @@ void LocalDerivationGoal::startBuilder()
|
2022-06-04 13:52:21 +08:00
|
|
|
|
us.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-12-16 13:03:19 +08:00
|
|
|
|
- if (derivationType->isSandboxed())
|
|
|
|
|
+ if (!networked && derivationType->isSandboxed())
|
2022-06-04 13:52:21 +08:00
|
|
|
|
privateNetwork = true;
|
|
|
|
|
|
|
|
|
|
userNamespaceSync.create();
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -1134,7 +1136,7 @@ void LocalDerivationGoal::initEnv()
|
2022-06-04 13:52:21 +08:00
|
|
|
|
to the builder is generally impure, but the output of
|
|
|
|
|
fixed-output derivations is by definition pure (since we
|
|
|
|
|
already know the cryptographic hash of the output). */
|
2023-12-16 13:03:19 +08:00
|
|
|
|
- if (!derivationType->isSandboxed()) {
|
|
|
|
|
+ if (networked || !derivationType->isSandboxed()) {
|
2022-06-04 13:52:21 +08:00
|
|
|
|
for (auto & i : parsedDrv->getStringsAttr("impureEnvVars").value_or(Strings()))
|
|
|
|
|
env[i] = getEnv(i).value_or("");
|
|
|
|
|
}
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -1799,7 +1801,7 @@ void LocalDerivationGoal::runChild()
|
2022-06-04 13:52:21 +08:00
|
|
|
|
/* Fixed-output derivations typically need to access the
|
|
|
|
|
network, so give them access to /etc/resolv.conf and so
|
|
|
|
|
on. */
|
2023-12-16 13:03:19 +08:00
|
|
|
|
- if (!derivationType->isSandboxed()) {
|
|
|
|
|
+ if (networked || !derivationType->isSandboxed()) {
|
2022-06-04 13:52:21 +08:00
|
|
|
|
// Only use nss functions to resolve hosts and
|
|
|
|
|
// services. Don’t use it for anything else that may
|
|
|
|
|
// be configured for this system. This limits the
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -2050,7 +2052,7 @@ void LocalDerivationGoal::runChild()
|
2023-06-02 17:36:05 +08:00
|
|
|
|
#include "sandbox-defaults.sb"
|
|
|
|
|
;
|
2022-06-04 13:52:21 +08:00
|
|
|
|
|
2023-12-16 13:03:19 +08:00
|
|
|
|
- if (!derivationType->isSandboxed())
|
|
|
|
|
+ if (networked || !derivationType->isSandboxed())
|
2023-06-02 17:36:05 +08:00
|
|
|
|
sandboxProfile +=
|
|
|
|
|
#include "sandbox-network.sb"
|
|
|
|
|
;
|
2022-06-04 13:52:21 +08:00
|
|
|
|
diff --git a/src/libstore/build/local-derivation-goal.hh b/src/libstore/build/local-derivation-goal.hh
|
2023-12-16 13:03:19 +08:00
|
|
|
|
index 0a05081c7..4c251718c 100644
|
2022-06-04 13:52:21 +08:00
|
|
|
|
--- a/src/libstore/build/local-derivation-goal.hh
|
|
|
|
|
+++ b/src/libstore/build/local-derivation-goal.hh
|
2023-12-16 13:03:19 +08:00
|
|
|
|
@@ -66,6 +66,8 @@ struct LocalDerivationGoal : public DerivationGoal
|
2022-06-04 13:52:21 +08:00
|
|
|
|
|
|
|
|
|
Path chrootRootDir;
|
|
|
|
|
|
|
|
|
|
+ bool networked;
|
|
|
|
|
+
|
2023-12-16 13:03:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* RAII object to delete the chroot directory.
|
|
|
|
|
*/
|