flattenTree: ignore attributes that throw errors
Improve flattenTree's safety. If attributes throw an error, they should just be ignored, since the goal is to filter out derivations.
This might filter too many packages. Let's say you modify a package and introduce a Nix error by mistake. The CI might still be building successfully while ignoring the failed package.
I don't think that should be a concern. derivations require a deeper evaluations to check if there are errors in them.
This should pretty much only be able to check if here is a literal throw on the other side of the attribute.
If its a syntax error, that would fail no matter what. And if the derivation is broken, it won't know - so won't be ignored.
I might be missing something here though.
Let's see what my imagination can come up with :)
{ stdenv, lib, openssl, zlib }:
stdenv.mkDerivation {
buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin zlib;
}
That package would get filtered out isn't it?
Great example! I just tried it out, I think it works. Here is my repl:
nix-repl> p = pkgs.callPackage ./test.nix { }
nix-repl> builtins.tryEval ((builtins.typeOf p) == "set")
{ success = true; value = true; }
where test.nix was the package you sent.
I think the error of missing attributes or any general package error only gets triggered when you access specific attributes in the package or actually evaluate the derivation. So a shallow evaluation of it, wouldn't catch such things.
But also I think we came up with a better solution in flake-utils-plus to avoid running into throw's in the first place. So Its ok to close this. This was totally worth it to learn about tryEval :)
I'd also want to add that https://github.com/numtide/flake-utils/blob/master/filterPackages.nix was intended for providing any kind of filtering services to users. I can't remember exactly why I didn't touch flattenTree filtering, I think it was because flatten tree does just the ordinary thing expected from any nix tools to recursively collect derivations.