Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Worker Class Reference

#include <worker.hh>

Inheritance diagram for nix::Worker:
nix::Builder

Public Member Functions

 Worker (Store &store, Store &evalStore)
std::shared_ptr< DerivationTrampolineGoal > makeDerivationTrampolineGoal (const StorePath &drvPath, const OutputsSpec &wantedOutputs, const Derivation &drv, BuildMode buildMode)
std::shared_ptr< DerivationGoal > makeDerivationGoal (const StorePath &drvPath, ref< const Derivation > drv, const OutputName &wantedOutput, BuildMode buildMode, bool storeDerivation)
std::shared_ptr< DerivationResolutionGoal > makeDerivationResolutionGoal (const StorePath &drvPath, ref< const Derivation > drv, BuildMode buildMode)
std::shared_ptr< DerivationBuildingGoal > makeDerivationBuildingGoal (const StorePath &drvPath, ref< const BasicDerivation > drv, BuildMode buildMode)
std::shared_ptr< PathSubstitutionGoal > makePathSubstitutionGoal (const StorePath &storePath, RepairFlag repair=NoRepair, std::optional< ContentAddress > ca=std::nullopt)
std::shared_ptr< DrvOutputSubstitutionGoal > makeDrvOutputSubstitutionGoal (const DrvOutput &id)
GoalPtr makeGoal (const DerivedPath &req, BuildMode buildMode=bmNormal)
void removeGoal (GoalPtr goal)
void wakeUp (GoalPtr goal)
std::weak_ptr< Waker > getCrossThreadWaker ()
size_t getNrLocalBuilds ()
size_t getNrSubstitutions ()
void childStarted (GoalPtr goal, const std::set< MuxablePipePollState::CommChannel > &channels, bool inBuildSlot, bool respectTimeouts)
void childTerminated (Goal *goal)
void childTerminated (Goal *goal, JobCategory jobCategory)
void waitForBuildSlot (GoalPtr goal)
void waitForAWhile (GoalPtr goal)
void waitForCompletion (GoalPtr goal)
void run (const Goals &topGoals)
void waitForInput ()
bool pathContentsGood (const StorePath &path)
void markContentsGood (const StorePath &path)
void updateProgress ()
void buildPaths (const std::vector< DerivedPath > &reqs, BuildMode buildMode) override
std::vector< KeyedBuildResult > buildPathsWithResults (const std::vector< DerivedPath > &reqs, BuildMode buildMode) override
BuildResult buildDerivation (const StorePath &drvPath, const BasicDerivation &drv, BuildMode buildMode) override
void ensurePath (const StorePath &path) override
void repairPath (const StorePath &path) override
Public Member Functions inherited from nix::Builder
virtual void anchor ()

Public Attributes

const Activity act
const Activity actDerivations
const Activity actSubstitutions
ExitStatusFlags exitStatusFlags
Store & store
Store & evalStore
const WorkerSettings & settings
fun< std::list< ref< Store > >()> getSubstituters
std::unique_ptr< HookInstance > hook
uint64_t expectedBuilds = 0
uint64_t doneBuilds = 0
uint64_t failedBuilds = 0
uint64_t runningBuilds = 0
uint64_t expectedSubstitutions = 0
uint64_t doneSubstitutions = 0
uint64_t failedSubstitutions = 0
uint64_t runningSubstitutions = 0
uint64_t expectedDownloadSize = 0
uint64_t doneDownloadSize = 0
uint64_t expectedNarSize = 0
uint64_t doneNarSize = 0
bool tryBuildHook = true

Detailed Description

Coordinates one or more realisations and their interdependencies.

Member Function Documentation

◆ buildDerivation()

BuildResult nix::Worker::buildDerivation ( const StorePath & drvPath,
const BasicDerivation & drv,
BuildMode buildMode )
overridevirtual

Build a single non-materialized derivation (i.e. not from an on-disk .drv file).

Parameters
drvPathThis is used to deduplicate worker goals so it is imperative that is correct. That said, it doesn't literally need to be store path that would be calculated from writing this derivation to the store: it is OK if it instead is that of a Derivation which would resolve to this (by taking the outputs of it's input derivations and adding them as input sources) such that the build time referenceable-paths are the same.

In the input-addressed case, we usually do use an "original" unresolved derivations's path, as that is what will be used in the buildPaths case. Also, the input-addressed output paths are verified only by that contents of that specific unresolved derivation, so it is nice to keep that information around so if the original derivation is ever obtained later, it can be verified whether the trusted user in fact used the proper output path.

