Nix  2.93.0-dev
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::LocalDerivationGoal Struct Reference
Inheritance diagram for nix::LocalDerivationGoal:
[legend]
Collaboration diagram for nix::LocalDerivationGoal:
[legend]

Classes

struct  ChrootPath
 

Public Types

typedef map< Path, ChrootPathPathsInChroot
 
typedef map< std::string, std::string > Environment
 
typedef map< StorePath, StorePathRedirectedOutputs
 
- Public Types inherited from nix::DerivationGoal
enum struct  NeedRestartForMoreOutputs { OutputsUnmodifedDontNeed , OutputsAddedDoNeed , BuildInProgressWillNotNeed }
 
enum  RetrySubstitution { NoNeed , YesNeed , AlreadyRetried }
 
- Public Types inherited from nix::Goal
enum  ExitCode { ecSuccess , ecFailed , ecNoSubstituters , ecIncompleteClosure }
 

Public Member Functions

LocalStoregetLocalStore ()
 
uid_t sandboxUid ()
 
gid_t sandboxGid ()
 
bool isAllowed (const StorePath &path)
 
bool isAllowed (const DrvOutput &id)
 
bool isAllowed (const DerivedPath &req)
 
virtual bool needsHashRewrite ()
 
kj::Promise< Result< WorkResult > > tryLocalBuild () noexcept override
 
kj::Promise< Result< void > > startBuilder ()
 
void initEnv ()
 
void initTmpDir ()
 
kj::Promise< Result< void > > writeStructuredAttrs ()
 
void startDaemon ()
 
void stopDaemon ()
 
void addDependency (const StorePath &path)
 
void chownToBuilder (const Path &path)
 
int getChildStatus () override
 
void runChild ()
 
kj::Promise< Result< SingleDrvOutputs > > registerOutputs () override
 
void signRealisation (Realisation &) override
 
kj::Promise< Result< void > > checkOutputs (const std::map< std::string, ValidPathInfo > &outputs, const std::map< std::string, StorePath > &alreadyRegisteredOutputs)
 
void closeReadPipes () override
 
void cleanupHookFinally () override
 
void cleanupPreChildKill () override
 
void cleanupPostChildKill () override
 
bool cleanupDecideWhetherDiskFull () override
 
void cleanupPostOutputsRegisteredModeCheck () override
 
void cleanupPostOutputsRegisteredModeNonCheck () override
 
void deleteTmpDir (bool force, bool duringDestruction=false)
 
void killChild () override final
 
virtual void killSandbox (bool getStats)
 
StorePath makeFallbackPath (const StorePath &path)
 
StorePath makeFallbackPath (OutputNameView outputName)
 
- Public Member Functions inherited from nix::DerivationGoal
 DerivationGoal (const StorePath &drvPath, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode=bmNormal)
 
 DerivationGoal (DrvHasRoot, const StorePath &drvPath, const BasicDerivation &drv, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode=bmNormal)
 
WorkResult timedOut (Error &&ex)
 
kj::Promise< Result< WorkResult > > workImpl () noexcept override
 
bool addWantedOutputs (const OutputsSpec &outputs)
 
kj::Promise< Result< WorkResult > > getDerivation () noexcept
 
kj::Promise< Result< WorkResult > > loadDerivation () noexcept
 
kj::Promise< Result< WorkResult > > haveDerivation () noexcept
 
kj::Promise< Result< WorkResult > > outputsSubstitutionTried () noexcept
 
kj::Promise< Result< WorkResult > > gaveUpOnSubstitution () noexcept
 
kj::Promise< Result< WorkResult > > closureRepaired () noexcept
 
kj::Promise< Result< WorkResult > > inputsRealised () noexcept
 
kj::Promise< Result< WorkResult > > tryToBuild () noexcept
 
kj::Promise< Result< WorkResult > > buildDone () noexcept
 
kj::Promise< Result< WorkResult > > resolvedFinished () noexcept
 
HookReply tryBuildHook ()
 
Path openLogFile ()
 
void closeLogFile ()
 
kj::Promise< Result< std::map< std::string, std::optional< StorePath > > > > queryPartialDerivationOutputMap ()
 
kj::Promise< Result< OutputPathMap > > queryDerivationOutputMap ()
 
kj::Promise< Result< std::pair< bool, SingleDrvOutputs > > > checkPathValidity ()
 
