jtojnar / nixpkgs-hammering

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

attribute-ordering: fix possible crash #74

Closed rmcgibbo closed 3 years ago

rmcgibbo commented 3 years ago

Fixes the following crash, against nixpkgs edb5000ea3e02c8fe1caba17c6c329066d6d8ae9

$ nixpkgs-hammer -f . warsow-engine
[1 built, 0.0 MiB DL]
error: --- TypeError ------------------------------------------------------------------------------------------------------------- nix-instantiate
at: (33:27) in file: /nix/store/0gsly7wzm6pkq7x8q8fzs24npsxmzjd5-nixpkgs-hammer/overlays/attribute-ordering.nix

    32|       getAttrPos = attr: (builtins.unsafeGetAttrPos attr drvArgs);
    33|       getAttrLine = attr: (getAttrPos attr).line; #or 0;
      |                           ^
    34| 

value is null while a set was expected
(use '--show-trace' to show detailed location information)
Traceback (most recent call last):
  File "/nix/store/0gsly7wzm6pkq7x8q8fzs24npsxmzjd5-nixpkgs-hammer/bin/.nixpkgs-hammer-wrapped", line 318, in <module>
    main(args)
  File "/nix/store/0gsly7wzm6pkq7x8q8fzs24npsxmzjd5-nixpkgs-hammer/bin/.nixpkgs-hammer-wrapped", line 238, in main
    overlay_data = nix_eval_json(all_messages_nix, args.show_trace)
  File "/nix/store/0gsly7wzm6pkq7x8q8fzs24npsxmzjd5-nixpkgs-hammer/bin/.nixpkgs-hammer-wrapped", line 70, in nix_eval_json
    result = subprocess.check_output(args, encoding="utf-8", input=expr)
  File "/nix/store/wkw6fsjasr7jbbrlakxxpbiapa8hws42-python3-3.8.7/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/nix/store/wkw6fsjasr7jbbrlakxxpbiapa8hws42-python3-3.8.7/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nix-instantiate', '--strict', '--json', '--eval', '-']' returned non-zero exit status 1.
jtojnar commented 3 years ago

Weird, that the attributes do not have position:

nix-repl> builtins.filter (attr: builtins.unsafeGetAttrPos attr warsow-engine == null) (builtins.attrNames warsow-engine)   
[ "curl" "freetype" "libjpeg" "libogg" "libpng" "libtheora" "libvorbis" "zlib" ]

nix-repl> builtins.unsafeGetAttrPos "foo" (builtins.listToAttrs [{name = "foo"; value = 1; }])                            
{ column = 71; file = "builtins.unsafeGetAttrPos \"foo\" (builtins.listToAttrs [{name = \"foo\"; value = 1; }])\n"; line = 1; }

nix-repl> builtins.unsafeGetAttrPos "foo" (builtins.mapAttrs (n: v: v) { foo = 1; })           
null

It looks like mapAttrs can strip it.

https://github.com/NixOS/nixpkgs/blob/e2c1fe74be9528ed69c281194aad02148fb98a1e/pkgs/games/warsow/engine.nix#L5-L11

jtojnar commented 3 years ago

Fixed warsow in https://github.com/NixOS/nixpkgs/pull/114330

jtojnar commented 3 years ago

Thanks.