Make formatter not strict in all systems and try to...

... avoid broken attributes in cases where we can predict that
we don't have any.

This is far from ideal, but it's the best we can do.
If it becomes a shit show, flake authors can opt out.
This commit is contained in:
Robert Hensing 2025-05-27 00:33:49 +02:00
parent 14a4a8d4fe
commit 157c95de4d
2 changed files with 128 additions and 8 deletions

View file

@ -464,4 +464,68 @@ in
expected = "dogfood";
};
};
formatter = {
"test: conditional null throws helpful error" = {
expr =
let
result = mkFlake { inputs.self = { }; } {
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { system, ... }: {
formatter =
if system == "x86_64-linux" then
derivation { name = "fmt"; builder = "x"; system = system; }
else null;
};
};
in
result.formatter.aarch64-darwin;
expectedError.type = "ThrownError";
expectedError.msg = "could not determine statically(.|\n)*disabledModules(.|\n)*inputs\\.flake-parts\\.modules\\.formatter";
};
"test: empty when never defined" = {
expr =
let
result = mkFlake { inputs.self = { }; } {
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { ... }: { };
};
in
result.formatter == { };
expected = true;
};
"test: present for all systems" = {
expr =
let
result = mkFlake { inputs.self = { }; } {
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { system, ... }: {
formatter = derivation { name = "fmt"; builder = "x"; inherit system; };
};
};
in
result ? formatter && result.formatter ? x86_64-linux && result.formatter ? aarch64-darwin;
expected = true;
};
"test: lazy per-system" = {
expr =
let
result = mkFlake { inputs.self = { }; } {
systems = [ "x86_64-linux" "aarch64-darwin" ];
perSystem = { system, ... }: {
formatter =
if system == "x86_64-linux" then
derivation { name = "fmt"; builder = "x"; system = system; }
else
throw "should not evaluate aarch64-darwin formatter";
};
};
in
result.formatter.x86_64-linux.name;
expected = "fmt";
};
};
}