Searching packages: Difference between revisions

From NixOS Wiki
Klinger (talk | contribs)
Package search does not only search package names, but also the description. Added pro/contra to a subsection. Added idea of search engines in browser)
Gerg-L (talk | contribs)
fixed nix-index link, updated nix repl section mention rippkgs
Line 3: Line 3:
== Using <code>search.nixos.org</code> website ==
== Using <code>search.nixos.org</code> website ==


There is a web service to search for
There is a web service to search with
: with [[channels]]
: [[channels]]
:* Nix packages at [https://search.nixos.org/packages search.nixos.org/packages]
:* Nix packages at [https://search.nixos.org/packages search.nixos.org/packages]
:* NixOS options at [https://search.nixos.org/options search.nixos.org/options]
:* NixOS options at [https://search.nixos.org/options search.nixos.org/options]
: with [[flakes]]
: [[flakes]]
:* packages at [https://search.nixos.org/flakes?type=packages search.nixos.org/flakes?type=packages]
:* packages at [https://search.nixos.org/flakes?type=packages search.nixos.org/flakes?type=packages]
:* options at [https://search.nixos.org/flakes?type=options search.nixos.org/flakes?type=options]
:* options at [https://search.nixos.org/flakes?type=options search.nixos.org/flakes?type=options]
Line 21: Line 21:
== Using the <code>nix search</code> command ==
== Using the <code>nix search</code> command ==


While this command is still experimental, you can use it to search for a package. It may be slow the first time, but further runs will use cached results.
While this command requires [[flakes]], you can use it to search for a package. It may be slow the first time, but further runs will use cached results.


<syntaxhighlight lang="bash">nix --extra-experimental-features "nix-command flakes" search nixpkgs firefox</syntaxhighlight>
<syntaxhighlight lang="bash">nix search nixpkgs firefox</syntaxhighlight>


; pros:
; pros:
Line 45: Line 45:
With the read–eval–print loop (REPL) of nix you can browse packages interactively.
With the read–eval–print loop (REPL) of nix you can browse packages interactively.


Starting the [[nix command/repl|nix repl]]
Starting the [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-repl.html nix repl]
<syntaxhighlight lang="bash">nix repl</syntaxhighlight>
<syntaxhighlight lang="bash">nix repl</syntaxhighlight>
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
Welcome to Nix 2.8.1. Type :? for help.
Welcome to Nix 2.18.2. Type :? for help.


nix-repl>
nix-repl>  
</syntaxhighlight>
</syntaxhighlight>


Line 57: Line 57:
nix-repl>
nix-repl>
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="bash">:load <nixpkgs></syntaxhighlight>
<syntaxhighlight lang="bash">nix-repl> :load <nixpkgs>
<syntaxhighlight lang="console">
Added 21181 variables.
Added 16519 variables.
</syntaxhighlight>Type the first letters of a package
</syntaxhighlight>
<syntaxhighlight lang="bash">nix-repl> neo  </syntaxhighlight>
 
Type the first letters of a package
<syntaxhighlight lang="console">nix-repl></syntaxhighlight>
<syntaxhighlight lang="bash">firef</syntaxhighlight>
Press <tt>Tab ↹</tt> key<!-- {{[[mw:Template::Key press]]|Tab}} --> for auto completion
Press <tt>Tab ↹</tt> key<!-- {{[[mw:Template::Key press]]|Tab}} --> for auto completion


== Reverse search: searching which package provides a file ==
== Reverse search: searching which package provides a file ==


There is a third party program [https://github.com/bennofs/nix-index nix-index] to find which package provides a given file. This is particularly useful when you are looking for a very specific file but you don't know which package installs it.
There is third party programs [https://github.com/nix-community/nix-index nix-index], and [https://wiki.nixos.org/wiki/Flakes rippkgs] to find which package provides a given file. This is particularly useful when you are looking for a very specific file but you don't know which package installs it.


[[Category:Reference]]
[[Category:Reference]]
[[Category:Nixpkgs]]
[[Category:Nixpkgs]]

Revision as of 18:22, 27 April 2024

There are numerous approaches available for searching substrings within both package names and package descriptions in nixpkgs.

Using search.nixos.org website

There is a web service to search with

channels
flakes
pros
  • easy to use
  • allows filters
  • nice GUI in browser
  • browser extensions possible (like @nixpgs as search engine in Firefox)
cons
  • always requires Internet connection

Using the nix search command

While this command requires flakes, you can use it to search for a package. It may be slow the first time, but further runs will use cached results.

nix search nixpkgs firefox
pros
  • fast
  • possible offline usage
cons
  • requires disk space for caching
  • quite long command

Using the nix-env command

It's possible to search for a package using nix-env -qaP

pros
  • works offline
cons
  • it's very slow and requires a lot of memory

Using the nix repl environment

With the read–eval–print loop (REPL) of nix you can browse packages interactively.

Starting the nix repl

nix repl
Welcome to Nix 2.18.2. Type :? for help.

nix-repl>

Loading the repository for nixpkgs

nix-repl>
nix-repl> :load <nixpkgs>
Added 21181 variables.

Type the first letters of a package

nix-repl> neo

Press Tab ↹ key for auto completion

Reverse search: searching which package provides a file

There is third party programs nix-index, and rippkgs to find which package provides a given file. This is particularly useful when you are looking for a very specific file but you don't know which package installs it.