Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions src/libstore/build/derivation-resolution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,7 @@ Goal::Co DerivationResolutionGoal::resolveDerivation()
{
auto & fullDrv = *drv;

auto drvType = fullDrv.type();
bool resolveDrv =
std::visit(
overloaded{
[&](const DerivationType::InputAddressed & ia) {
/* must resolve if deferred. */
return ia.deferred;
},
[&](const DerivationType::ContentAddressed & ca) {
return !fullDrv.inputDrvs.map.empty()
&& (ca.fixed
/* Can optionally resolve if fixed, which is good
for avoiding unnecessary rebuilds. */
? experimentalFeatureSettings.isEnabled(Xp::CaDerivations)
/* Must resolve if floating and there are any inputs
drvs. */
: true);
},
[&](const DerivationType::Impure &) { return true; }},
drvType.raw)
/* no inputs are outputs of dynamic derivations */
|| std::ranges::any_of(fullDrv.inputDrvs.map.begin(), fullDrv.inputDrvs.map.end(), [](auto & pair) {
return !pair.second.childMap.empty();
});

if (resolveDrv && !fullDrv.inputDrvs.map.empty()) {
if (fullDrv.shouldResolve()) {
experimentalFeatureSettings.require(Xp::CaDerivations);

/* We are be able to resolve this derivation based on the
Expand Down
33 changes: 33 additions & 0 deletions src/libstore/derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,39 @@ static void rewriteDerivation(Store & store, BasicDerivation & drv, const String
}
}

bool Derivation::shouldResolve() const
{
/* No input drvs means nothing to resolve. */
if (inputDrvs.map.empty())
return false;

auto drvType = type();

bool typeNeedsResolve = std::visit(
overloaded{
[&](const DerivationType::InputAddressed & ia) {
/* Must resolve if deferred. */
return ia.deferred;
},
[&](const DerivationType::ContentAddressed & ca) {
return ca.fixed
/* Can optionally resolve if fixed, which is good
for avoiding unnecessary rebuilds. */
? experimentalFeatureSettings.isEnabled(Xp::CaDerivations)
/* Must resolve if floating. */
: true;
},
[&](const DerivationType::Impure &) { return true; },
},
drvType.raw);

/* Also need to resolve if any inputs are outputs of dynamic derivations. */
bool hasDynamicInputs = std::ranges::any_of(
inputDrvs.map.begin(), inputDrvs.map.end(), [](auto & pair) { return !pair.second.childMap.empty(); });

return typeNeedsResolve || hasDynamicInputs;
}

std::optional<BasicDerivation> Derivation::tryResolve(Store & store, Store * evalStore) const
{
return tryResolve(
Expand Down
13 changes: 13 additions & 0 deletions src/libstore/include/nix/store/derivations.hh
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,19 @@ struct Derivation : BasicDerivation
bool maskOutputs,
DerivedPathMap<StringSet>::ChildNode::Map * actualInputs = nullptr) const;

/**
* Determine whether this derivation should be resolved before building.
*
* Resolution is needed when:
* - Input-addressed derivations are deferred (depend on CA derivations)
* - Content-addressed derivations have input drvs and are either:
* - Floating (non-fixed), which must always be resolved
* - Fixed, which can optionally be resolved when ca-derivations is enabled
* - Impure derivations always need resolution
* - Any input derivations have outputs from dynamic derivations
*/
bool shouldResolve() const;

/**
* Return the underlying basic derivation but with these changes:
*
Expand Down
2 changes: 1 addition & 1 deletion src/nix/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ static void main_nix_build(int argc, char ** argv)
shell = store->printStorePath(shellDrvOutputs.at("out").value()) + "/bin/bash";
}

if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
if (drv.shouldResolve()) {
auto resolvedDrv = drv.tryResolve(*store);
Comment on lines -534 to 535
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this still require the XP feature? Or would that check be redundant and we'd fail earlier anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be redundant, yeah. Though I wouldn't mind putting more redundant checks in the body of the function.

assert(resolvedDrv && "Successfully resolved the derivation");
drv = *resolvedDrv;
Expand Down
Loading