Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with nixStatic #102

Open
rmcgibbo opened this issue Apr 2, 2021 · 3 comments
Open

Crash with nixStatic #102

rmcgibbo opened this issue Apr 2, 2021 · 3 comments

Comments

@rmcgibbo
Copy link
Collaborator

rmcgibbo commented Apr 2, 2021

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.
@rmcgibbo rmcgibbo changed the title Crash with nix-static Crash with nixStatic Apr 3, 2021
@YoungC2015
Copy link

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
Copy link
Owner

jtojnar commented Jul 16, 2021

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
Copy link
Owner

jtojnar commented Jul 16, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants