Searching packages: Difference between revisions

imported>Vater
there is also a search for everybody's (experimental) darling flakes nowadays
Adda0 (talk | contribs)
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
There are multiple ways to search for a package name in <code>nixpkgs</code>.
There are numerous approaches available for searching substrings within both package names and package descriptions in <code>nixpkgs</code>.


== Using <code>search.nixos.org</code> ==
== Using <code>search.nixos.org</code> website ==


There is a web service to search for
There is a web service to search with
* Nix packages at [https://search.nixos.org/packages search.nixos.org/packages]
: [[channel branches]]
* NixOS options at [https://search.nixos.org/options search.nixos.org/options]
:* Nix packages at [https://search.nixos.org/packages search.nixos.org/packages]
* packages for [[flakes]] at [https://search.nixos.org/flakes?type=options search.nixos.org/flakes?type=options]
:* NixOS options at [https://search.nixos.org/options search.nixos.org/options]
* options for [[flakes]] at [https://search.nixos.org/flakes?type=packages search.nixos.org/flakes?type=packages]
: [[flakes]]
:* 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]


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


== Using <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.
If you'd like to search with this web service from the command line, you may use [https://github.com/peterldowns/nix-search-cli peterldowns/nix-search-cli]. It provides exactly the same search experience by default.


<pre>
== Other online sites for searching ==
$ nix --extra-experimental-features "nix-command flakes" search nixpkgs firefox
 
</pre>
These are another possible places to search
 
* [https://github.com/search?q=language%3ANix+&type=code github.com] - search for regex/strings in nixpkgs, home-manager, nix-darwin and any other public github repos.
* [https://mynixos.com mynixos.com] - search for packages in nixpkgs, also nixos, home-manager, nix-darwin options. Not foss and unofficial.
* [https://home-manager-options.extranix.com home-manager-options.extranix.com] - search for home-manager options. [https://github.com/mipmip/home-manager-option-search foss]
 
== Using the <code>nix search</code> 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.
 
<syntaxhighlight lang="bash">nix search nixpkgs firefox</syntaxhighlight>
 
; pros:
* fast
* possible offline usage
; cons:
* requires disk space for caching
* quite long command
 
 
There are third party tools that allow searching for packages similarly to <code>nix search</code>, namely:
* [https://github.com/diamondburned/nix-search diamondburned/nix-search]: A faster and channel-compatible <code>nix search</code> using only stable Nix tools (no [[flakes]] required) which creates a local database with a package index.


== Using the <code>nix-env</code> command ==
== Using the <code>nix-env</code> command ==
Line 27: Line 51:
It's possible to search for a package using <code>nix-env -qaP</code>
It's possible to search for a package using <code>nix-env -qaP</code>


* pros:
; pros:
** works offline
* works offline
* cons:
; cons:
** it's very slow and requires a lot of memory
* it's very slow and requires a lot of memory


== Interactive package browsing with <code>nix repl</code> ==
== Using the <code>nix repl</code> environment ==


You can start <code>nix repl</code> to load the <code>nixpkgs</code> repository and then use auto completion to search for packages.
With the read–eval–print loop (REPL) of nix you can browse packages interactively.


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


nix-repl> :load <nixpkgs>
nix-repl>  
Added 16519 variables.
</syntaxhighlight>


nix-repl> firef[PRESS TAB]
Loading the repository for nixpkgs
</pre>
<syntaxhighlight lang="console">
nix-repl>
</syntaxhighlight>
<syntaxhighlight lang="bash">nix-repl> :load <nixpkgs>
Added 21181 variables.
</syntaxhighlight>Type the first letters of a package
<syntaxhighlight lang="bash">nix-repl> neo  </syntaxhighlight>
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 are third party programs that make it easier to determine which package you need to install in order to obtain a specific file or program.
 
These are most commonly used, and require you to create an index on your computer before you can search for a package:
 
* [https://github.com/nix-community/nix-index nix-community/nix-index]
* [https://github.com/replit/rippkgs replit/rippkgs]
 
These are online tools which search an index someone else keeps up to date:
 
* [https://github.com/peterldowns/nix-search-cli peterldowns/nix-search-cli]: <code>nix-search -p theBinaryIWantToInstall</code> to search the search.nixos.org elasticsearch index.


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