2021-04-24 17:07:14 +08:00
|
|
|
|
diff -Naur /nix/store/32wd1lrf55ymaz1aysrqffpxfgkwl6m4-source/src/libstore/build/local-derivation-goal.cc nix3/src/libstore/build/local-derivation-goal.cc
|
|
|
|
|
--- /nix/store/32wd1lrf55ymaz1aysrqffpxfgkwl6m4-source/src/libstore/build/local-derivation-goal.cc 1970-01-01 08:00:01.000000000 +0800
|
|
|
|
|
+++ nix3/src/libstore/build/local-derivation-goal.cc 2021-04-24 16:29:52.493166702 +0800
|
|
|
|
|
@@ -395,6 +395,8 @@
|
2020-11-06 00:22:26 +08:00
|
|
|
|
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");
|
2021-04-24 17:07:14 +08:00
|
|
|
|
@@ -412,7 +414,7 @@
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 17:07:14 +08:00
|
|
|
|
auto & localStore = getLocalStore();
|
|
|
|
|
@@ -623,7 +625,7 @@
|
2020-11-06 00:22:26 +08:00
|
|
|
|
"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,
|
2021-04-24 17:07:14 +08:00
|
|
|
|
@@ -810,7 +812,7 @@
|
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();
|
2021-04-24 17:07:14 +08:00
|
|
|
|
@@ -1066,7 +1068,7 @@
|
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("");
|
|
|
|
|
}
|
2021-04-24 17:07:14 +08:00
|
|
|
|
@@ -1702,7 +1704,7 @@
|
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
|
|
|
|
// Only use nss functions to resolve hosts and
|
2021-04-24 17:07:14 +08:00
|
|
|
|
// services. Don’t use it for anything else that may
|
|
|
|
|
// be configured for this system. This limits the
|
|
|
|
|
@@ -1943,7 +1945,7 @@
|
2020-11-06 00:22:26 +08:00
|
|
|
|
|
|
|
|
|
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 */
|
2021-04-24 17:07:14 +08:00
|
|
|
|
diff -Naur /nix/store/32wd1lrf55ymaz1aysrqffpxfgkwl6m4-source/src/libstore/build/local-derivation-goal.hh nix3/src/libstore/build/local-derivation-goal.hh
|
|
|
|
|
--- /nix/store/32wd1lrf55ymaz1aysrqffpxfgkwl6m4-source/src/libstore/build/local-derivation-goal.hh 1970-01-01 08:00:01.000000000 +0800
|
|
|
|
|
+++ nix3/src/libstore/build/local-derivation-goal.hh 2021-04-24 16:35:23.060968488 +0800
|
|
|
|
|
@@ -40,6 +40,12 @@
|
|
|
|
|
|
|
|
|
|
Path chrootRootDir;
|
2020-11-06 00:22:26 +08:00
|
|
|
|
|
|
|
|
|
+ bool networked;
|
|
|
|
|
+ bool allowNetwork()
|
|
|
|
|
+ {
|
|
|
|
|
+ return derivationIsFixed(drv->type()) || networked;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
2021-04-24 17:07:14 +08:00
|
|
|
|
/* RAII object to delete the chroot directory. */
|
|
|
|
|
std::shared_ptr<AutoDelete> autoDelChroot;
|
2020-11-06 00:22:26 +08:00
|
|
|
|
|