Nix-build a set of sets of derivations


nix-build -A foo
  • If foo evaluates to a derivation, it builds that derivation
  • If foo evaluates to a set of derivations, it builds all these derivations
  • If foo evaluates to a set of set of derivations, it builds … nothing

This seems a bit unfortunate if my project consists of many derivations which I may want to build all nix-build or some nix-build -A some.of.them.

Is there a good solution to that? Can I somehow mark a set of derivations so that nix-build (or rather, nix-instantiate) recurses into it?

Reading the code I see that

                /* If the value of this attribute is itself a set,
                   should we recurse into it?  => Only if it has a
                   `recurseForDerivations = true' attribute. */

This special attribute does not seem to be documented in the nix manual… let’s see if it works…

Yup, seems to work. TIL! Guess this can be recagorized as a howto… :slight_smile:

Although this solution has the downside of confusing hydra :-/

in job ‘tests.recurseForDerivations’:
error: --- TypeError --- hydra-eval-jobs
attribute 'tests.recurseForDerivations' is a Boolean, which is not supported

I think recurseIntoAttrs may be closer to what you want

This one?

  recurseIntoAttrs =
    attrs: attrs // { recurseForDerivations = true; };

looks it’s wrapping the same concept (and I am actually not convinced it it helpful to have have the same concept available both as an attributed and a similarly named function … more cognitive load, as people need to know about the attribute and recognize what the function does when they see it. At least recurseForDerivations is documentd in the nixpkg manual…

Hydra doesn’t understand that, yeah. What pkgs/top-level/release.nix does is, as far as I know, convert all recurseForDerivation attributes to empty sets when generating the set of jobs which are then just ignored by Hydra. Unfortunately this nix expression is pretty convoluted and I can’t point you to the exact location where this is done on the spot.

Indeed. I have since used the following simpel function to make the job set hydra-friendly:

  removeRecurseForDerivations = nixpkgs.lib.filterAttrsRecursive (k: v: k != "recurseForDerivations");