How to find the package name for executable

Though that doesn’t always point to the correct location…

Today I had this problem:

$ dig
The program ‘dig’ is currently not installed. You can install it by typing:
  nix-env -iA nixos.bind
$ nix run nixos.bind -c dig example.com
error: unable to exec 'dig': No such file or directory
$ nix run nixpkgs.bind -c dig example.com
error: unable to exec 'dig': No such file or directory

Where nixos and nixpkgs are nixos-20.03 and nixos-unstable channels respectively.

Someone else in the inofficial discourse already helped me out by pointing me to nixos.bind.dnsutils which then worked.

Still it seems as if either the database isn’t updated properly or needs manual updating which isn’t documented very well.