kj::Promise< Result< SingleDrvOutputs > > assertPathValidity ()
 
kj::Promise< Result< WorkResult > > repairClosure () noexcept
 
void started ()
 
WorkResult done (BuildResult::Status status, SingleDrvOutputs builtOutputs={}, std::optional< Error > ex={})
 
void waiteeDone (GoalPtr waitee) override
 
StorePathSet exportReferences (const StorePathSet &storePaths)
 
JobCategory jobCategory () const override
 Hint for the scheduler, which concurrency limit applies.
 
- Public Member Functions inherited from nix::Goal
 Goal (Worker &worker, bool isDependency)
 
kj::Promise< Result< WorkResult > > work () noexcept
 
void trace (std::string_view s)
 
std::string getName () const
 
virtual void cleanup ()
 

Static Public Member Functions

static std::unique_ptr< LocalDerivationGoalmakeLocalDerivationGoal (const StorePath &drvPath, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode)
 
static std::unique_ptr< LocalDerivationGoalmakeLocalDerivationGoal (DrvHasRoot drvRoot, const StorePath &drvPath, const BasicDerivation &drv, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode)
 

Public Attributes

std::unique_ptr< UserLockbuildUser
 
Pid pid
 
std::optional< Pathcgroup
 
Path tmpDir
 
Path tmpDirInSandbox
 
AutoCloseFD builderOutPTY
 
Pipe userNamespaceSync
 
AutoCloseFD sandboxMountNamespace
 
AutoCloseFD sandboxUserNamespace
 
bool usingUserNamespace = true
 
bool useChroot = false
 
Path chrootRootDir
 
std::shared_ptr< AutoDeleteautoDelChroot
 
bool privateNetwork = false
 
PathsInChroot pathsInChroot
 
Environment env
 
StringMap inputRewrites
 
StringMap outputRewrites
 
RedirectedOutputs redirectedOutputs
 
OutputPathMap scratchOutputs
 
std::map< Path, ValidPathInfoprevInfos
 
AutoCloseFD daemonSocket
 
std::thread daemonThread
 
std::vector< std::thread > daemonWorkerThreads
 
StorePathSet addedPaths
 
std::set< DrvOutputaddedDrvOutputs
 
- Public Attributes inherited from nix::DerivationGoal
bool isDone = false
 
bool useDerivation
 
StorePath drvPath
 
std::shared_ptr< DerivationGoalresolvedDrvGoal
 
OutputsSpec wantedOutputs
 
std::map< std::pair< StorePath, std::string >, StorePathinputDrvOutputs
 
NeedRestartForMoreOutputs needRestart = NeedRestartForMoreOutputs::OutputsUnmodifedDontNeed
 
bool anyHashMismatchSeen = false
 
bool anyCheckMismatchSeen = false
 
RetrySubstitution retrySubstitution = RetrySubstitution::NoNeed
 
std::unique_ptr< Derivationdrv
 
std::unique_ptr< ParsedDerivationparsedDrv
 
std::optional< PathLocks > outputLocks
 
StorePathSet inputPaths
 
std::map< std::string, InitialOutputinitialOutputs
 
BuildResult buildResult
 
AutoCloseFD fdLogFile
 
std::shared_ptr< BufferedSinklogFileSink
 
std::shared_ptr< BufferedSinklogSink
 
unsigned long logSize
 
std::list< std::string > logTail
 
std::string currentLogLine
 
size_t currentLogLinePos = 0
 
std::string currentHookLine
 
std::unique_ptr< HookInstancehook
 
AutoCloseFDbuilderOutFD = nullptr
 
std::optional< DerivationTypederivationType
 
BuildMode buildMode
 
NotifyingCounter< uint64_t >::Bump mcExpectedBuilds
 
NotifyingCounter< uint64_t >::Bump mcRunningBuilds
 
std::unique_ptr< Activityact
 
std::unique_ptr< ActivityactLock
 
std::map< ActivityId, ActivitybuilderActivities
 
std::string machineName
 
- Public Attributes inherited from nix::Goal
Workerworker
 
const bool isDependency
 
size_t nrFailed = 0
 
size_t nrNoSubstituters = 0
 
size_t nrIncompleteClosure = 0
 
std::string name
 

Static Public Attributes

