Quickly check what packages are available to your NixOS machine
This project provides a Python-based CLI tool for searching NixOS packages. It uses caching to improve search performance, especially for repeated searches. The script supports various search modes and can highlight matching terms in the results for better readability.
- Caching: Automatically caches package information for faster subsequent searches.
- Search Modes:
- Case-sensitive search
- Whole word match
- Match at the end of package names
- Exact component match
- Customizable Output: Option to enable or disable colored output for matched terms.
- Automatic Cache Refresh: Cache updates automatically if it's older than 24 hours.
- NixOS: The tool uses
nix-env
to fetch package details, and is intended to be ran on NixOS - Python 3: Ensure Python 3 is installed.
Run the script with a search term to look for NixOS packages. The tool provides several optional flags for different search behaviors.
python search-nixos-packages.py <search_term>
-f
,--force
: Force refresh the package cache, even if it’s less than 24 hours old.-x
: Case-sensitive match.-xx
: Match whole words only, ensuring the search term is a separate word.-xxx
: Match at the end of package names, restricting results to packages where the term appears at the end.-xxxx
or-e
: Match exact package name components only, highlighting packages that match the term exactly, either at the start or after a period.--no-color
: Disable colored output for matched terms.
-
Simple Search (case-insensitive):
python search-nixos-packages.py firefox
-
Case-Sensitive Search:
python search-nixos-packages.py -x firefox
-
Exact Package Component Search:
python search-nixos-packages.py -xxxx firefox
-
Force Update Cache:
python search-nixos-packages.py firefox -f
-
Shorthand for Exact Component Search:
python search-nixos-packages.py -e firefox
Running the command below highlights firefox
as an exact package component, showing only matches where firefox
appears precisely as part of the package name or after a period.
python search-nixos-packages.py -e firefox
Searching for: firefox (exact package name components only)
----------------------------------------
nixos.firefox A web browser built from Firefox source tree
- Caching: The script saves package information to a unique cache file in
/tmp
. The cache is refreshed automatically if it's older than 24 hours, or can be forced to refresh using the-f
flag. - Matching and Highlighting: The tool provides multiple matching modes to customize the search behavior. It highlights matching terms in red by default, which can be disabled with the
--no-color
option.
The provided nixos-scan-packages.nix can be imported into your configuration.nix and used to map the script to a unique command name for easy usage from any terminal. Update the path to your local copy. The example maps the command to "ca", allowing you to run the script from anywhere, such as
ca firefox
or
ca -e firefox
highlight_matches
: Highlights the matched search term in the output line.search_packages
: Reads the cached package file and applies the search term with the chosen match type.update_cache
: Updates the package cache by callingnix-env
.main
: Manages argument parsing, cache checking, and initiates the search.