I can’t tell from the nixpkgs-hammering repo whether it’s usable against arbitrary Nix files, like a typical shell.nix. Does anyone know? It’s not in nixpkgs, so I expect not, but I thought I’d check before filing a feature request.
No, not really. If you mimic nixpkgs closely you could get it to work but it just failed like this on an arbritary nix file:
▶ nix run github:jtojnar/nixpkgs-hammering something
error: anonymous function at default.nix:1:1 called with unexpected argument 'overlays'
at «stdin»:6:12:
5|
6| pkgs = import packageSet {
| ^
7| overlays = [
Traceback (most recent call last):
File "/nix/store/wkwnhc6i4s1f66c6aip008s2bxpb5xyi-nixpkgs-hammering/bin/.nixpkgs-hammer-wrapped", line 410, in <module>
main(args)
File "/nix/store/wkwnhc6i4s1f66c6aip008s2bxpb5xyi-nixpkgs-hammering/bin/.nixpkgs-hammer-wrapped", line 331, in main
overlay_data = nix_eval_json(all_messages_nix, args.show_trace)
File "/nix/store/wkwnhc6i4s1f66c6aip008s2bxpb5xyi-nixpkgs-hammering/bin/.nixpkgs-hammer-wrapped", line 136, in nix_eval_json
json_text = subprocess.check_output(args, text=True, input=expr)
File "/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3.10/subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3.10/subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nix-instantiate', '--strict', '--json', '--eval', '-']' returned non-zero exit status 1.
Currently, the conditions are that the repo must have default.nix
that supports being passed overlays
argument:
and returns an attribute set, whose packages are called by Nixpkgs passed those overlays.
Here is an example from nixpkgs-hammering tests:
And here is what I do in my personal config flake (using flake-compat):
So you can make it work for shell.nix
but not without some adjustments to match the aforementioned requirements.
Moreover, some checks are very dependent on the revision of Nixpkgs and will crash if a different revision is used (e.g. lib.licenses.gpl1
has been removed). Also, some newer Nixpkgs idioms (e.g finalAttrs
) are not implemented yet, so attempting to check packages using those will fail.