NixOS/nix

nix build --all: build all packages in a flake

Opened this issue Β· 17 comments

There's currently no way to build all packages in a flake, a quite common operation that was previously just nix-build.

You can see here people struggling: https://www.reddit.com/r/NixOS/comments/vohopf/is_there_an_easy_way_to_build_all_the_packages_of/

A possible workaround is to add all packages as "checks" and then "nix flake check" will build all.

There is also a workaround using symlinkJoin and defining an all default package. You can find an example of this in this article in the section titled "The Flake"

just ran into the same issue.
what if we could just add the --all feature to flakes which builds all packages as expected?

just ran into the same issue.
what if we could just add the --all feature to flakes which builds all packages as expected?

That's what I assumed already existed, at least.

Or, when no default package is set, that "nix build" would build everything.

What should be the output of --all? For instance, should it result in a bunch of result-{1,2,3,4,5} symlinks?

What should be the output of --all? For instance, should it result in a bunch of result-{1,2,3,4,5} symlinks?

Good question. I guess this would clutter your workspace on larger package sets.
Iβ€˜d like a folder in the nix store which holds a list of symlinks to every single package

So it'll basically implicitly create a new derivation using --all?

linkFarm [
  { name = "packagea"; path = packages.${system}.packagea }
  { name = "packageb"; path = packages.${system}.packageb }
  { name = "packageb"; path = packages.${system}.packageb }
]

Resulting in a result symlink:

result/packagea -> /nix/store/...-packagea/
result/packageb -> /nix/store/...-packageb/
result/packagec -> /nix/store/...-packagec/

I'm not sure I like the approach, as it is non-transparent if Nix is going to build derivations implicitly.

It could also be a convention or even a default to make packages.${system}.default or packages.${system}.all use the linkFarm approach. If it was a convention, a helper function that creates a 'package set' derivation would be useful.

Then it would work without needing a --all option.

I don't like it, shouldn't have to depend on nixpkgs in my opinion. Moreover derivations can have multiple outputs (can't remember how nix build manages it currently, not even sure it does).

What do you think is the better approach to solve the issue?

shouldn't have to depend on nixpkgs in my opinion

There could also be a builtin for creating a 'package set', but I would agree is it's not ideal.

Moreover derivations can have multiple outputs

Indeed, that's why I thought earlier that it would output result-{1,2,3,4,5}.

Would it output result-{packagea,packageb,packagec} instead?

I meant multiple outputs per single derivation, so something like result-{drvName}-{outputName}.

This seems to be a duplicate of #3811, though I would vote to close the older issue, as there is more discussion in this thread here.

The gist of #3811 is that the behavior of nix build --all is not intuitively well-defined, as a flake can have any number of outputs, of which only some are known.

For example, the nix repo itself has all these outputs:

There's a lot, click here to expand...
$ nix flake show
git+file:///Users/feuh/repos/nix
β”œβ”€β”€β”€checks
β”‚   β”œβ”€β”€β”€aarch64-darwin
β”‚   β”‚   β”œβ”€β”€β”€binaryTarball: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€installTests: derivation 'install-tests'
β”‚   β”‚   β”œβ”€β”€β”€nixpkgsLibTests: derivation 'nixpkgs-lib-tests'
β”‚   β”‚   β”œβ”€β”€β”€perlBindings: derivation 'nix-perl-2.21.0pre20240305_dirty'
β”‚   β”‚   └───rl-next: derivation 'test-rl-next-release-notes'
β”‚   β”œβ”€β”€β”€aarch64-linux
β”‚   β”‚   β”œβ”€β”€β”€binaryTarball omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€dockerImage omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€installTests omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€nixpkgsLibTests omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€perlBindings omitted (use '--all-systems' to show)
β”‚   β”‚   └───rl-next omitted (use '--all-systems' to show)
β”‚   β”œβ”€β”€β”€i686-linux
β”‚   β”‚   β”œβ”€β”€β”€binaryTarball omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€installTests omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€nixpkgsLibTests omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€perlBindings omitted (use '--all-systems' to show)
β”‚   β”‚   └───rl-next omitted (use '--all-systems' to show)
β”‚   β”œβ”€β”€β”€x86_64-darwin
β”‚   β”‚   β”œβ”€β”€β”€binaryTarball omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€installTests omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€nixpkgsLibTests omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€perlBindings omitted (use '--all-systems' to show)
β”‚   β”‚   └───rl-next omitted (use '--all-systems' to show)
β”‚   └───x86_64-linux
β”‚       β”œβ”€β”€β”€binaryTarball omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€dockerImage omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€installTests omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€nixpkgsLibTests omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€perlBindings omitted (use '--all-systems' to show)
β”‚       └───rl-next omitted (use '--all-systems' to show)
β”œβ”€β”€β”€devShells
β”‚   β”œβ”€β”€β”€aarch64-darwin
β”‚   β”‚   β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf: development environment 'nix-armv6l-unknown-linux-gnueabihf-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf: development environment 'nix-armv7l-unknown-linux-gnueabihf-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€default: development environment 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€native-ccacheStdenvPackages: development environment 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€native-clangStdenvPackages: development environment 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€native-gccStdenvPackages: development environment 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€native-libcxxStdenvPackages: development environment 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€native-stdenvPackages: development environment 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-freebsd13: development environment 'nix-x86_64-unknown-freebsd13-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-netbsd: development environment 'nix-x86_64-unknown-netbsd-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-w64-mingw32: development environment 'nix-x86_64-w64-mingw32-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€aarch64-linux
β”‚   β”‚   β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-stdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-stdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-netbsd omitted (use '--all-systems' to show)
β”‚   β”‚   └───x86_64-w64-mingw32 omitted (use '--all-systems' to show)
β”‚   β”œβ”€β”€β”€i686-linux
β”‚   β”‚   β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-stdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€static-stdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-netbsd omitted (use '--all-systems' to show)
β”‚   β”‚   └───x86_64-w64-mingw32 omitted (use '--all-systems' to show)
β”‚   β”œβ”€β”€β”€x86_64-darwin
β”‚   β”‚   β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€native-stdenvPackages omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-netbsd omitted (use '--all-systems' to show)
β”‚   β”‚   └───x86_64-w64-mingw32 omitted (use '--all-systems' to show)
β”‚   └───x86_64-linux
β”‚       β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€native-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€native-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€native-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€native-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€native-stdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€static-ccacheStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€static-clangStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€static-gccStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€static-libcxxStdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€static-stdenvPackages omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
β”‚       β”œβ”€β”€β”€x86_64-unknown-netbsd omitted (use '--all-systems' to show)
β”‚       └───x86_64-w64-mingw32 omitted (use '--all-systems' to show)
β”œβ”€β”€β”€hydraJobs
β”‚   β”œβ”€β”€β”€binaryTarball
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€binaryTarballCross
β”‚   β”‚   └───x86_64-linux
β”‚   β”‚       β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚       β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚       β”œβ”€β”€β”€x86_64-unknown-freebsd13: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚       └───x86_64-unknown-netbsd: derivation 'nix-binary-tarball-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€build
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€buildCross
β”‚   β”‚   β”œβ”€β”€β”€armv6l-unknown-linux-gnueabihf
β”‚   β”‚   β”‚   └───x86_64-linux: derivation 'nix-armv6l-unknown-linux-gnueabihf-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€armv7l-unknown-linux-gnueabihf
β”‚   β”‚   β”‚   └───x86_64-linux: derivation 'nix-armv7l-unknown-linux-gnueabihf-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-unknown-freebsd13
β”‚   β”‚   β”‚   └───x86_64-linux: derivation 'nix-x86_64-unknown-freebsd13-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-unknown-netbsd
β”‚   β”‚       └───x86_64-linux: derivation 'nix-x86_64-unknown-netbsd-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€buildNoGc
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€buildNoTests
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€buildReadlineNoMarkdown
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€buildStatic
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-static-aarch64-unknown-linux-musl-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-static-x86_64-unknown-linux-musl-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€coverage: derivation 'nix-coverage'
β”‚   β”œβ”€β”€β”€dockerImage
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'docker-image-tarball-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'docker-image-tarball-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€installTests
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'install-tests'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'install-tests'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'install-tests'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'install-tests'
β”‚   β”‚   └───x86_64-linux: derivation 'install-tests'
β”‚   β”œβ”€β”€β”€installerScript: derivation 'installer-script'
β”‚   β”œβ”€β”€β”€installerScriptForGHA: derivation 'installer-script'
β”‚   β”œβ”€β”€β”€installerTests
β”‚   β”‚   β”œβ”€β”€β”€fedora-36
β”‚   β”‚   β”‚   └───x86_64-linux
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-default: derivation 'installer-test-fedora-36-install-default'
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-force-daemon: derivation 'installer-test-fedora-36-install-force-daemon'
β”‚   β”‚   β”‚       └───install-force-no-daemon: derivation 'installer-test-fedora-36-install-force-no-daemon'
β”‚   β”‚   β”œβ”€β”€β”€rhel-7
β”‚   β”‚   β”‚   └───x86_64-linux
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-default: derivation 'installer-test-rhel-7-install-default'
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-force-daemon: derivation 'installer-test-rhel-7-install-force-daemon'
β”‚   β”‚   β”‚       └───install-force-no-daemon: derivation 'installer-test-rhel-7-install-force-no-daemon'
β”‚   β”‚   β”œβ”€β”€β”€rhel-8
β”‚   β”‚   β”‚   └───x86_64-linux
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-default: derivation 'installer-test-rhel-8-install-default'
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-force-daemon: derivation 'installer-test-rhel-8-install-force-daemon'
β”‚   β”‚   β”‚       └───install-force-no-daemon: derivation 'installer-test-rhel-8-install-force-no-daemon'
β”‚   β”‚   β”œβ”€β”€β”€rhel-9
β”‚   β”‚   β”‚   └───x86_64-linux
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-default: derivation 'installer-test-rhel-9-install-default'
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-force-daemon: derivation 'installer-test-rhel-9-install-force-daemon'
β”‚   β”‚   β”‚       └───install-force-no-daemon: derivation 'installer-test-rhel-9-install-force-no-daemon'
β”‚   β”‚   β”œβ”€β”€β”€ubuntu-16-04
β”‚   β”‚   β”‚   └───x86_64-linux
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-default: derivation 'installer-test-ubuntu-16-04-install-default'
β”‚   β”‚   β”‚       β”œβ”€β”€β”€install-force-daemon: derivation 'installer-test-ubuntu-16-04-install-force-daemon'
β”‚   β”‚   β”‚       └───install-force-no-daemon: derivation 'installer-test-ubuntu-16-04-install-force-no-daemon'
β”‚   β”‚   └───ubuntu-22-04
β”‚   β”‚       └───x86_64-linux
β”‚   β”‚           β”œβ”€β”€β”€install-default: derivation 'installer-test-ubuntu-22-04-install-default'
β”‚   β”‚           β”œβ”€β”€β”€install-force-daemon: derivation 'installer-test-ubuntu-22-04-install-force-daemon'
β”‚   β”‚           └───install-force-no-daemon: derivation 'installer-test-ubuntu-22-04-install-force-no-daemon'
β”‚   β”œβ”€β”€β”€internal-api-docs: derivation 'nix-2.21.0'
β”‚   β”œβ”€β”€β”€metrics
β”‚   β”‚   └───nixpkgs: derivation 'nixpkgs-metrics'
β”‚   β”œβ”€β”€β”€perlBindings
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-perl-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-perl-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-perl-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-perl-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-perl-2.21.0pre20240305_dirty'
β”‚   β”œβ”€β”€β”€shellInputs
β”‚   β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   β”‚   └───x86_64-linux: derivation 'nix-2.21.0pre20240305_dirty'
β”‚   └───tests
β”‚       β”œβ”€β”€β”€authorization: derivation 'vm-test-run-authorization'
β”‚       β”œβ”€β”€β”€containers: derivation 'vm-test-run-containers'
β”‚       β”œβ”€β”€β”€evalNixpkgs: derivation 'eval-nixos'
β”‚       β”œβ”€β”€β”€fetch-git: derivation 'vm-test-run-fetch-git'
β”‚       β”œβ”€β”€β”€githubFlakes: derivation 'vm-test-run-github-flakes'
β”‚       β”œβ”€β”€β”€nix-copy: derivation 'vm-test-run-nix-copy'
β”‚       β”œβ”€β”€β”€nix-copy-closure: derivation 'vm-test-run-nix-copy-closure'
β”‚       β”œβ”€β”€β”€nixpkgsLibTests
β”‚       β”‚   β”œβ”€β”€β”€aarch64-darwin: derivation 'nixpkgs-lib-tests'
β”‚       β”‚   β”œβ”€β”€β”€aarch64-linux: derivation 'nixpkgs-lib-tests'
β”‚       β”‚   β”œβ”€β”€β”€i686-linux: derivation 'nixpkgs-lib-tests'
β”‚       β”‚   β”œβ”€β”€β”€x86_64-darwin: derivation 'nixpkgs-lib-tests'
β”‚       β”‚   └───x86_64-linux: derivation 'nixpkgs-lib-tests'
β”‚       β”œβ”€β”€β”€nssPreload: derivation 'vm-test-run-nss-preload'
β”‚       β”œβ”€β”€β”€remoteBuilds: derivation 'vm-test-run-remote-builds'
β”‚       β”œβ”€β”€β”€remoteBuildsSshNg: derivation 'vm-test-run-remote-builds-ssh-ng'
β”‚       β”œβ”€β”€β”€remoteBuildsSshNg_remote_2_13: derivation 'vm-test-run-remoteBuildsSshNg_remote_2_13'
β”‚       β”œβ”€β”€β”€remoteBuildsSshNg_remote_2_3: derivation 'vm-test-run-remoteBuildsSshNg_remote_2_3'
β”‚       β”œβ”€β”€β”€remoteBuilds_local_2_13: derivation 'vm-test-run-remoteBuilds_local_2_13'
β”‚       β”œβ”€β”€β”€remoteBuilds_local_2_3: derivation 'vm-test-run-remoteBuilds_local_2_3'
β”‚       β”œβ”€β”€β”€remoteBuilds_remote_2_13: derivation 'vm-test-run-remoteBuilds_remote_2_13'
β”‚       β”œβ”€β”€β”€remoteBuilds_remote_2_3: derivation 'vm-test-run-remoteBuilds_remote_2_3'
β”‚       β”œβ”€β”€β”€setuid
β”‚       β”‚   β”œβ”€β”€β”€i686-linux: derivation 'vm-test-run-setuid'
β”‚       β”‚   └───x86_64-linux: derivation 'vm-test-run-setuid'
β”‚       β”œβ”€β”€β”€sourcehutFlakes: derivation 'vm-test-run-sourcehut-flakes'
β”‚       └───tarballFlakes: derivation 'vm-test-run-tarball-flakes'
β”œβ”€β”€β”€overlays
β”‚   └───default: Nixpkgs overlay
└───packages
    β”œβ”€β”€β”€aarch64-darwin
    β”‚   β”œβ”€β”€β”€changelog-d-nix: package 'changelog-d-0.1-git-f30f696'
    β”‚   β”œβ”€β”€β”€default: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-armv6l-unknown-linux-gnueabihf: package 'nix-armv6l-unknown-linux-gnueabihf-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-armv7l-unknown-linux-gnueabihf: package 'nix-armv7l-unknown-linux-gnueabihf-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-ccacheStdenv: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-clangStdenv: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-gccStdenv: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-libcxxStdenv: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-stdenv: package 'nix-2.21.0pre20240305_dirty'
    β”‚   β”œβ”€β”€β”€nix-x86_64-unknown-freebsd13: package 'nix-x86_64-unknown-freebsd13-2.21.0pre20240305_dirty'
    β”‚   └───nix-x86_64-unknown-netbsd: package 'nix-x86_64-unknown-netbsd-2.21.0pre20240305_dirty'
    β”œβ”€β”€β”€aarch64-linux
    β”‚   β”œβ”€β”€β”€changelog-d-nix omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€dockerImage omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-ccacheStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-clangStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-gccStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-libcxxStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-static omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-stdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
    β”‚   └───nix-x86_64-unknown-netbsd omitted (use '--all-systems' to show)
    β”œβ”€β”€β”€i686-linux
    β”‚   β”œβ”€β”€β”€changelog-d-nix omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-ccacheStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-clangStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-gccStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-libcxxStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-stdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
    β”‚   └───nix-x86_64-unknown-netbsd omitted (use '--all-systems' to show)
    β”œβ”€β”€β”€x86_64-darwin
    β”‚   β”œβ”€β”€β”€changelog-d-nix omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-ccacheStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-clangStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-gccStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-libcxxStdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-stdenv omitted (use '--all-systems' to show)
    β”‚   β”œβ”€β”€β”€nix-x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
    β”‚   └───nix-x86_64-unknown-netbsd omitted (use '--all-systems' to show)
    └───x86_64-linux
        β”œβ”€β”€β”€changelog-d-nix omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€default omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€dockerImage omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-armv6l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-armv7l-unknown-linux-gnueabihf omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-ccacheStdenv omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-clangStdenv omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-gccStdenv omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-libcxxStdenv omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-static omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-stdenv omitted (use '--all-systems' to show)
        β”œβ”€β”€β”€nix-x86_64-unknown-freebsd13 omitted (use '--all-systems' to show)
        └───nix-x86_64-unknown-netbsd omitted (use '--all-systems' to show)

As a summary, these are the categories:

  • checks
  • devShells
  • hydraJobs
  • overlays
  • packages

Many of them are available for five platforms, but some aren't. What should be built when running nix build --all? Would everyone have the same expectation?

As I understand the sentiment of this thread, the general expectation would be for it to build all packages for the current architecture. Potentially, adding the same --all-systems flag that nix flake show already has might be a reasonable addition, as well as allowing --all to be passed multiple times with an optional value that allows building all devShells or any other set of outputs.

$ nix build --all  # Builds all packages
$ nix build --all packages   # Same as above
$ nix build --all packages --all devShells # Build all packages and devShells
$ nix build --all devShells --all-systems # Build all devShells for all systems (requires remote builders)
$ nix build --all --system x86_64-linux --system aarch64-linux # Another flag for selecting specific systems

I think --all-systems would be very niche, though. I guess I can see the use when doing release builds and you indeed have remote builders for all the systems.

A (neat but complex) alternative would be to add more syntax to flakerefs:

$ nix build '.#*'  # * could be any other character, but has precedent

$ nix build '.#packages.aarch64-darwin.*' # Have to type out system tuple
$ nix build '.#packages.$system.*'  # or add special case
$ nix build ".#packages.$(nix system).*" # or additional command and substitute in the shell

$ nix build .#{packages,devShells}.aarch64-darwin."*" # Shell expansion allows more freedom, but also counterintuitive

$ nix build ".#devShells.*.*" # The most niche usecase is the shortest

$ nix build .#packages.{x86_64,aarch64}-{linux,darwin}."*"  # And you can do clever stuff like this

I'd say the latter approach feels very powerful and composable, but the first one is definitely much easier to discover, and probably covers most use-cases already. They don't have to be mutually exclusive, but more features isn't necessarily better.

Another way of solving this could be with nix code, if #5567 ever gets implemented, though that would be far from an intuitive alternative to --all, more of an argument against implementing a syntax extension to flakerefs.

Proposal

I would suggest to start a first implementation with the following behavior:

$ nix build --all
error: --all requires the name of a package set.
       The following package sets are available in the selected flake:
         checks
         packages
         devShells
$ nix build --all packages

For starters, the outputs would be numbered results, that is in line with the current behavior of nix build when multiple derivations are built.

This is obviously a limited and minimally viable solution, but it avoids ambiguity and is relatively easy to implement, which means the feature can be added and maintained with limited effort. It is also easy to extend in the future without breaking backwards compatibility.

In case it helps, I've made this shell function to build and push all flake inputs and outputs for myself:

cashout() {
	set -x
	nix flake archive --json |
		jq -r '.path,(.inputs|to_entries[].value.path)' |
		gopass env "env/$1/cachix_auth_token" cachix push "$1"
	for target in $(
		nix flake show --json --all-systems | jq '
		["checks", "packages", "devShells"] as $tops | 
		$tops[] as $top |
		.[$top] | 
		to_entries[] | 
		.key as $arch | 
		.value | 
		keys[] | 
		"\($top).\($arch).\(.)"
		' | tr -d '"'
	); do
		nix build --json ".#$target" "${@:2}" |
			jq -r '.[].outputs | to_entries[].value' |
			gopass env "env/$1/cachix_auth_token" cachix push "$1"
	done
}

what about recurseIntoAttrs ?

I'm embarrassed to say I don't fully understand how recurseIntoAttrs would be used in this case. Any example would be helpful.

This is an issue with the new nix commands. Thats also why this issue is open in the nix repository and not nixpkgs.

recurseIntoAttrs acts as hand-maintained guide for some tools in nix, where to recurse for automatically discovering packages/derivations. I am not long enough into nix but i think recurseIntoAttrs was invented because it is impossble to use nix itself to recursively evaluate nixpkgs and find all potentially deeply nested packages. So this function evolved into a convention and adds little hints to the expression tree, where to stop/continue with the recursion.

Now this convention was respected by nix itself:

`recurseForDerivations = true' attribute. */

But the problem is that the new command nix build doesn't respect it as before via nix-build.

(Reference to the new build command:

void run(ref<Store> store, Installables && installables) override
)