mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
Fix deep overrides
An override like inputs.foo.inputs.bar.inputs.nixpkgs.follows = "nixpkgs"; implicitly set `inputs.foo.inputs.bar` to `flake:bar`, which led to an unexpected error like error: cannot find flake 'flake:bar' in the flake registries We now no longer create a parent override (like for `foo.bar` in the example above) if it doesn't set an explicit ref or follows attribute. We only recursively apply its child overrides. Fixes https://github.com/NixOS/nix/issues/8325, https://github.com/DeterminateSystems/nix-src/issues/95, https://github.com/NixOS/nix/issues/12083, https://github.com/NixOS/nix/issues/5790.
This commit is contained in:
parent
df2d5f276a
commit
7c0ea143d8
1 changed files with 20 additions and 15 deletions
|
@ -101,7 +101,6 @@ static void parseFlakeInputAttr(
|
||||||
|
|
||||||
static FlakeInput parseFlakeInput(
|
static FlakeInput parseFlakeInput(
|
||||||
EvalState & state,
|
EvalState & state,
|
||||||
std::string_view inputName,
|
|
||||||
Value * value,
|
Value * value,
|
||||||
const PosIdx pos,
|
const PosIdx pos,
|
||||||
const InputAttrPath & lockRootAttrPath,
|
const InputAttrPath & lockRootAttrPath,
|
||||||
|
@ -171,9 +170,6 @@ static FlakeInput parseFlakeInput(
|
||||||
input.ref = parseFlakeRef(state.fetchSettings, *url, {}, true, input.isFlake, true);
|
input.ref = parseFlakeRef(state.fetchSettings, *url, {}, true, input.isFlake, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.follows && !input.ref)
|
|
||||||
input.ref = FlakeRef::fromAttrs(state.fetchSettings, {{"type", "indirect"}, {"id", std::string(inputName)}});
|
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +197,6 @@ static std::pair<std::map<FlakeId, FlakeInput>, fetchers::Attrs> parseFlakeInput
|
||||||
} else {
|
} else {
|
||||||
inputs.emplace(inputName,
|
inputs.emplace(inputName,
|
||||||
parseFlakeInput(state,
|
parseFlakeInput(state,
|
||||||
inputName,
|
|
||||||
inputAttr.value,
|
inputAttr.value,
|
||||||
inputAttr.pos,
|
inputAttr.pos,
|
||||||
lockRootAttrPath,
|
lockRootAttrPath,
|
||||||
|
@ -483,18 +478,27 @@ LockedFlake lockFlake(
|
||||||
|
|
||||||
/* Get the overrides (i.e. attributes of the form
|
/* Get the overrides (i.e. attributes of the form
|
||||||
'inputs.nixops.inputs.nixpkgs.url = ...'). */
|
'inputs.nixops.inputs.nixpkgs.url = ...'). */
|
||||||
for (auto & [id, input] : flakeInputs) {
|
std::function<void(const FlakeInput & input, const InputAttrPath & prefix)> addOverrides;
|
||||||
|
addOverrides = [&](const FlakeInput & input, const InputAttrPath & prefix)
|
||||||
|
{
|
||||||
for (auto & [idOverride, inputOverride] : input.overrides) {
|
for (auto & [idOverride, inputOverride] : input.overrides) {
|
||||||
auto inputAttrPath(inputAttrPathPrefix);
|
auto inputAttrPath(prefix);
|
||||||
inputAttrPath.push_back(id);
|
|
||||||
inputAttrPath.push_back(idOverride);
|
inputAttrPath.push_back(idOverride);
|
||||||
overrides.emplace(inputAttrPath,
|
if (inputOverride.ref || inputOverride.follows)
|
||||||
OverrideTarget {
|
overrides.emplace(inputAttrPath,
|
||||||
.input = inputOverride,
|
OverrideTarget {
|
||||||
.sourcePath = sourcePath,
|
.input = inputOverride,
|
||||||
.parentInputAttrPath = inputAttrPathPrefix
|
.sourcePath = sourcePath,
|
||||||
});
|
.parentInputAttrPath = inputAttrPathPrefix
|
||||||
|
});
|
||||||
|
addOverrides(inputOverride, inputAttrPath);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto & [id, input] : flakeInputs) {
|
||||||
|
auto inputAttrPath(inputAttrPathPrefix);
|
||||||
|
inputAttrPath.push_back(id);
|
||||||
|
addOverrides(input, inputAttrPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether this input has overrides for a
|
/* Check whether this input has overrides for a
|
||||||
|
@ -550,7 +554,8 @@ LockedFlake lockFlake(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(input.ref);
|
if (!input.ref)
|
||||||
|
input.ref = FlakeRef::fromAttrs(state.fetchSettings, {{"type", "indirect"}, {"id", std::string(id)}});
|
||||||
|
|
||||||
auto overriddenParentPath =
|
auto overriddenParentPath =
|
||||||
input.ref->input.isRelative()
|
input.ref->input.isRelative()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue