nix-index はnixpkgs
内の特定のファイルを提供するパッケージを素早く見つけるためのツールです。バイナリ キャッシュで見つかったビルドされた派生のインデックスを作成します。
$ nix-locate 'bin/hello'
hello.out 29,488 x /nix/store/bdjyhh70npndlq3rzmggh4f2dzdsj4xy-hello-2.10/bin/hello
linuxPackages_4_4.dpdk.examples 2,022,224 x /nix/store/jlnk3d38zsk0bp02rp9skpqk4vjfijnn-dpdk-16.07.2-4.4.52-examples/bin/helloworld
linuxPackages.dpdk.examples 2,022,224 x /nix/store/rzx4k0pb58gd1dr9kzwam3vk9r8bfyv1-dpdk-16.07.2-4.9.13-examples/bin/helloworld
linuxPackages_4_10.dpdk.examples 2,022,224 x /nix/store/wya1b0910qidfc9v3i6r9rnbnc9ykkwq-dpdk-16.07.2-4.10.1-examples/bin/helloworld
linuxPackages_grsec_nixos.dpdk.examples 2,022,224 x /nix/store/2wqv94290pa38aclld7sc548a7hnz35k-dpdk-16.07.2-4.9.13-examples/bin/helloworld
camlistore.out 7,938,952 x /nix/store/xn5ivjdyslxldhm5cb4x0lfz48zf21rl-camlistore-0.9/bin/hello
データベースを作成します。
$ nix run github:nix-community/nix-index#nix-index
ファイルのクエリ:
$ nix run github:nix-community/nix-index#nix-locate -- bin/hello
nix-index の最新開発バージョンをインストールするには、リポジトリのクローンを作成し、 nix-env -if.
:
$ git clone https://github.com/nix-community/nix-index
$ cd nix-index
$ nix-env -if.
安定バージョンの場合は、最新のタグをチェックアウトするか (リストはこちら)、Nixpkgs のリポジトリを使用して次のようにインストールできます。
$ nix-env -iA nixos.nix-index
まず、 nix-index
実行してインデックスを生成する必要があります (約 5 分かかります)。次に、 nix-locate pattern
使用できます。詳細については、 nix-locate --help
およびnix-index --help
を参照してください。
nix-index-database は、データベースをローカルに生成したくない場合に、事前に生成されたデータベースを提供します。これらのデータベースを使用するための nixos/home-manager モジュールも付属しています。
Nix-index は、シェル内で見つからないコマンドの属性パスを出力できる「command-not-found」スクリプトを提供します。 ${pkgs.nix-index}/etc/command-not-found.sh
独自のシェル初期化ファイルでソースするか (私たちが知っている限り ZSH と Bash で動作します)、ホームで次のものを使用できます。マネージャー / /etc/nixos/configuration.nix
:
programs . command-not-found . enable = false ;
# for home-manager, use programs.bash.initExtra instead
programs . bash . interactiveShellInit = ''
source ${ pkgs . nix-index } /etc/profile.d/command-not-found.sh
'' ;
zsh
使用する場合は、 bash
zsh
に置き換えます。
出力例:
$ blender
The program 'blender' is currently not installed. You can install it
by typing:
nix-env -iA nixpkgs.blender.out
Or run it once with:
nix-shell -p blender.out --run ...
このスクリプトを使用してnix-index
bash
、 zsh
、およびfish
と統合するhome-manager
モジュールが利用できるようになりました。
不足している機能を見つけて実装したい場合は、ぜひ PR してください。機能がより複雑な場合は、最初に問題を作成して、可能な実装について話し合うこともできます。
すべての関連ファイルの簡単な説明は次のとおりです。
bin/{nix-index, nix-locate}.rs
: nix-index / nix-locate コマンドライン ツールの実装src/database.rs
: データベース形式を操作するための高レベル関数src/files.rs
: ファイルリストを操作するためのデータ型src/frcode.rs
: 多くのファイル パスを効率的に保存するためのエンコーダーの低レベル実装 (詳細については、ファイル内のコメントを参照してください)。 database.rs
によって使用されます。src/hydra.rs
: バイナリ キャッシュからのダウンロードに関連するすべての処理 (ファイル リストと参照の取得)src/nixpkgs.rs
: nix-env
を使用したパッケージ (ストアパスと属性) の収集を実装します。src/package.rs
: ストア パスを表す高レベルのデータ型 (パッケージとも呼ばれる)src/workset.rs
: 再帰的フェッチ (すべての参照をフェッチ) を実装するためにnix-index
によって使用されるキュー