To figure out why a repo is failing to build I'd like to enumerate all the available attributes in the source. That is, list every ATTR
which fits into nix-build --attr ATTR https://github.com/USER/REPO/tarball/X.Y.Z
.
1 Answers
You can use various tools depending on your use case and format.
If you are looking for packages in a flake repository you can do:
$ 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.
…
You can also list the attributes in an arbitrary file like:
$ cat demo.nix
{
myAttr = 42;
myOtherAttr = "hello";
}
by calling attrNames
to extract the names of the attributes of an imported file:
$ nix eval --impure --expr "let pkgs = import <nixpkgs> {}; in pkgs.lib.attrNames (import ./demo.nix)"
[ "myAttr" "myOtherAttr" ]
If you locally copy/extract the tarball you gave and run this:
$ 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" ]
you will see that in your case default.nix
directly outputs a single derivation (the garbage you see are just the content of the derivation) and not a set of derivations. If you actually read the source of the file you see that it indeed outputs flake.defaultNix.defaultPackage.${system}
. This way you should call nix-build
without any attribute like nix-build https://github.com/kamadorueda/alejandra/tarball/3.0.0
.
That being said, I'm not sure how you run/install this software but in my case (with flake enabled) I can just run:
$ 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.
at it works… So I guess the issue is not with the library but with the way you install it.

- 4,041
- 4
- 23
- 35