mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
DerivationBuilderImpl: Drop std::optional from derivationType
No point in computing this lazily, since it's pretty much the first thing the DerivationBuilder does.
This commit is contained in:
parent
6adee1145f
commit
aaca9711fc
1 changed files with 12 additions and 15 deletions
|
@ -100,6 +100,7 @@ public:
|
||||||
: DerivationBuilderParams{std::move(params)}
|
: DerivationBuilderParams{std::move(params)}
|
||||||
, store{store}
|
, store{store}
|
||||||
, miscMethods{std::move(miscMethods)}
|
, miscMethods{std::move(miscMethods)}
|
||||||
|
, derivationType{drv.type()}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
LocalStore & getLocalStore();
|
LocalStore & getLocalStore();
|
||||||
|
@ -168,9 +169,9 @@ private:
|
||||||
/**
|
/**
|
||||||
* The sort of derivation we are building.
|
* The sort of derivation we are building.
|
||||||
*
|
*
|
||||||
* Just a cached value, can be recomputed from `drv`.
|
* Just a cached value, computed from `drv`.
|
||||||
*/
|
*/
|
||||||
std::optional<DerivationType> derivationType;
|
const DerivationType derivationType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stuff we need to pass to initChild().
|
* Stuff we need to pass to initChild().
|
||||||
|
@ -438,9 +439,6 @@ void DerivationBuilderImpl::killSandbox(bool getStats)
|
||||||
|
|
||||||
bool DerivationBuilderImpl::prepareBuild()
|
bool DerivationBuilderImpl::prepareBuild()
|
||||||
{
|
{
|
||||||
/* Cache this */
|
|
||||||
derivationType = drv.type();
|
|
||||||
|
|
||||||
/* Are we doing a chroot build? */
|
/* Are we doing a chroot build? */
|
||||||
{
|
{
|
||||||
if (settings.sandboxMode == smEnabled) {
|
if (settings.sandboxMode == smEnabled) {
|
||||||
|
@ -457,7 +455,7 @@ bool DerivationBuilderImpl::prepareBuild()
|
||||||
else if (settings.sandboxMode == smDisabled)
|
else if (settings.sandboxMode == smDisabled)
|
||||||
useChroot = false;
|
useChroot = false;
|
||||||
else if (settings.sandboxMode == smRelaxed)
|
else if (settings.sandboxMode == smRelaxed)
|
||||||
useChroot = derivationType->isSandboxed() && !drvOptions.noChroot;
|
useChroot = derivationType.isSandboxed() && !drvOptions.noChroot;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & localStore = getLocalStore();
|
auto & localStore = getLocalStore();
|
||||||
|
@ -594,11 +592,10 @@ std::variant<std::pair<BuildResult::Status, Error>, SingleDrvOutputs> Derivation
|
||||||
return std::move(builtOutputs);
|
return std::move(builtOutputs);
|
||||||
|
|
||||||
} catch (BuildError & e) {
|
} catch (BuildError & e) {
|
||||||
assert(derivationType);
|
|
||||||
BuildResult::Status st =
|
BuildResult::Status st =
|
||||||
dynamic_cast<NotDeterministic*>(&e) ? BuildResult::NotDeterministic :
|
dynamic_cast<NotDeterministic*>(&e) ? BuildResult::NotDeterministic :
|
||||||
statusOk(status) ? BuildResult::OutputRejected :
|
statusOk(status) ? BuildResult::OutputRejected :
|
||||||
!derivationType->isSandboxed() || diskFull ? BuildResult::TransientFailure :
|
!derivationType.isSandboxed() || diskFull ? BuildResult::TransientFailure :
|
||||||
BuildResult::PermanentFailure;
|
BuildResult::PermanentFailure;
|
||||||
|
|
||||||
return std::pair{std::move(st), std::move(e)};
|
return std::pair{std::move(st), std::move(e)};
|
||||||
|
@ -1068,7 +1065,7 @@ void DerivationBuilderImpl::startBuilder()
|
||||||
"nogroup:x:65534:\n", sandboxGid()));
|
"nogroup:x:65534:\n", sandboxGid()));
|
||||||
|
|
||||||
/* Create /etc/hosts with localhost entry. */
|
/* Create /etc/hosts with localhost entry. */
|
||||||
if (derivationType->isSandboxed())
|
if (derivationType.isSandboxed())
|
||||||
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,
|
||||||
|
@ -1296,7 +1293,7 @@ void DerivationBuilderImpl::startBuilder()
|
||||||
|
|
||||||
ProcessOptions options;
|
ProcessOptions options;
|
||||||
options.cloneFlags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_PARENT | SIGCHLD;
|
options.cloneFlags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_PARENT | SIGCHLD;
|
||||||
if (derivationType->isSandboxed())
|
if (derivationType.isSandboxed())
|
||||||
options.cloneFlags |= CLONE_NEWNET;
|
options.cloneFlags |= CLONE_NEWNET;
|
||||||
if (usingUserNamespace)
|
if (usingUserNamespace)
|
||||||
options.cloneFlags |= CLONE_NEWUSER;
|
options.cloneFlags |= CLONE_NEWUSER;
|
||||||
|
@ -1502,7 +1499,7 @@ void DerivationBuilderImpl::initEnv()
|
||||||
derivation, tell the builder, so that for instance `fetchurl'
|
derivation, tell the builder, so that for instance `fetchurl'
|
||||||
can skip checking the output. On older Nixes, this environment
|
can skip checking the output. On older Nixes, this environment
|
||||||
variable won't be set, so `fetchurl' will do the check. */
|
variable won't be set, so `fetchurl' will do the check. */
|
||||||
if (derivationType->isFixed()) env["NIX_OUTPUT_CHECKED"] = "1";
|
if (derivationType.isFixed()) env["NIX_OUTPUT_CHECKED"] = "1";
|
||||||
|
|
||||||
/* *Only* if this is a fixed-output derivation, propagate the
|
/* *Only* if this is a fixed-output derivation, propagate the
|
||||||
values of the environment variables specified in the
|
values of the environment variables specified in the
|
||||||
|
@ -1513,7 +1510,7 @@ void DerivationBuilderImpl::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 (!derivationType->isSandboxed()) {
|
if (!derivationType.isSandboxed()) {
|
||||||
auto & impureEnv = settings.impureEnv.get();
|
auto & impureEnv = settings.impureEnv.get();
|
||||||
if (!impureEnv.empty())
|
if (!impureEnv.empty())
|
||||||
experimentalFeatureSettings.require(Xp::ConfigurableImpureEnv);
|
experimentalFeatureSettings.require(Xp::ConfigurableImpureEnv);
|
||||||
|
@ -1863,7 +1860,7 @@ void DerivationBuilderImpl::runChild()
|
||||||
|
|
||||||
userNamespaceSync.readSide = -1;
|
userNamespaceSync.readSide = -1;
|
||||||
|
|
||||||
if (derivationType->isSandboxed()) {
|
if (derivationType.isSandboxed()) {
|
||||||
|
|
||||||
/* Initialise the loopback interface. */
|
/* Initialise the loopback interface. */
|
||||||
AutoCloseFD fd(socket(PF_INET, SOCK_DGRAM, IPPROTO_IP));
|
AutoCloseFD fd(socket(PF_INET, SOCK_DGRAM, IPPROTO_IP));
|
||||||
|
@ -1939,7 +1936,7 @@ void DerivationBuilderImpl::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 (!derivationType->isSandboxed()) {
|
if (!derivationType.isSandboxed()) {
|
||||||
// Only use nss functions to resolve hosts and
|
// Only use nss functions to resolve hosts and
|
||||||
// services. Don’t use it for anything else that may
|
// services. Don’t use it for anything else that may
|
||||||
// be configured for this system. This limits the
|
// be configured for this system. This limits the
|
||||||
|
@ -2172,7 +2169,7 @@ void DerivationBuilderImpl::runChild()
|
||||||
#include "sandbox-defaults.sb"
|
#include "sandbox-defaults.sb"
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!derivationType->isSandboxed())
|
if (!derivationType.isSandboxed())
|
||||||
sandboxProfile +=
|
sandboxProfile +=
|
||||||
#include "sandbox-network.sb"
|
#include "sandbox-network.sb"
|
||||||
;
|
;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue