From 0928d4d87ac9c6bc28b9b850c3cb590174a4674c Mon Sep 17 00:00:00 2001 From: piegames Date: Mon, 3 Feb 2025 12:49:55 +0100 Subject: [PATCH] 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 --- lix/nix/flake.cc | 19 ++++--------------- tests/functional/flakes/check.sh | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lix/nix/flake.cc b/lix/nix/flake.cc index 599e258cb..f8419f910 100644 --- a/lix/nix/flake.cc +++ b/lix/nix/flake.cc @@ -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(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(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) { diff --git a/tests/functional/flakes/check.sh b/tests/functional/flakes/check.sh index 0433e5335..fefaae9dd 100644 --- a/tests/functional/flakes/check.sh +++ b/tests/functional/flakes/check.sh @@ -23,6 +23,28 @@ cat > $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix < $flakeDir/flake.nix <