Merge pull request #6663 from Ma27/follows-invalid-input
flakes: throw an error if `follows`-declaration for an input is invalid
This commit is contained in:
commit
2dbd5ed0b4
|
@ -352,6 +352,39 @@ LockedFlake lockFlake(
|
||||||
|
|
||||||
std::vector<FlakeRef> parents;
|
std::vector<FlakeRef> parents;
|
||||||
|
|
||||||
|
std::function<void(
|
||||||
|
const InputPath & inputPathPrefix,
|
||||||
|
const FlakeInputs & flakeInputs
|
||||||
|
)>
|
||||||
|
checkFollowsDeclarations;
|
||||||
|
|
||||||
|
checkFollowsDeclarations = [&](
|
||||||
|
const InputPath & inputPathPrefix,
|
||||||
|
const FlakeInputs & flakeInputs
|
||||||
|
) {
|
||||||
|
for (auto [inputPath, inputOverride] : overrides) {
|
||||||
|
auto inputPath2(inputPath);
|
||||||
|
auto follow = inputPath2.back();
|
||||||
|
inputPath2.pop_back();
|
||||||
|
if (inputPath2 == inputPathPrefix
|
||||||
|
&& flakeInputs.find(follow) == flakeInputs.end()
|
||||||
|
) {
|
||||||
|
std::string root;
|
||||||
|
for (auto & element : inputPath2) {
|
||||||
|
root.append(element);
|
||||||
|
if (element != inputPath2.back()) {
|
||||||
|
root.append(".inputs.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
warn(
|
||||||
|
"%s has a `follows'-declaration for a non-existant input %s!",
|
||||||
|
root,
|
||||||
|
follow
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
std::function<void(
|
std::function<void(
|
||||||
const FlakeInputs & flakeInputs,
|
const FlakeInputs & flakeInputs,
|
||||||
std::shared_ptr<Node> node,
|
std::shared_ptr<Node> node,
|
||||||
|
@ -373,6 +406,8 @@ LockedFlake lockFlake(
|
||||||
{
|
{
|
||||||
debug("computing lock file node '%s'", printInputPath(inputPathPrefix));
|
debug("computing lock file node '%s'", printInputPath(inputPathPrefix));
|
||||||
|
|
||||||
|
checkFollowsDeclarations(inputPathPrefix, flakeInputs);
|
||||||
|
|
||||||
/* 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) {
|
for (auto & [id, input] : flakeInputs) {
|
||||||
|
|
|
@ -801,6 +801,8 @@ nix flake metadata $flakeFollowsA
|
||||||
|
|
||||||
nix flake update $flakeFollowsA
|
nix flake update $flakeFollowsA
|
||||||
|
|
||||||
|
nix flake lock $flakeFollowsA
|
||||||
|
|
||||||
oldLock="$(cat "$flakeFollowsA/flake.lock")"
|
oldLock="$(cat "$flakeFollowsA/flake.lock")"
|
||||||
|
|
||||||
# Ensure that locking twice doesn't change anything
|
# Ensure that locking twice doesn't change anything
|
||||||
|
@ -823,7 +825,6 @@ cat > $flakeFollowsA/flake.nix <<EOF
|
||||||
inputs = {
|
inputs = {
|
||||||
B = {
|
B = {
|
||||||
url = "path:./flakeB";
|
url = "path:./flakeB";
|
||||||
inputs.nonFlake.follows = "D";
|
|
||||||
};
|
};
|
||||||
D.url = "path:./flakeD";
|
D.url = "path:./flakeD";
|
||||||
};
|
};
|
||||||
|
@ -859,3 +860,21 @@ nix store delete $(nix store add-path $badFlakeDir)
|
||||||
|
|
||||||
[[ $(nix path-info $(nix store add-path $flake1Dir)) =~ flake1 ]]
|
[[ $(nix path-info $(nix store add-path $flake1Dir)) =~ flake1 ]]
|
||||||
[[ $(nix path-info path:$(nix store add-path $flake1Dir)) =~ simple ]]
|
[[ $(nix path-info path:$(nix store add-path $flake1Dir)) =~ simple ]]
|
||||||
|
|
||||||
|
# Non-existant follows causes an error
|
||||||
|
|
||||||
|
cat >$flakeFollowsA/flake.nix <<EOF
|
||||||
|
{
|
||||||
|
description = "Flake A";
|
||||||
|
inputs.B = {
|
||||||
|
url = "path:./flakeB";
|
||||||
|
inputs.invalid.follows = "D";
|
||||||
|
};
|
||||||
|
inputs.D.url = "path:./flakeD";
|
||||||
|
outputs = { ... }: {};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
git -C $flakeFollowsA add flake.nix
|
||||||
|
|
||||||
|
nix flake lock $flakeFollowsA 2>&1 | grep "warning: B has a \`follows'-declaration for a non-existant input invalid!"
|
||||||
|
|
Loading…
Reference in a new issue