2020-11-06 00:22:26 +08:00
|
|
|
From e9d0448929a46df1b5923d69989fa3ca4c9e47ba Mon Sep 17 00:00:00 2001
|
2020-10-06 06:45:56 +08:00
|
|
|
From: Astro <astro@spaceboyz.net>
|
2020-11-06 00:22:26 +08:00
|
|
|
Date: Thu, 5 Nov 2020 17:21:09 +0100
|
2020-10-06 06:45:56 +08:00
|
|
|
Subject: [PATCH] networked derivations
|
|
|
|
|
|
|
|
---
|
2020-11-06 00:22:26 +08:00
|
|
|
src/libstore/build/derivation-goal.cc | 14 ++++++++------
|
|
|
|
src/libstore/build/derivation-goal.hh | 6 ++++++
|
|
|
|
2 files changed, 14 insertions(+), 6 deletions(-)
|
2020-10-06 06:45:56 +08:00
|
|
|
|
2020-11-06 00:22:26 +08:00
|
|
|
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc
|
|
|
|
index bf2bad62c..ef4ce8a0b 100644
|
|
|
|
--- a/src/libstore/build/derivation-goal.cc
|
|
|
|
+++ b/src/libstore/build/derivation-goal.cc
|
|
|
|
@@ -1199,6 +1199,8 @@ void DerivationGoal::startBuilder()
|
|
|
|
additionalSandboxProfile = parsedDrv->getStringAttr("__sandboxProfile").value_or("");
|
|
|
|
#endif
|
2020-10-06 06:45:56 +08:00
|
|
|
|
|
|
|
+ networked = parsedDrv->getBoolAttr("__networked");
|
|
|
|
+
|
2020-11-06 00:22:26 +08:00
|
|
|
/* Are we doing a chroot build? */
|
|
|
|
{
|
|
|
|
auto noChroot = parsedDrv->getBoolAttr("__noChroot");
|
|
|
|
@@ -1216,7 +1218,7 @@ void DerivationGoal::startBuilder()
|
2020-10-06 06:45:56 +08:00
|
|
|
else if (settings.sandboxMode == smDisabled)
|
|
|
|
useChroot = false;
|
|
|
|
else if (settings.sandboxMode == smRelaxed)
|
|
|
|
- useChroot = !(derivationIsImpure(derivationType)) && !noChroot;
|
|
|
|
+ useChroot = !allowNetwork() && !(derivationIsImpure(derivationType)) && !noChroot;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (worker.store.storeDir != worker.store.realStoreDir) {
|
2020-11-06 00:22:26 +08:00
|
|
|
@@ -1430,7 +1432,7 @@ void DerivationGoal::startBuilder()
|
|
|
|
"nogroup:x:65534:\n", sandboxGid()));
|
2020-10-06 06:45:56 +08:00
|
|
|
|
|
|
|
/* Create /etc/hosts with localhost entry. */
|
|
|
|
- if (!(derivationIsImpure(derivationType)))
|
2020-11-06 00:22:26 +08:00
|
|
|
+ if (!allowNetwork() && !(derivationIsImpure(derivationType)))
|
2020-10-06 06:45:56 +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,
|
2020-11-06 00:22:26 +08:00
|
|
|
@@ -1617,7 +1619,7 @@ void DerivationGoal::startBuilder()
|
2020-10-06 06:45:56 +08:00
|
|
|
us.
|
|
|
|
*/
|
|
|
|
|
|
|
|
- if (!(derivationIsImpure(derivationType)))
|
2020-11-06 00:22:26 +08:00
|
|
|
+ if (!allowNetwork() && !(derivationIsImpure(derivationType)))
|
2020-10-06 06:45:56 +08:00
|
|
|
privateNetwork = true;
|
|
|
|
|
|
|
|
userNamespaceSync.create();
|
2020-11-06 00:22:26 +08:00
|
|
|
@@ -1865,7 +1867,7 @@ void DerivationGoal::initEnv()
|
2020-10-06 06:45:56 +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). */
|
|
|
|
- if (derivationIsImpure(derivationType)) {
|
2020-11-06 00:22:26 +08:00
|
|
|
+ if (allowNetwork() || derivationIsImpure(derivationType)) {
|
2020-10-06 06:45:56 +08:00
|
|
|
for (auto & i : parsedDrv->getStringsAttr("impureEnvVars").value_or(Strings()))
|
|
|
|
env[i] = getEnv(i).value_or("");
|
|
|
|
}
|
2020-11-06 00:22:26 +08:00
|
|
|
@@ -2487,7 +2489,7 @@ void DerivationGoal::runChild()
|
2020-10-06 06:45:56 +08:00
|
|
|
/* Fixed-output derivations typically need to access the
|
|
|
|
network, so give them access to /etc/resolv.conf and so
|
|
|
|
on. */
|
|
|
|
- if (derivationIsImpure(derivationType)) {
|
2020-11-06 00:22:26 +08:00
|
|
|
+ if (allowNetwork() || derivationIsImpure(derivationType)) {
|
2020-10-06 06:45:56 +08:00
|
|
|
ss.push_back("/etc/resolv.conf");
|
|
|
|
|
|
|
|
// Only use nss functions to resolve hosts and
|
2020-11-06 00:22:26 +08:00
|
|
|
@@ -2728,7 +2730,7 @@ void DerivationGoal::runChild()
|
|
|
|
|
|
|
|
sandboxProfile += "(import \"sandbox-defaults.sb\")\n";
|
|
|
|
|
|
|
|
- if (derivationIsImpure(derivationType))
|
|
|
|
+ if (allowNetwork() || derivationIsImpure(derivationType))
|
|
|
|
sandboxProfile += "(import \"sandbox-network.sb\")\n";
|
|
|
|
|
|
|
|
/* Add the output paths we'll use at build-time to the chroot */
|
|
|
|
diff --git a/src/libstore/build/derivation-goal.hh b/src/libstore/build/derivation-goal.hh
|
|
|
|
index 4976207e0..c57238403 100644
|
|
|
|
--- a/src/libstore/build/derivation-goal.hh
|
|
|
|
+++ b/src/libstore/build/derivation-goal.hh
|
|
|
|
@@ -134,6 +134,12 @@ private:
|
|
|
|
/* Whether to run the build in a private network namespace. */
|
|
|
|
bool privateNetwork = false;
|
|
|
|
|
|
|
|
+ bool networked;
|
|
|
|
+ bool allowNetwork()
|
|
|
|
+ {
|
|
|
|
+ return derivationIsFixed(drv->type()) || networked;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
typedef void (DerivationGoal::*GoalState)();
|
|
|
|
GoalState state;
|
|
|
|
|
2020-10-06 06:45:56 +08:00
|
|
|
--
|
2020-11-06 00:22:26 +08:00
|
|
|
2.29.0
|
2020-10-06 06:45:56 +08:00
|
|
|
|