From 7cdda9c5fa2abeba02803a7ff9ba7145693b8ff9 Mon Sep 17 00:00:00 2001 From: piegames Date: Thu, 30 Apr 2026 21:32:53 +0200 Subject: [PATCH] flakes: checkOverlay: Don't check the second argument It's software archaeology time. - In 2019 (Nix 2.4), Eelco added `checkOverlays`, which strictly checked that the overlay must be a function of two arguments, one called `final` and the other `prev`. (dc3f52a1447df8523f44c89e25e48e8b7f5341a0, gh#3573) - In 2024, NofairKing opened an issue about checking the exact name being a silly idea (gh#10516). Instead of trying to make the check more sensible, the first fix attempt simply expanded the check to allow `previous` instead of `prev` (the author's preferred name for the attribute, supposedly; gh#10553). After some discussion, instead a PR got merged which simply removed the `prev` check altogether, while leaving the `final` argument check intact for some reason (ad65a50a94a97bf1f1a1902f43542d28a2e8206b, gh#10572). - In 2025, over at Lix and oblivious to the latest change over at CppNix, I came across this stupid check while trying to improve the abstractions of the AST in Nixexpr. I spent (wasted, retrospect) considerable amounts of time removing the exact name checks while also improving the check overall (making it check for more than two arguments, and also generally improved error message). (0928d4d87ac9c6bc28b9b850c3cb590174a4674c, Id4244171123dd8a228be71ce9f04d8e9f647c111) - Fast forward to 2026, where I run into this becursed piece of code once again, and once again during some Lixexpr cleanups. Now that I have seen how carlessly the issue was handled at CppNix, I can't be arsed to give a flying fuck anymore. Out the code goes. Bye. With this commit, all casts on `Expr` subclasses outside of libexpr itself have been removed. No more violation of abstraction boundaries. Good riddance. Change-Id: I939968bb01d461764cfa0f4ea7152b4fcf1acf93 --- lix/nix/flake.cc | 5 ----- tests/functional2/flakes/test_check.py | 28 -------------------------- 2 files changed, 33 deletions(-) diff --git a/lix/nix/flake.cc b/lix/nix/flake.cc index 52db3e4b1..ea8550a9b 100644 --- a/lix/nix/flake.cc +++ b/lix/nix/flake.cc @@ -469,11 +469,6 @@ struct CmdFlakeCheck : FlakeCommand if (!v.isLambda()) { throw Error("overlay is not a function, but %s instead", showType(v)); } - auto body = v.lambda().fun->body->try_cast(); - if (!body) - throw Error("overlay is not a function with two arguments, but only takes one"); - if (body->body->try_cast()) - 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/functional2/flakes/test_check.py b/tests/functional2/flakes/test_check.py index 756518720..f5359165e 100644 --- a/tests/functional2/flakes/test_check.py +++ b/tests/functional2/flakes/test_check.py @@ -34,34 +34,6 @@ def test_check_overlay_args_good(nix: Nix, files: Path): nix.nix(["flake", "check", str(files)]).run().ok() -@with_files( - make_flake("""{ - outputs = { self }: { - overlay = one: two: three: {}; - }; - }""") -) -def test_check_overlay_too_many_args(nix: Nix, files: Path): - assert ( - "error: overlay is not a function with two arguments, but takes more than two" - in nix.nix(["flake", "check", str(files)]).run().expect(1).stderr_s - ) - - -@with_files( - make_flake("""{ - outputs = { self }: { - overlay = one: {}; - }; - }""") -) -def test_check_overlay_not_enough_args(nix: Nix, files: Path): - assert ( - "error: overlay is not a function with two arguments, but only takes one" - in nix.nix(["flake", "check", str(files)]).run().expect(1).stderr_s - ) - - @with_files( make_flake("""{ outputs = { self, ... }: {