forked from M-Labs/it-infra
nixbld: update Nix unstable patch for networked derivations
Fixes Gitea issue #7
This commit is contained in:
parent
8f62706b08
commit
b10ee89454
|
@ -1,43 +1,27 @@
|
||||||
From d7fc00b5770a7d194c0ba9e70a4cdb2ece621d5b Mon Sep 17 00:00:00 2001
|
From e9d0448929a46df1b5923d69989fa3ca4c9e47ba Mon Sep 17 00:00:00 2001
|
||||||
From: Astro <astro@spaceboyz.net>
|
From: Astro <astro@spaceboyz.net>
|
||||||
Date: Mon, 5 Oct 2020 14:18:59 +0200
|
Date: Thu, 5 Nov 2020 17:21:09 +0100
|
||||||
Subject: [PATCH] networked derivations
|
Subject: [PATCH] networked derivations
|
||||||
|
|
||||||
---
|
---
|
||||||
src/libstore/build.cc | 19 ++++++++++++++-----
|
src/libstore/build/derivation-goal.cc | 14 ++++++++------
|
||||||
1 file changed, 14 insertions(+), 5 deletions(-)
|
src/libstore/build/derivation-goal.hh | 6 ++++++
|
||||||
|
2 files changed, 14 insertions(+), 6 deletions(-)
|
||||||
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
|
|
||||||
index 0499273a4..40fe4e859 100644
|
|
||||||
--- a/src/libstore/build.cc
|
|
||||||
+++ b/src/libstore/build.cc
|
|
||||||
@@ -845,9 +845,16 @@ private:
|
|
||||||
/* The sort of derivation we are building. */
|
|
||||||
DerivationType derivationType;
|
|
||||||
|
|
||||||
+ bool networked;
|
|
||||||
+
|
|
||||||
/* Whether to run the build in a private network namespace. */
|
|
||||||
bool privateNetwork = false;
|
|
||||||
|
|
||||||
+ bool allowNetwork()
|
|
||||||
+ {
|
|
||||||
+ return derivationIsFixed(drv->type()) || networked;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
typedef void (DerivationGoal::*GoalState)();
|
|
||||||
GoalState state;
|
|
||||||
|
|
||||||
@@ -1293,6 +1300,8 @@ void DerivationGoal::haveDerivation()
|
|
||||||
parsedDrv = std::make_unique<ParsedDerivation>(drvPath, *drv);
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
+ networked = parsedDrv->getBoolAttr("__networked");
|
+ networked = parsedDrv->getBoolAttr("__networked");
|
||||||
+
|
+
|
||||||
/* We are first going to try to create the invalid output paths
|
/* Are we doing a chroot build? */
|
||||||
through substitutes. If that doesn't work, we'll build
|
{
|
||||||
them. */
|
auto noChroot = parsedDrv->getBoolAttr("__noChroot");
|
||||||
@@ -2210,7 +2219,7 @@ void DerivationGoal::startBuilder()
|
@@ -1216,7 +1218,7 @@ void DerivationGoal::startBuilder()
|
||||||
else if (settings.sandboxMode == smDisabled)
|
else if (settings.sandboxMode == smDisabled)
|
||||||
useChroot = false;
|
useChroot = false;
|
||||||
else if (settings.sandboxMode == smRelaxed)
|
else if (settings.sandboxMode == smRelaxed)
|
||||||
|
@ -46,42 +30,68 @@ index 0499273a4..40fe4e859 100644
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worker.store.storeDir != worker.store.realStoreDir) {
|
if (worker.store.storeDir != worker.store.realStoreDir) {
|
||||||
@@ -2434,7 +2443,7 @@ void DerivationGoal::startBuilder()
|
@@ -1430,7 +1432,7 @@ void DerivationGoal::startBuilder()
|
||||||
"nogroup:x:65534:\n") % sandboxGid).str());
|
"nogroup:x:65534:\n", sandboxGid()));
|
||||||
|
|
||||||
/* Create /etc/hosts with localhost entry. */
|
/* Create /etc/hosts with localhost entry. */
|
||||||
- if (!(derivationIsImpure(derivationType)))
|
- if (!(derivationIsImpure(derivationType)))
|
||||||
+ if (!allowNetwork())
|
+ if (!allowNetwork() && !(derivationIsImpure(derivationType)))
|
||||||
writeFile(chrootRootDir + "/etc/hosts", "127.0.0.1 localhost\n::1 localhost\n");
|
writeFile(chrootRootDir + "/etc/hosts", "127.0.0.1 localhost\n::1 localhost\n");
|
||||||
|
|
||||||
/* Make the closure of the inputs available in the chroot,
|
/* Make the closure of the inputs available in the chroot,
|
||||||
@@ -2621,7 +2630,7 @@ void DerivationGoal::startBuilder()
|
@@ -1617,7 +1619,7 @@ void DerivationGoal::startBuilder()
|
||||||
us.
|
us.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- if (!(derivationIsImpure(derivationType)))
|
- if (!(derivationIsImpure(derivationType)))
|
||||||
+ if (!allowNetwork())
|
+ if (!allowNetwork() && !(derivationIsImpure(derivationType)))
|
||||||
privateNetwork = true;
|
privateNetwork = true;
|
||||||
|
|
||||||
userNamespaceSync.create();
|
userNamespaceSync.create();
|
||||||
@@ -2833,7 +2842,7 @@ void DerivationGoal::initEnv()
|
@@ -1865,7 +1867,7 @@ void DerivationGoal::initEnv()
|
||||||
to the builder is generally impure, but the output of
|
to the builder is generally impure, but the output of
|
||||||
fixed-output derivations is by definition pure (since we
|
fixed-output derivations is by definition pure (since we
|
||||||
already know the cryptographic hash of the output). */
|
already know the cryptographic hash of the output). */
|
||||||
- if (derivationIsImpure(derivationType)) {
|
- if (derivationIsImpure(derivationType)) {
|
||||||
+ if (allowNetwork()) {
|
+ if (allowNetwork() || derivationIsImpure(derivationType)) {
|
||||||
for (auto & i : parsedDrv->getStringsAttr("impureEnvVars").value_or(Strings()))
|
for (auto & i : parsedDrv->getStringsAttr("impureEnvVars").value_or(Strings()))
|
||||||
env[i] = getEnv(i).value_or("");
|
env[i] = getEnv(i).value_or("");
|
||||||
}
|
}
|
||||||
@@ -3447,7 +3456,7 @@ void DerivationGoal::runChild()
|
@@ -2487,7 +2489,7 @@ void DerivationGoal::runChild()
|
||||||
/* Fixed-output derivations typically need to access the
|
/* Fixed-output derivations typically need to access the
|
||||||
network, so give them access to /etc/resolv.conf and so
|
network, so give them access to /etc/resolv.conf and so
|
||||||
on. */
|
on. */
|
||||||
- if (derivationIsImpure(derivationType)) {
|
- if (derivationIsImpure(derivationType)) {
|
||||||
+ if (allowNetwork()) {
|
+ if (allowNetwork() || derivationIsImpure(derivationType)) {
|
||||||
ss.push_back("/etc/resolv.conf");
|
ss.push_back("/etc/resolv.conf");
|
||||||
|
|
||||||
// Only use nss functions to resolve hosts and
|
// Only use nss functions to resolve hosts and
|
||||||
--
|
@@ -2728,7 +2730,7 @@ void DerivationGoal::runChild()
|
||||||
2.28.0
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
--
|
||||||
|
2.29.0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue