[!NOTE] I've been using the Nix website to search for packages, and while it worked fine, it required me to open the site, enter the search string, and go through the process each time. Although the nix search nixpkgs command worked, it took some time to load and evaluate everything.
Later, a friend on Discord (.sszark) shared a command with me that allows searching for packages using fzf. Although I eventually learned about nix-index, I had already created this script. So, here we are.
nix run github:niksingh710/nsearch
# flake input
nsearch = {
url = "github:niksingh710/nsearch";
inputs.nixpkgs.follows = "nixpkgs";
};
environment.systemPackages = [
inputs.nsearch.packages.${pkgs.system}.default
];
[!TIP] Use fzf multimode to select multiple packages.
NSEARCH_FZF_CMD="fzf --multi --bind='ctrl-space:select' --bind='ctrl-/:deselect' "
Make the bellow script your shell
command as replacement of nix-shell
command.
#!/usr/bin/env bash
# Initialize empty arrays for package names and options
ps=()
os=()
# Loop through all the arguments
for p in "$@"; do
if [[ "$p" != --* ]]; then
# If not an option, add it to the package names array
ps+=("nixpkgs#$p")
else
# If it is an option, add it to the options array
os+=("$p")
fi
done
# Construct the command
cmd="SHELL=$(which zsh) IN_NIX_SHELL=\"impure\" nix shell ${os[*]} ${ps[*]}"
echo "Executing \`$cmd\`..."
# Execute the command
eval $cmd
Then you can use the below command to easily initialize the nix-shell with multiple packages.
shell $(nsearch)
[!TIP] You can also map
nsearch
to a keybind in zsh via widgets.
Addition of new features, bug fixes, and improvements are always welcome.