static const Path homeDir = "/homeless-shelter"
 

Protected Member Functions

virtual void prepareSandbox ()
 
virtual Pid startChild (std::function< void()> openSlave)
 
virtual void setupSyscallFilter ()
 
virtual void execBuilder (std::string builder, Strings args, Strings envStrs)
 
virtual bool supportsUidRange ()
 
virtual bool respectsTimeouts () override
 
 DerivationGoal (const StorePath &drvPath, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode=bmNormal)
 
 DerivationGoal (DrvHasRoot, const StorePath &drvPath, const BasicDerivation &drv, const OutputsSpec &wantedOutputs, Worker &worker, bool isDependency, BuildMode buildMode=bmNormal)
 
- Protected Member Functions inherited from nix::DerivationGoal
kj::Promise< Outcome< void, WorkResult > > handleChildOutput () noexcept
 
kj::Promise< Outcome< void, WorkResult > > handleChildStreams (InputStream &builderIn, InputStream *hookIn) noexcept
 
kj::Promise< Outcome< void, WorkResult > > handleBuilderOutput (InputStream &in) noexcept
 
kj::Promise< Outcome< void, WorkResult > > handleHookOutput (InputStream &in) noexcept
 
kj::Promise< Outcome< void, WorkResult > > monitorForSilence () noexcept
 
WorkResult tooMuchLogs ()
 
void flushLine ()
 
- Protected Member Functions inherited from nix::Goal
kj::Promise< void > waitForAWhile ()
 
kj::Promise< Result< void > > waitForGoals (kj::Array< std::pair< GoalPtr, kj::Promise< Result< WorkResult > > > > dependencies) noexcept
 
template<std::derived_from< Goal >... G>
kj::Promise< Result< void > > waitForGoals (std::pair< std::shared_ptr< G >, kj::Promise< Result< WorkResult > > >... goals) noexcept
 

Friends

struct RestrictedStore
 

Additional Inherited Members

- Protected Attributes inherited from nix::DerivationGoal
kj::TimePoint lastChildActivity = kj::minValue
 
- Protected Attributes inherited from nix::Goal
AsyncSemaphore::Token slotToken
 

Member Function Documentation

◆ addDependency()

void nix::LocalDerivationGoal::addDependency ( const StorePath & path)

Add 'path' to the set of paths that may be referenced by the outputs, and make it appear in the sandbox.

◆ checkOutputs()

kj::Promise< Result< void > > nix::LocalDerivationGoal::checkOutputs ( const std::map< std::string, ValidPathInfo > & outputs,
const std::map< std::string, StorePath > & alreadyRegisteredOutputs )

Check that an output meets the requirements specified by the 'outputChecks' attribute (or the legacy '{allowed,disallowed}{References,Requisites}' attributes).

◆ chownToBuilder()

void nix::LocalDerivationGoal::chownToBuilder ( const Path & path)

Make a file owned by the builder.

◆ cleanupDecideWhetherDiskFull()

bool nix::LocalDerivationGoal::cleanupDecideWhetherDiskFull ( )
overridevirtual

Reimplemented from nix::DerivationGoal.

◆ cleanupHookFinally()

void nix::LocalDerivationGoal::cleanupHookFinally ( )
overridevirtual

Cleanup hooks for buildDone()

Reimplemented from nix::DerivationGoal.

◆ cleanupPostChildKill()

void nix::LocalDerivationGoal::cleanupPostChildKill ( )
overridevirtual

Reimplemented from nix::DerivationGoal.

◆ cleanupPostOutputsRegisteredModeCheck()

void nix::LocalDerivationGoal::cleanupPostOutputsRegisteredModeCheck ( )
overridevirtual

Reimplemented from nix::DerivationGoal.

◆ cleanupPostOutputsRegisteredModeNonCheck()

void nix::LocalDerivationGoal::cleanupPostOutputsRegisteredModeNonCheck ( )
overridevirtual

Reimplemented from nix::DerivationGoal.

◆ cleanupPreChildKill()

void nix::LocalDerivationGoal::cleanupPreChildKill ( )
overridevirtual

Reimplemented from nix::DerivationGoal.

◆ closeReadPipes()

void nix::LocalDerivationGoal::closeReadPipes ( )
overridevirtual

Close the read side of the logger pipe.

Reimplemented from nix::DerivationGoal.

