How to find the package name for executable

i install a lot nix command to use rather than system command.

such as sed, grep, netstat…

    pkgs.coreutils                                                                                                                                             
    pkgs.inetutils                                                                                                                                             
    pkgs.unixtools.netstat                                                                                                                                     
    pkgs.findutils                                                                                                                                             
    pkgs.dnsutils                                                                                                                                              
    pkgs.gnused                                                                                                                                                
    pkgs.less                                                                                                                                                  
    pkgs.gawk                                                                                                                                                  
    pkgs.cron                                                                                                                                                  

but sometimes the command is hard to find.
such as, i can’t find ‘free -m’, which package the [free] origin from?

what’s the good way to search about it?

4 Likes

Perhaps programs.command-not-found.enable can help you a bit?

GitHub - nix-community/nix-index: Quickly locate nix packages with specific files [maintainers=@bennofs @figsoda @raitobezarius] was built for this. I usually run nix-locate bin/whatever. It is also available as irc bot command ,locate in #nixos in freenode.

2 Likes

As a quick-and-dirty method, I will often just use readlink -e $(which $APP) to see what program I’m calling; the path in the Nix store will generally tell you the package name. For example, on my system:

$ readlink -e $(which free)
/nix/store/yrnnk11a7wafwhx2nzl4xa1l89av3h3d-procps-3.3.16/bin/free
$ 

And, indeed, free in this case is provided by pkgs.procps.

This method can get a little wonky for packages with different outputs (bin, lib, etc.), and occasionally the path doesn’t match the attribute name exactly (utillinux, I’m looking at you), but 95% of the time you can tell the package just from the Nix store path.

if you’re using nix-channels and NixOS, you will get a message as to which package to install:

$ glances
The program ‘glances’ is currently not installed. You can install it by typing:
  nix-env -iA nixos.glances

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.