jtojnar / nixpkgs-hammering

Beat your package expressions into a shape
MIT License
241 stars 15 forks source link

Crash with `nixStatic` #102

Open rmcgibbo opened 3 years ago

rmcgibbo commented 3 years ago

In nixpkgs e58bd1763e4cd047371712f2030716440b40cff9

This looks like a new error beyond those that were flagged in #97

$ nix run -f ~/projects/nixpkgs-hammering -c nixpkgs-hammer -f . nixStatic
error: --- TypeError ------------------------------------------------------------------------------------------------------------- nix-instantiate
at: (63:22) in file: /home/mcgibbon/projects/nixpkgs/pkgs/stdenv/adapters.nix

    62|         ];
    63|         cmakeFlags = (args.cmakeFlags or []) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ];
      |                      ^
    64|         mesonFlags = (args.mesonFlags or []) ++ [ "-Ddefault_library=static" ];

value is null while a list was expected
(use '--show-trace' to show detailed location information)
Traceback (most recent call last):
  File "/nix/store/ihsdscx45ryv06g36v8p7nz88ncx2kc1-nixpkgs-hammer/bin/.nixpkgs-hammer-wrapped", line 399, in <module>
    main(args)
  File "/nix/store/ihsdscx45ryv06g36v8p7nz88ncx2kc1-nixpkgs-hammer/bin/.nixpkgs-hammer-wrapped", line 326, in main
    overlay_data = nix_eval_json(all_messages_nix, args.show_trace)
  File "/nix/store/ihsdscx45ryv06g36v8p7nz88ncx2kc1-nixpkgs-hammer/bin/.nixpkgs-hammer-wrapped", line 136, in nix_eval_json
    json_text = subprocess.check_output(args, text=True, input=expr)
  File "/nix/store/yl69v76azrz4daiqksrhb8nnmdiqdjg9-python3-3.8.8/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/nix/store/yl69v76azrz4daiqksrhb8nnmdiqdjg9-python3-3.8.8/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nix-instantiate', '--strict', '--json', '--eval', '-']' returned non-zero exit status 1.
YoungC2015 commented 2 years ago

I'm new to nix. And I don't even know how print-and-debug the value of any internal variables. All I known is to run nix-build with --show-trace to get the prompts. I would like to share my experiment.

when it was originally: cmakeFlags = (args.cmakeFlags or []) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]; The error prompted: value is null while a list was expected

I guess the (args.cmakeFlags or []) become null and lead to the result of concatLists(++) being null. But when I changed it to: cmakeFlags = (if args.cmakeFlags == null then [] else args.cmakeFlags) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]; The error prompted: attribute 'cmakeFlags' missing

Not robusting enough? So I tried : (if builtins.hasAttr "cmakeFlags" args then args.cmakeFlags else []) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]; The error prompted: value is null while a list was expected, AGAIN!

Finally, this annoyed me, so I used this to fix the problem. (if builtins.hasAttr "cmakeFlags" args then [ args.cmakeFlags ] else []) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]; Obviously, it would be a problem if the cmakeFlags was originally a list.

It worked at least. And I would appreciate it if any one tell me the reason why all these happened.

jtojnar commented 2 years ago

If you run nix shell -f /home/jtojnar/Projects/nixpkgs-hammering -c nixpkgs-hammer nixStatic --show-trace, you will get the Nix expression used to run the checks. You can save it into a file and then evaluate it using nix-instantiate --strict --json --eval test.nix, commenting out individual overlays using binary search to find the offending check. In this case it looks like overlays/unnecessary-parallel-building.nix.


You are right that the issue is that cmakeFlags is null. <set>.<attr> or <fallback> syntax only returns the fallback if the attribute set does not contain the attribute – when it is present but set to null, the syntax will return null.

(if builtins.hasAttr "cmakeFlags" args then [ args.cmakeFlags ] else []) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]

will return a list or null, depending on the original value, wrapped in a list. That avoids the type error but is still not optimal since inputs should be precisely of type list of derivations.

You could use:

(if args.cmakeFlags or [] == null then [] else args.cmakeFlags or []) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]

or

(if args.cmakeFlags or null == null then [] else args.cmakeFlags) ++ [ "-DBUILD_SHARED_LIBS:BOOL=OFF" ]
jtojnar commented 2 years ago

Running with --show-trace also reveals that the null value comes from https://github.com/NixOS/nixpkgs/blob/6d049fcad132f1f05336fcf373ec009d0d9a62cc/pkgs/development/libraries/libtiff/default.nix#L22-L24