How to get the .nix file of a nixpkgs package

I’m looking to find out the file/dir where a package/attribute from nixpkgs comes from. I’ve looked into the repl and through nix-pills but I’m not very familiar with whats available from builtins or lib, I’m not really sure I’d find something that would do what I want in there though. So I thought to ask here if anyone knows of a way to get this info?

Most of the time just doing git grep 'hello =' from nixpkgs root works out well for me (where hello is the name of the attribute).

It’ll print usually a line of a file in pkgs/top-level, from which you can then follow to the actual file.

Yeah this is what I started to work with, but then ran into “issues” with some packages like:
gitAndTools.(hub|delta|...)
pythonPackages.python-language-server vs just python-language-server (in c# from microsoft)

Nothing I can’t hack around but was wondering if anything existed that would do a better job.

For some rare circumstances nix edit might work (if you use a version that supports it, I’m not sure if its in 2.3 or 2.4 only) also :e on the REPL can help.

Hmm I’ll take a look at this.

This works great!

E:EDITOR=echo nix edit -I nixpkgs=$E:HOME/.config/home-manager-config/nixpkgs nixpkgs.gitAndTools.hub
/home/manny/.config/home-manager-config/nixpkgs/pkgs/applications/version-management/git-and-tools/hub/default.nix