flake-utils icon indicating copy to clipboard operation
flake-utils copied to clipboard

flattenTree: ignore attributes that throw errors

Open Pacman99 opened this issue 4 years ago • 5 comments

Improve flattenTree's safety. If attributes throw an error, they should just be ignored, since the goal is to filter out derivations.

Pacman99 avatar May 17 '21 17:05 Pacman99

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.

zimbatm avatar May 18 '21 16:05 zimbatm

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.

Pacman99 avatar May 18 '21 17:05 Pacman99

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?

zimbatm avatar May 19 '21 08:05 zimbatm

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 :)

Pacman99 avatar May 19 '21 15:05 Pacman99

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.

blaggacao avatar May 27 '21 17:05 blaggacao