libstore: make runPasta a function of LinuxLocalDerivationGoal

this way we can use it anywhere without fear of it being uninitialized.
only the linux platform bit uses this anyway, so we will move it there.

Change-Id: I35e207eec91daa8aa327c4f8b36c0dc8e703a7c4
This commit is contained in:
eldritch horrors
2026-01-28 12:41:26 +01:00
parent bd458f9f89
commit 7d3dde851a
3 changed files with 18 additions and 13 deletions
@@ -278,12 +278,6 @@ struct LocalDerivationGoal : public DerivationGoal
protected:
using DerivationGoal::DerivationGoal;
/**
* Whether to run pasta for network-endowed derivations. Running pasta
* currently requires actively waiting for its net-ns setup to finish.
*/
bool runPasta = false;
/**
* Setup dependencies outside the sandbox.
* Called in the parent nix process.
+3 -7
View File
@@ -904,7 +904,7 @@ void LinuxLocalDerivationGoal::prepareSandbox()
std::string LinuxLocalDerivationGoal::rewriteResolvConf(std::string fromHost)
{
if (!runPasta) {
if (!runPasta()) {
return fromHost;
}
@@ -1211,7 +1211,7 @@ bool LinuxLocalDerivationGoal::prepareChildSetup()
throw SysError("setuid failed");
}
if (runPasta) {
if (runPasta()) {
// wait for the pasta interface to appear. pasta can't signal us when
// it's done setting up the namespace, so we have to wait for a while
AutoCloseFD fd(socket(PF_INET, SOCK_DGRAM, IPPROTO_IP));
@@ -1299,10 +1299,6 @@ Pid LinuxLocalDerivationGoal::startChild(
us.
*/
// don't launch pasta unless we have a tun device. in a build sandbox we
// commonly do not, and trying to run pasta anyway naturally won't work.
runPasta = !privateNetwork() && settings.pastaPath != "" && pathExists("/dev/net/tun");
userNamespaceSync.create();
Pipe sendPid;
@@ -1408,7 +1404,7 @@ Pid LinuxLocalDerivationGoal::startChild(
/* Signal the builder that we've updated its user namespace. */
writeFull(userNamespaceSync.writeSide.get(), "1");
if (runPasta) {
if (runPasta()) {
// Bring up pasta, for handling FOD networking. We don't let it daemonize
// itself for process managements reasons and kill it manually when done.
+15
View File
@@ -109,5 +109,20 @@ private:
{
return derivationType.value().isSandboxed();
}
/**
* Whether to run pasta for network-endowed derivations. Running pasta
* currently requires actively waiting for its net-ns setup to finish.
*/
bool runPasta()
{
if (!_runPasta) {
// don't launch pasta unless we have a tun device. in a build sandbox we
// commonly do not, and trying to run pasta anyway naturally won't work.
_runPasta = !privateNetwork() && settings.pastaPath != "" && pathExists("/dev/net/tun");
}
return *_runPasta;
}
std::optional<bool> _runPasta;
};
}