Files
lix/tests/functional2/flakes/test_check.py
T
piegames 7cdda9c5fa 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`. (dc3f52a144,
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).
(0928d4d87a,
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
2026-05-06 17:22:19 +02:00

137 lines
3.6 KiB
Python

from testlib.fixtures.nix import Nix
from testlib.fixtures.file_helper import FileDeclaration, with_files
from testlib.utils import File
from pathlib import Path
import pytest
@pytest.fixture(autouse=True)
def common_init(nix: Nix):
nix.settings.add_xp_feature("nix-command", "flakes")
def make_flake(text: str) -> FileDeclaration:
return {"flake.nix": File(text)}
@pytest.mark.parametrize(
"files",
[
make_flake("""{
outputs = { self }: {
overlay = final: prev: {};
};
}"""),
make_flake("""{
outputs = { self }: {
overlay = finall: prev: {};
};
}"""),
],
indirect=True,
)
def test_check_overlay_args_good(nix: Nix, files: Path):
nix.nix(["flake", "check", str(files)]).run().ok()
@with_files(
make_flake("""{
outputs = { self, ... }: {
overlays.x86_64-linux.foo = final: prev: {};
};
}""")
)
def test_check_overlay_not_a_function(nix: Nix, files: Path):
assert (
"error: overlay is not a function, but a set instead"
in nix.nix(["flake", "check", str(files)]).run().expect(1).stderr_s
)
@pytest.mark.parametrize(
"files",
[
make_flake("""{
outputs = { self }: {
nixosModules.foo = {
a.b.c = 123;
foo = true;
};
};
}"""),
make_flake("""{
outputs = { self }: {
nixosModule = { config, pkgs, ... }: {
a.b.c = 123;
};
};
}"""),
],
indirect=True,
)
def test_check_nixos_modules_good(nix: Nix, files: Path):
nix.nix(["flake", "check", str(files)]).run().ok()
@with_files(
make_flake("""{
outputs = { self }: {
nixosModules.foo = assert false; {
a.b.c = 123;
foo = true;
};
};
}""")
)
def test_check_nixos_modules_eval_fail(nix: Nix, files: Path):
assert "assertion failed" in nix.nix(["flake", "check", str(files)]).run().expect(1).stderr_s
@with_files(
make_flake("""{
outputs = { self }: {
packages.system-1.default = "foo";
packages.system-2.default = "bar";
};
}""")
)
class TestMultipleSystems:
def test_check(self, nix: Nix, files: Path):
nix.nix(["flake", "check", str(files)]).run().ok()
def test_check_with_eval_system(self, nix: Nix, files: Path):
"""
--eval-system should be considered for which the local system is for flake
purposes, and thus it should fail checking that attr
"""
assert (
"'packages.system-1.default' is not a derivation"
in nix.nix(["flake", "check", "--eval-system", "system-1", str(files)])
.run()
.expect(1)
.stderr_s
)
def test_check_with_system(self, nix: Nix, files: Path):
"""
--system should be considered for which the local system is for flake
purposes, and thus it should fail checking that attr
"""
assert (
"'packages.system-1.default' is not a derivation"
in nix.nix(["flake", "check", "--system", "system-1", str(files)])
.run()
.expect(1)
.stderr_s
)
def test_check_all_systems(self, nix: Nix, files: Path):
result = (
nix.nix(["flake", "check", "--all-systems", "--keep-going", str(files)])
.run()
.expect(1)
.stderr_s
)
assert "'packages.system-1.default' is not a derivation" in result
assert "'packages.system-2.default' is not a derivation" in result