Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference to nix-index? #19

Closed
TornaxO7 opened this issue Feb 6, 2025 · 2 comments
Closed

Difference to nix-index? #19

TornaxO7 opened this issue Feb 6, 2025 · 2 comments

Comments

@TornaxO7
Copy link

TornaxO7 commented Feb 6, 2025

Hi, may I ask what the advantages/disadvantages are of nps in comparison to nix-index/nix-locate?

@OleMussmann
Copy link
Owner

Sure! Maybe I need to explain that better in the README.md.

  • nix-index/nix-locate allow you to search for paths in derivations; it finds all derivations that contain your search term in the paths they provide.
  • nps searches the name and description text of derivations in nixpkgs.

Here's a motivation for nps and a general comparison with the existing search commands.

Why nps?

NixOS and the nix package manager miss an equivalent for apt search/dnf search/pacman -Ss/etc. There are powerful existing tools available which do work, but do not provide the user experience I am searching for. Before installing packages or creating a nix shell, I would like to know:

  • Is the package in the repo?
  • What is the package version?
  • Are there other packages related to it?

My goal is not for nps to replace any of the already existing tools, but to supply an intuitive way to quickly obtain the information outlined above.

For comparison, the following examples search for avahi. Benchmarks are done with hyperfine.

Comparisons

Keep in mind that the readability is, of course, subjective.

command cache size speed readability
nix-env -qaP avahi ? 9720 ms ++
nix search nixpkgs avahi ? 1055 ms +
nix-locate "bin/avahi" 73 M 806.0 ms --
nps avahi 5.9 M 4.1 ms +++

nix-index/nix-locate

Maybe it was a glitch, but creating the nix-index cache stalled my internet connection and took such a long time that I decided to run it over night. Using the pre-generated nix-index-database would certainly help here.

This tool scores rather low, it is not really meant for simple package searching.

Output (cropped, way too long):
Image

Usecase nix-index:

  • command-not-found replacement
  • Query derivations for certain paths

Benefits

  • Can find derivation paths, even if the name of the executable does not match the package name, e.g. ripgrep with executable rg.

Drawbacks

  • Long, confusing output
  • Unsorted
  • Slow

nix search nixpkgs

I'm throwing nix search a bone here and used a repeated search for benchmarking. This makes it much faster and omits a ton of "evaluation warning"s that clutter the output. Output content is rather similar to nps, since we cache the (JSON) output of this command. I don't know if this commands use any cache of some sorts.

Output (full)
Image

Benefits

  • Rather brief output

Drawbacks

  • Unsorted
  • Slow

nix-env -qaP --description

Output content is rather similar to nps, since we cache the output of this command. I don't know if this commands use any cache of some sorts.

Output (full)
Image

Benefits

  • Brief output!
  • Can search available or installed packages

Drawbacks

  • Unsorted
  • Very slow
  • Does not search package descriptions

nps

Output (full)
Image

Benefits

  • Brief output
  • Color coded
  • Sorted by relevance, most important match is below
  • Configurable output, choose desired columns

Drawbacks

  • Only search nixpkgs (for now)
  • Cannot filter for only installed packages

@TornaxO7
Copy link
Author

Thank you for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants