![如何打印 Nix 表达式的所有可用属性](https://linux22.com/image/212014/%E5%A6%82%E4%BD%95%E6%89%93%E5%8D%B0%20Nix%20%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E6%89%80%E6%9C%89%E5%8F%AF%E7%94%A8%E5%B1%9E%E6%80%A7.png)
找出原因回购协议无法构建我想枚举源中所有可用的属性。也就是说,列出所有ATTR
适合 的内容nix-build --attr ATTR https://github.com/USER/REPO/tarball/X.Y.Z
。
答案1
您可以根据您的用例和格式使用各种工具。
如果您正在 flake 存储库中查找包,您可以执行以下操作:
$ nix search github:kamadorueda/alejandra/3.0.0
* packages.x86_64-linux.alejandra-aarch64-unknown-linux-musl (3.0.0+20220814.ef03f7e)
The Uncompromising Nix Code Formatter.
…
您还可以列出任意文件中的属性,例如:
$ cat demo.nix
{
myAttr = 42;
myOtherAttr = "hello";
}
通过调用attrNames
提取导入文件的属性名称:
$ nix eval --impure --expr "let pkgs = import <nixpkgs> {}; in pkgs.lib.attrNames (import ./demo.nix)"
[ "myAttr" "myOtherAttr" ]
如果您在本地复制/提取您提供的 tarball 并运行以下命令:
$ nix eval --impure --expr "let pkgs = import <nixpkgs> {}; in pkgs.lib.attrNames (import ./default.nix {})"
[ "PKG_CONFIG_ALLOW_CROSS" "__ignoreNulls" "all" "args" "buildAndTestSubdir" "buildInputs" "builder" "cargoBuildFeatures" "cargoBuildNoDefaultFeatures" "cargoBuildType" "cargoCheckFeatures" "cargoCheckNoDefaultFeatures" "cargoCheckType" "cargoDeps" "configureFlags" "configurePhase" "depsBuildBuild" "depsBuildBuildPropagated" "depsBuildTarget" "depsBuildTargetPropagated" "depsHostHost" "depsHostHostPropagated" "depsTargetTarget" "depsTargetTargetPropagated" "doCheck" "doInstallCheck" "drvAttrs" "drvPath" "inputDerivation" "meta" "name" "nativeBuildInputs" "out" "outPath" "outputName" "outputs" "overrideAttrs" "passthru" "patchRegistryDeps" "patches" "pname" "postUnpack" "propagatedBuildInputs" "propagatedNativeBuildInputs" "src" "stdenv" "strictDeps" "system" "tests" "type" "userHook" "version" ]
您将看到,在您的情况下,default.nix
直接输出单个推导(您看到的垃圾只是推导的内容)而不是一组推导。如果您实际阅读该文件的源代码,您会发现它确实输出了flake.defaultNix.defaultPackage.${system}
.这样你应该nix-build
在没有任何属性的情况下调用,例如nix-build https://github.com/kamadorueda/alejandra/tarball/3.0.0
.
话虽这么说,我不确定你如何运行/安装这个软件,但就我而言(启用了薄片)我可以运行:
$ nix run github:kamadorueda/alejandra/3.0.0
Formatting stdin.
Use --help to see all command line options.
use --quiet to suppress this and other messages.
它有效......所以我想问题不在于库,而在于安装它的方式。