◆ deleteTmpDir()

void nix::LocalDerivationGoal::deleteTmpDir ( bool force,
bool duringDestruction = false )

Delete the temporary directory, if we have one.

◆ execBuilder()

void nix::LocalDerivationGoal::execBuilder ( std::string builder,
Strings args,
Strings envStrs )
protectedvirtual

Execute the builder, replacing the current process. Generally this means an execve call.

◆ getChildStatus()

int nix::LocalDerivationGoal::getChildStatus ( )
overridevirtual

Reimplemented from nix::DerivationGoal.

◆ initEnv()

void nix::LocalDerivationGoal::initEnv ( )

Fill in the environment for the builder.

◆ initTmpDir()

void nix::LocalDerivationGoal::initTmpDir ( )

Setup tmp dir location.

◆ isAllowed()

bool nix::LocalDerivationGoal::isAllowed ( const StorePath & path)
inline

Recursive Nix calls are only allowed to build or realize paths in the original input closure or added via a recursive Nix call (so e.g. you can't do 'nix-store -r /nix/store/<bla>' where /nix/store/<bla> is some arbitrary path in a binary cache).

◆ killChild()

void nix::LocalDerivationGoal::killChild ( )
finaloverridevirtual

Forcibly kill the child process, if any.

Called by destructor, can't be overridden

Reimplemented from nix::DerivationGoal.

◆ killSandbox()

void nix::LocalDerivationGoal::killSandbox ( bool getStats)
virtual

Kill any processes running under the build user UID or in the cgroup of the build.

◆ makeFallbackPath() [1/2]

StorePath nix::LocalDerivationGoal::makeFallbackPath ( const StorePath & path)

Create alternative path calculated from but distinct from the input, so we can avoid overwriting outputs (or other store paths) that already exist.

◆ makeFallbackPath() [2/2]

StorePath nix::LocalDerivationGoal::makeFallbackPath ( OutputNameView outputName)

Make a path to another based on the output name along with the derivation hash.

Todo
Add option to randomize, so we can audit whether our rewrites caught everything

◆ makeLocalDerivationGoal() [1/2]

std::unique_ptr< LocalDerivationGoal > nix::LocalDerivationGoal::makeLocalDerivationGoal ( const StorePath & drvPath,
const OutputsSpec & wantedOutputs,
Worker & worker,
bool isDependency,
BuildMode buildMode )
static

Create a LocalDerivationGoal without an on-disk .drv file, possibly a platform-specific subclass

◆ makeLocalDerivationGoal() [2/2]

std::unique_ptr< LocalDerivationGoal > nix::LocalDerivationGoal::makeLocalDerivationGoal ( DrvHasRoot drvRoot,
const StorePath & drvPath,
const BasicDerivation & drv,
const OutputsSpec & wantedOutputs,
Worker & worker,
bool isDependency,
BuildMode buildMode )
static

Create a LocalDerivationGoal for an on-disk .drv file, possibly a platform-specific subclass

◆ needsHashRewrite()

bool nix::LocalDerivationGoal::needsHashRewrite ( )
virtual

Whether we need to perform hash rewriting if there are valid output paths.

◆ prepareSandbox()

virtual void nix::LocalDerivationGoal::prepareSandbox ( )
inlineprotectedvirtual

Setup dependencies outside the sandbox. Called in the parent nix process.

◆ registerOutputs()

kj::Promise< Result< SingleDrvOutputs > > nix::LocalDerivationGoal::registerOutputs ( )
overridevirtual

Check that the derivation outputs all exist and register them as valid.

Reimplemented from nix::DerivationGoal.

◆ respectsTimeouts()

virtual bool nix::LocalDerivationGoal::respectsTimeouts ( )
inlineoverrideprotectedvirtual

Reimplemented from nix::DerivationGoal.

◆ runChild()

void nix::LocalDerivationGoal::runChild ( )

Run the builder's process.

◆ setupSyscallFilter()

virtual void nix::LocalDerivationGoal::setupSyscallFilter ( )
inlineprotectedvirtual

Set up the system call filtering required for the sandbox. This currently only has an effect on Linux.

◆ signRealisation()

void nix::LocalDerivationGoal::signRealisation ( Realisation & )
overridevirtual

Sign the newly built realisation if the store allows it

Reimplemented from nix::DerivationGoal.

◆ startBuilder()

kj::Promise< Result< void > > nix::LocalDerivationGoal::startBuilder ( )

Start building a derivation.

◆ startChild()

Pid nix::LocalDerivationGoal::startChild ( std::function< void()> openSlave)
protectedvirtual

Create a new process that runs openSlave and runChild On some platforms this process is created with sandboxing flags.

◆ supportsUidRange()

virtual bool nix::LocalDerivationGoal::supportsUidRange ( )
inlineprotectedvirtual

Whether derivation can be built on current platform with uid-range feature

◆ tryLocalBuild()

kj::Promise< Result< Goal::WorkResult > > nix::LocalDerivationGoal::tryLocalBuild ( )
overridevirtualnoexcept

The additional states.

Reimplemented from nix::DerivationGoal.

◆ writeStructuredAttrs()

kj::Promise< Result< void > > nix::LocalDerivationGoal::writeStructuredAttrs ( )

Write a JSON file containing the derivation attributes.

Member Data Documentation

◆ addedDrvOutputs

std::set<DrvOutput> nix::LocalDerivationGoal::addedDrvOutputs

Realisations that were added via recursive Nix calls.

◆ addedPaths

StorePathSet nix::LocalDerivationGoal::addedPaths

Paths that were added via recursive Nix calls.

◆ autoDelChroot

std::shared_ptr<AutoDelete> nix::LocalDerivationGoal::autoDelChroot

RAII object to delete the chroot directory.

◆ builderOutPTY

AutoCloseFD nix::LocalDerivationGoal::builderOutPTY

Master side of the pseudoterminal used for the builder's standard output/error.

◆ buildUser

std::unique_ptr<UserLock> nix::LocalDerivationGoal::buildUser

User selected for running the builder.

◆ cgroup

std::optional<Path> nix::LocalDerivationGoal::cgroup

The cgroup of the builder, if any.

◆ daemonSocket

AutoCloseFD nix::LocalDerivationGoal::daemonSocket

The recursive Nix daemon socket.

◆ daemonThread

std::thread nix::LocalDerivationGoal::daemonThread

The daemon main thread.

◆ daemonWorkerThreads

std::vector<std::thread> nix::LocalDerivationGoal::daemonWorkerThreads

The daemon worker threads.

◆ inputRewrites

StringMap nix::LocalDerivationGoal::inputRewrites

Hash rewriting.

◆ pid

Pid nix::LocalDerivationGoal::pid

The process ID of the builder.

◆ prevInfos

std::map<Path, ValidPathInfo> nix::LocalDerivationGoal::prevInfos

Path registration info from the previous round, if we're building multiple times. Since this contains the hash, it allows us to compare whether two rounds produced the same result.

◆ privateNetwork

bool nix::LocalDerivationGoal::privateNetwork = false

Whether to run the build in a private network namespace.

◆ sandboxMountNamespace

AutoCloseFD nix::LocalDerivationGoal::sandboxMountNamespace

The mount namespace and user namespace of the builder, used to add additional paths to the sandbox as a result of recursive Nix calls.

◆ scratchOutputs

OutputPathMap nix::LocalDerivationGoal::scratchOutputs

The outputs paths used during the build.

  • Input-addressed derivations or fixed content-addressed outputs are sometimes built when some of their outputs already exist, and can not be hidden via sandboxing. We use temporary locations instead and rewrite after the build. Otherwise the regular predetermined paths are put here.
  • Floating content-addressed derivations do not know their final build output paths until the outputs are hashed, so random locations are used, and then renamed. The randomness helps guard against hidden self-references.

◆ tmpDir

Path nix::LocalDerivationGoal::tmpDir

The temporary directory.

◆ tmpDirInSandbox

Path nix::LocalDerivationGoal::tmpDirInSandbox

The path of the temporary directory in the sandbox.

◆ useChroot

bool nix::LocalDerivationGoal::useChroot = false

Whether we're currently doing a chroot build.

◆ userNamespaceSync

Pipe nix::LocalDerivationGoal::userNamespaceSync

Pipe for synchronising updates to the builder namespaces.

◆ usingUserNamespace

bool nix::LocalDerivationGoal::usingUserNamespace = true

On Linux, whether we're doing the build in its own user namespace.


The documentation for this struct was generated from the following files: