如何在 Nixpkgs 中搜索包表达式?
How can I search in Nixpkgs for a package expression?
来自手册:
Components are installed from a set of Nix expressions that tell Nix
how to build those packages, including, if necessary, their
dependencies. There is a collection of Nix expressions called the
Nixpkgs package collection that contains packages ranging from basic
development stuff such as GCC and Glibc, to end-user applications like
Mozilla Firefox.
假设我想搜索 Go 包的 nix 表达式。我应该在 repository 的什么地方找到正确的文件?
我选择的工具是nix repl
。通常它的制表符完成足以找到属性名称。有时您可能想使用 https://search.nixos.org/packages.
为了方便的工作流程,您可以设置 EDITOR
并在 nix repl
中使用 :edit
命令。通常我在 VSCode 中打开 nixpkgs,然后在 VSCode 终端中打开 运行 nix repl .
,这样我也可以按住 Ctrl 并单击文件位置。
我从不使用目录结构,因为搜索起来方便多了。
[~/nixpkgs]$ export EDITOR=... # nano doesn't seem to work for this
[~/nixpkgs]$ nix repl .
nix-repl> :edit go
或
nix-repl> go.meta.position
"~/nixpkgs/pkgs/development/compilers/go/1.17.nix:278"
这通常会为您提供 mkDerivation
调用或类似函数调用的位置。
要获取定义属性的位置,请使用
nix-repl> builtins.unsafeGetAttrPos "go" pkgs
{ column = 3; file = "~/nixpkgs/pkgs/top-level/all-packages.nix"; line = 12753; }
然后是递归目录搜索选项(如 grep -R
、IDE-integrated 搜索等)。这通常非常有效,因为包名称往往是特定的。可惜 go
不是。我们通常不会在 Nix 中进行疯狂的代码格式化,前导 space 和等号在查找定义方面做得很好,即使对于 go
,如果您忽略 lib/
中的定义].
[~/nixpkgs]$ git grep -n ' go ='
lib/attrsets.nix:125: go = prefixLength: hasValue: value: updates:
lib/debug.nix:234: go = x: generators.toPretty
lib/deprecated.nix:92: let go = xs: acc:
lib/filesystem.nix:29: let go = path:
lib/generators.nix:237: go = indent: v: with builtins;
lib/trivial.nix:500: go = i:
nixos/modules/security/apparmor/includes.nix:9: let go = { path ? null, mode ? "r", trail ? "" }:
pkgs/stdenv/booter.nix:63: go = pred: n:
pkgs/top-level/all-packages.nix:12753: go = go_1_17;
pkgs/top-level/all-packages.nix:21043: go = buildPackages.go_1_16;
pkgs/top-level/all-packages.nix:21046: go = buildPackages.go_1_17;
pkgs/top-level/all-packages.nix:21049: go = buildPackages.go_1_18;
pkgs/top-level/all-packages.nix:21055: go = buildPackages.go_1_16;
pkgs/top-level/all-packages.nix:21058: go = buildPackages.go_1_17;
pkgs/top-level/all-packages.nix:21061: go = buildPackages.go_1_18;
pkgs/top-level/all-packages.nix:26493: go = go_1_16;
来自手册:
Components are installed from a set of Nix expressions that tell Nix how to build those packages, including, if necessary, their dependencies. There is a collection of Nix expressions called the Nixpkgs package collection that contains packages ranging from basic development stuff such as GCC and Glibc, to end-user applications like Mozilla Firefox.
假设我想搜索 Go 包的 nix 表达式。我应该在 repository 的什么地方找到正确的文件?
我选择的工具是nix repl
。通常它的制表符完成足以找到属性名称。有时您可能想使用 https://search.nixos.org/packages.
为了方便的工作流程,您可以设置 EDITOR
并在 nix repl
中使用 :edit
命令。通常我在 VSCode 中打开 nixpkgs,然后在 VSCode 终端中打开 运行 nix repl .
,这样我也可以按住 Ctrl 并单击文件位置。
我从不使用目录结构,因为搜索起来方便多了。
[~/nixpkgs]$ export EDITOR=... # nano doesn't seem to work for this
[~/nixpkgs]$ nix repl .
nix-repl> :edit go
或
nix-repl> go.meta.position
"~/nixpkgs/pkgs/development/compilers/go/1.17.nix:278"
这通常会为您提供 mkDerivation
调用或类似函数调用的位置。
要获取定义属性的位置,请使用
nix-repl> builtins.unsafeGetAttrPos "go" pkgs
{ column = 3; file = "~/nixpkgs/pkgs/top-level/all-packages.nix"; line = 12753; }
然后是递归目录搜索选项(如 grep -R
、IDE-integrated 搜索等)。这通常非常有效,因为包名称往往是特定的。可惜 go
不是。我们通常不会在 Nix 中进行疯狂的代码格式化,前导 space 和等号在查找定义方面做得很好,即使对于 go
,如果您忽略 lib/
中的定义].
[~/nixpkgs]$ git grep -n ' go ='
lib/attrsets.nix:125: go = prefixLength: hasValue: value: updates:
lib/debug.nix:234: go = x: generators.toPretty
lib/deprecated.nix:92: let go = xs: acc:
lib/filesystem.nix:29: let go = path:
lib/generators.nix:237: go = indent: v: with builtins;
lib/trivial.nix:500: go = i:
nixos/modules/security/apparmor/includes.nix:9: let go = { path ? null, mode ? "r", trail ? "" }:
pkgs/stdenv/booter.nix:63: go = pred: n:
pkgs/top-level/all-packages.nix:12753: go = go_1_17;
pkgs/top-level/all-packages.nix:21043: go = buildPackages.go_1_16;
pkgs/top-level/all-packages.nix:21046: go = buildPackages.go_1_17;
pkgs/top-level/all-packages.nix:21049: go = buildPackages.go_1_18;
pkgs/top-level/all-packages.nix:21055: go = buildPackages.go_1_16;
pkgs/top-level/all-packages.nix:21058: go = buildPackages.go_1_17;
pkgs/top-level/all-packages.nix:21061: go = buildPackages.go_1_18;
pkgs/top-level/all-packages.nix:26493: go = go_1_16;