nix index
v0.1.8
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”脚本,可以为您打印 shell 中未找到命令的属性路径。您可以在您自己的 shell 初始化文件中获取${pkgs.nix-index}/etc/command-not-found.sh
(据我们所知,适用于 ZSH 和 Bash),或者您可以在 home 中使用以下内容 -经理/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 ...
现在可以使用home-manager
模块使用此脚本将nix-index
与bash
、 zsh
和fish
集成。
如果您发现任何想要实现的缺失功能,我对任何 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
用于实现递归获取的队列(获取所有内容的引用)