Searching packages: Difference between revisions
imported>Vater |
Add `nps` as an option for searching packages |
||
| (10 intermediate revisions by 7 users not shown) | |||
| Line 1: | Line 1: | ||
There are | 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> website == | == Using <code>search.nixos.org</code> website == | ||
There is a web service to search | There is a web service to search with | ||
: | : [[channel branches]] | ||
:* 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] | ||
: | : [[flakes]] | ||
:* packages at [https://search.nixos.org/flakes?type= | :* packages at [https://search.nixos.org/flakes?type=packages search.nixos.org/flakes?type=packages] | ||
:* options at [https://search.nixos.org/flakes?type= | :* 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 | ||
* nice GUI in browser | |||
* browser extensions possible (like @nixpkgs as search engine in Firefox) | |||
; cons: | ; cons: | ||
* requires Internet connection | * always requires Internet connection | ||
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. | |||
== Other online sites for searching == | |||
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 == | == Using the <code>nix search</code> command == | ||
While this 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 -- | <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 31: | Line 55: | ||
; cons: | ; cons: | ||
* it's very slow and requires a lot of memory | * it's very slow and requires a lot of memory | ||
== Using the <code>nps</code> command == | |||
<code>nps</code> caches entire <code>nix search nixpkgs ^</code> and <code>nix-env -qaP --description</code> results locally and queries the cache. | |||
<syntaxhighlight lang="bash">nps firefox</syntaxhighlight> | |||
; pros: | |||
* works offline | |||
* very fast | |||
* easy syntax | |||
* output sorted by relevance | |||
; cons: | |||
* [https://github.com/OleMussmann/nps/blob/main/README.md third party program] | |||
* [https://github.com/OleMussmann/nps/blob/main/README.md#automatic-cache-refresh-optional-recommended- cache needs regular refreshing (automatable)] | |||
== Using the <code>nix repl</code> environment == | == Using the <code>nix repl</code> environment == | ||
| Line 36: | Line 76: | ||
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 [ | 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. | Welcome to Nix 2.18.2. Type :? for help. | ||
nix-repl> | nix-repl> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 48: | Line 88: | ||
nix-repl> | nix-repl> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="bash">:load <nixpkgs | <syntaxhighlight lang="bash">nix-repl> :load <nixpkgs> | ||
Added 21181 variables. | |||
Added | </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=" | |||
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 | 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]] | ||
Latest revision as of 16:28, 7 December 2025
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
- channel branches
- Nix packages at search.nixos.org/packages
- NixOS options at search.nixos.org/options
- flakes
- packages at search.nixos.org/flakes?type=packages
- options at search.nixos.org/flakes?type=options
- pros
- easy to use
- allows filters
- nice GUI in browser
- browser extensions possible (like @nixpkgs as search engine in Firefox)
- cons
- always requires Internet connection
If you'd like to search with this web service from the command line, you may use peterldowns/nix-search-cli. It provides exactly the same search experience by default.
Other online sites for searching
These are another possible places to search
- github.com - search for regex/strings in nixpkgs, home-manager, nix-darwin and any other public github repos.
- mynixos.com - search for packages in nixpkgs, also nixos, home-manager, nix-darwin options. Not foss and unofficial.
- home-manager-options.extranix.com - search for home-manager options. foss
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
There are third party tools that allow searching for packages similarly to nix search, namely:
- diamondburned/nix-search: A faster and channel-compatible
nix searchusing only stable Nix tools (no flakes required) which creates a local database with a package index.
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 nps command
nps caches entire nix search nixpkgs ^ and nix-env -qaP --description results locally and queries the cache.
nps firefox
- pros
- works offline
- very fast
- easy syntax
- output sorted by relevance
- cons
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 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:
These are online tools which search an index someone else keeps up to date:
- peterldowns/nix-search-cli:
nix-search -p theBinaryIWantToInstallto search the search.nixos.org elasticsearch index.