flakes: Make checkOverlay less strict

I'm sorry but checking the name of the function arguments to be "final"
and "prev" is just absurd. That's like worst of
type-checking-meets-static-analysis. And the error message of the second
`throw` was not even good, as it mixed all three failure cases together.

Change-Id: Id4244171123dd8a228be71ce9f04d8e9f647c111
This commit is contained in:
piegames
2025-02-24 12:54:48 +01:00
parent 43b0902390
commit 0928d4d87a
2 changed files with 26 additions and 15 deletions
+4 -15
View File
@@ -391,14 +391,6 @@ struct CmdFlakeCheck : FlakeCommand
return evaluator->positions[p];
};
auto argHasName = [&] (Symbol arg, std::string_view expected) {
std::string_view name = evaluator->symbols[arg];
return
name == expected
|| name == "_"
|| (name.starts_with("_") && name.substr(1) == expected);
};
auto checkSystemName = [&](const std::string & system, const PosIdx pos) {
// FIXME: what's the format of "system"?
if (system.find('-') == std::string::npos)
@@ -464,14 +456,11 @@ struct CmdFlakeCheck : FlakeCommand
if (!v.isLambda()) {
throw Error("overlay is not a function, but %s instead", showType(v));
}
if (v.lambda.fun->hasFormals()
|| !argHasName(v.lambda.fun->arg, "final"))
throw Error("overlay does not take an argument named 'final'");
auto body = dynamic_cast<ExprLambda *>(v.lambda.fun->body.get());
if (!body
|| body->hasFormals()
|| !argHasName(body->arg, "prev"))
throw Error("overlay does not take an argument named 'prev'");
if (!body)
throw Error("overlay is not a function with two arguments, but only takes one");
if (dynamic_cast<ExprLambda *>(body->body.get()))
throw Error("overlay is not a function with two arguments, but takes more than two");
// FIXME: if we have a 'nixpkgs' input, use it to
// evaluate the overlay.
} catch (Error & e) {
+22
View File
@@ -23,6 +23,28 @@ cat > $flakeDir/flake.nix <<EOF
}
EOF
(nix flake check $flakeDir)
cat > $flakeDir/flake.nix <<EOF
{
outputs = { self }: {
overlay = one: two: three: {
};
};
}
EOF
(! nix flake check $flakeDir)
cat > $flakeDir/flake.nix <<EOF
{
outputs = { self }: {
overlay = one: {
};
};
}
EOF
(! nix flake check $flakeDir)
cat > $flakeDir/flake.nix <<EOF