jtojnar / nixpkgs-hammering

Beat your package expressions into a shape
MIT License
245 stars 14 forks source link

tool: Handle eval errors #36

Closed jtojnar closed 3 years ago

jtojnar commented 3 years ago

Fixes: #35

Perhaps we should show why the package does not evaluate but I do not see how to get the eval error with tryEvalhttps://github.com/NixOS/nix/pull/1000

jtojnar commented 3 years ago

This behaves weirdly, for example, the following two attributes both return success = false from tryEval when run in the same hammer execution:

nix shell -f ~/Projects/nixpkgs-hammering -c nixpkgs-hammer python39Packages.hwi python3Packages.hwi --show-trace

Even though python3Packages.hwi does eval on its own.

I tried to reduce the expression printed by the above command so I could run it with nix-instantiate --eval --strict test.nix:

let
    inherit (import /nix/store/xxyy6942qw7qwy93vn6gjf1b2lirhirf-nixpkgs-hammer/lib/standalone.nix) getDrvSourceLocation;
    builtAttrs = [ "python3Packages.hwi" ];
    packageSet = /home/jtojnar/Projects/nixpkgs;
    cleanPkgs = import /home/jtojnar/Projects/nixpkgs { };
    namePositions = builtins.filter (p: p != null) [
        # I can remove either the 3.9 position,
        (let
            drv = cleanPkgs.python39Packages.hwi or { };
        in
            getDrvSourceLocation drv)
        (let
            drv = cleanPkgs.python3Packages.hwi or { };
        in
            getDrvSourceLocation drv)
    ];

    pkgs = import /home/jtojnar/Projects/nixpkgs {
        # or all overlays and it will start to evaluate.
        overlays = [
            # It fails as long as at least one overlay is left (any overlay according to my testing).
            (import /nix/store/xxyy6942qw7qwy93vn6gjf1b2lirhirf-nixpkgs-hammer/overlays/missing-phase-hooks.nix {
                inherit builtAttrs packageSet namePositions;
            })
        ];
    };
in 
    builtins.tryEval pkgs.python3Packages.hwi or null

Edit: Actually, the failure comes from namepositions itself.

jtojnar commented 3 years ago

Works now but we might want to show the nix edit error.

$ nix shell -f ~/Projects/nixpkgs-hammering -c nixpkgs-hammer python39Packages.hwi python3Packages.hwi
error: --- ThrownError ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix
hwi-1.2.1 not supported for interpreter python3.9
When evaluating attribute ‘python39Packages.hwi’:
warning: EvalError
Cannot evaluate attribute ‘python39Packages.hwi’ in ‘/home/jtojnar/Projects/nixpkgs’.

When evaluating attribute ‘python3Packages.hwi’:
warning: attribute-ordering
The lists of dependencies, including the attribute “propagatedBuildInputs” should preferably come before attributes for overriding default phases’ “postPatch” attribute in the expression.

Near /home/jtojnar/Projects/nixpkgs/pkgs/development/python-modules/hwi/default.nix:25:3:
   |
25 |   postPatch = ''
   |   ^
Near /home/jtojnar/Projects/nixpkgs/pkgs/development/python-modules/hwi/default.nix:32:3:
   |
32 |   propagatedBuildInputs = [
   |   ^
See: https://github.com/jtojnar/nixpkgs-hammering/blob/master/explanations/attribute-ordering.md

Or keep it and drop our native error since that one contains the thrown message. But it is not part of the structured output :disappointed: