Hysen Labs
Open-source project
nix-community/nix-index-database avatar
nix-community

nix-index-database

Weekly updated nix-index database [maintainer=@Mic92]

610 stars50 forksNixMIT
DEEP OPEN-SOURCE ANALYSIS

Nix index database ships a weekly updated nix index

A companion repository that provides NixOS, nix darwin, and home manager modules wrapping a regularly rebuilt nix index database.

What the database provides

nix-index-database is a weekly updated nix-index database for the nixos unstable channel. The nix-index tool lets you locate which package provides a given file by searching an index of the nix package set. Maintaining that index yourself takes time and bandwidth, so this repository publishes a prebuilt database and wraps it so your system uses it automatically. The repository also provides NixOS modules and home manager modules that add a nix-index wrapper pointing at the database from this project. The home manager module can also integrate with the existing command not found functionality, so typing a missing command name can tell you which package provides it. The project offers two database variants. The full variant, which is the default, contains all indexed files including headers and libraries, and it is packaged as nix-index-with-db. The small variant contains only files under the /bin/ directories, so it is much smaller, downloads faster, and uses less memory, and it is packaged as nix-index-with-small-db. To use the small database you override the nix-index package in your configuration with the small db package. A demo in the README shows running nix run against the repository to locate the binary cntr and its store path. The requirements state Nix 2.18 or newer, because the packages use unsafeDiscardReferences to skip nix store checks, and on older Nix the packages may fail.

Wiring it into NixOS and home manager

To use the database on NixOS you add the project's flake as an input and include its nixosModules.default in your configuration. The README warns that when you use this module you must not also list nix-index in environment.systemPackages, because that conflicts with the wrapper this project provides. After that, calling nix-locate uses the database from this repository without further setup. For nix darwin the setup is similar: you add the flake input, follow the nixpkgs input, and include the darwinModules.nix-index module. For home manager you follow the home manager flakes manual, add the nix-index-database flake, and include homeModules.default. The same conflict warning applies: do not also put nix-index in home.packages. Once installed, nix-locate works as usual and automatically reads the provided database. The README's demo resolves the cntr binary to its store path by running nix run github:nix-community/nix-index-database bin/cntr, and switching to the small database means overriding programs.nix-index.package with the nix-index-with-small-db package for your system. If your shell is managed by home manager, you can set programs.nix-index.enable to true so nix-index integrates with the shell's command not found feature. The README also notes an optional comma wrapper that you can enable with programs.nix-index-database.comma.enable in either the NixOS or home manager module, which also wraps and installs the comma tool alongside nix-index.

Fetching the index without a module

If you do not want to use the NixOS, nix darwin, or home manager modules, you can download the index file directly. The README gives a shell function called download_nixpkgs_cache_index that builds a filename from the machine architecture and operating system, makes a cache directory under your home, and fetches the latest release asset with wget. It then links the downloaded file to the name files that nix-index expects. This is useful for ad hoc use on a machine where you cannot or do not want to change the system configuration. The database is rebuilt weekly, so a periodic rerun of the function keeps the local copy current. The project is maintained by the nix community organization, and the README links to the underlying nix-index project for background on how the locator works. Because the index covers the nixos unstable channel, the package names and store paths it reports reflect that rolling release. Users on a stable or small channel should be aware that the provided database targets unstable, which is the explicitly stated scope of this repository. The two variants let you trade coverage for size depending on whether you only need to find executables or also headers and libraries.

Editorial conclusion

nix-index-database is a weekly updated nix-index database for the nixos unstable channel, licensed under MIT. It ships NixOS, nix darwin, and home manager modules plus a full and a small database variant.

DEEP OPEN-SOURCE ANALYSIS

Official sources

Community notes

Community notes