In the content-addressed case, we want to always use the resolved drv path calculated from the provided derivation. This serves two purposes:

  • It keeps the operation trustless, by ruling out a maliciously invalid drv path corresponding to a non-resolution-equivalent derivation.
  • For the floating case in particular, it ensures that the derivation to output mapping respects the resolution equivalence relation, so one cannot choose different resolution-equivalent derivations to subvert dependency coherence (i.e. the property that one doesn't end up with multiple different versions of dependencies without explicitly choosing to allow it).

Implements nix::Builder.

◆ buildPaths()

void nix::Worker::buildPaths ( const std::vector< DerivedPath > & reqs,
BuildMode buildMode )
overridevirtual

For each path, if it's a derivation, build it. Building a derivation means ensuring that the output paths are valid. If they are already valid, this is a no-op. Otherwise, validity can be reached in two ways. First, if the output paths is substitutable, then build the path that way. Second, the output paths can be created by running the builder, after recursively building any sub-derivations. For inputs that are not derivations, substitute them.

Implements nix::Builder.

◆ buildPathsWithResults()

std::vector< KeyedBuildResult > nix::Worker::buildPathsWithResults ( const std::vector< DerivedPath > & reqs,
BuildMode buildMode )
overridevirtual

Like buildPaths(), but return a vector of BuildResult BuildResults corresponding to each element in paths. Note that in case of a build/substitution error, this function won't throw an exception, but return a BuildResult containing an error message.

Implements nix::Builder.

◆ childStarted()

void nix::Worker::childStarted ( GoalPtr goal,
const std::set< MuxablePipePollState::CommChannel > & channels,
bool inBuildSlot,
bool respectTimeouts )

Registers a running child process. inBuildSlot means that the process counts towards the jobs limit.

◆ childTerminated() [1/2]

void nix::Worker::childTerminated ( Goal * goal)

Unregisters a running child process.

This overload requires goal to point to a fully constructed, valid goal object, as it calls goal->jobCategory().

◆ childTerminated() [2/2]

void nix::Worker::childTerminated ( Goal * goal,
JobCategory jobCategory )

Unregisters a running child process, like the other overload.

This overload only uses goal as a pointer for comparison with weak goal references, so it is safe to call from destructors where the goal object may be partially destroyed.

◆ ensurePath()

void nix::Worker::ensurePath ( const StorePath & path)
overridevirtual

Ensure that a path is valid. If it is not currently valid, it may be made valid by running a substitute (if defined for the path).

The path is registered as a temporary GC root first, whether or not it was already valid, so that a concurrent garbage collection cannot delete it while the caller is still using it.

Implements nix::Builder.

◆ getCrossThreadWaker()

std::weak_ptr< Worker::Waker > nix::Worker::getCrossThreadWaker ( )

Get a weak reference to the goal waker. It can be used to safely enqueue Goals for wakeup from other threads.

◆ getNrLocalBuilds()

size_t nix::Worker::getNrLocalBuilds ( )

Return the number of local build processes currently running (but not remote builds via the build hook).

◆ getNrSubstitutions()

size_t nix::Worker::getNrSubstitutions ( )

Return the number of substitution processes currently running.

◆ makeDerivationBuildingGoal()

std::shared_ptr< DerivationBuildingGoal > nix::Worker::makeDerivationBuildingGoal ( const StorePath & drvPath,
ref< const BasicDerivation > drv,
BuildMode buildMode )

◆ makeDerivationResolutionGoal()

std::shared_ptr< DerivationResolutionGoal > nix::Worker::makeDerivationResolutionGoal ( const StorePath & drvPath,
ref< const Derivation > drv,
BuildMode buildMode )

◆ makeGoal()

GoalPtr nix::Worker::makeGoal ( const DerivedPath & req,
BuildMode buildMode = bmNormal )

Make a goal corresponding to the DerivedPath.

It will be a DerivationGoal for a DerivedPath::Built or a PathSubstitutionGoal for a DerivedPath::Opaque.

◆ makePathSubstitutionGoal()

std::shared_ptr< PathSubstitutionGoal > nix::Worker::makePathSubstitutionGoal ( const StorePath & storePath,
RepairFlag repair = NoRepair,
std::optional< ContentAddress > ca = std::nullopt )

◆ pathContentsGood()

bool nix::Worker::pathContentsGood ( const StorePath & path)

Check whether the given valid path exists and has the right contents.

◆ removeGoal()

void nix::Worker::removeGoal ( GoalPtr goal)

Remove a dead goal.

◆ repairPath()

void nix::Worker::repairPath ( const StorePath & path)
overridevirtual

Repair the contents of the given path by redownloading it using a substituter (if available).

Implements nix::Builder.

◆ run()

void nix::Worker::run ( const Goals & topGoals)

Loop until the specified top-level goals have finished.

◆ waitForAWhile()

void nix::Worker::waitForAWhile ( GoalPtr goal)

Wait for a few seconds and then retry this goal. Used when waiting for a lock held by another process. This kind of polling is inefficient, but POSIX doesn't really provide a way to wait for multiple locks in the main select() loop.

◆ waitForBuildSlot()

void nix::Worker::waitForBuildSlot ( GoalPtr goal)

Put goal to sleep until a build slot becomes available (which might be right away).

◆ waitForCompletion()

void nix::Worker::waitForCompletion ( GoalPtr goal)

Wait until explicitly resumed by Waker::enqueue.

◆ waitForInput()

void nix::Worker::waitForInput ( )

Wait for input to become available.

◆ wakeUp()

void nix::Worker::wakeUp ( GoalPtr goal)

Wake up a goal (i.e., there is something for it to do).

Member Data Documentation

◆ exitStatusFlags

ExitStatusFlags nix::Worker::exitStatusFlags

Tracks different types of build failures for exit status computation.

◆ getSubstituters

fun<std::list<ref<Store> >()> nix::Worker::getSubstituters

Function to get the substituters to use for path substitution.

Defaults to getDefaultSubstituters. This allows tests to inject custom substituters.

◆ tryBuildHook

bool nix::Worker::tryBuildHook = true

Whether to ask the build hook if it can build a derivation. If it answers with "decline-permanently", we don't try again.


The documentation for this class was generated from the following files:
  • libstore/include/nix/store/build/worker.hh
  • libstore/build/entry-points.cc
  • libstore/build/worker.cc