Skip to content

srid/devour-flake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

devour-flake

Devour all outputs in a flake.

Why?

Running nix build .#a .#b ... .#z on a flake with that many outputs can be rather slow if the evaluation of those packages are non-trivial, as is often the case when using IFD. Nix evaluates separately for each of the argument (as if not using the eval cache).

To workaround this, we create a "consumer" flake that will depend on all outputs in the given input flake, and then run nix build on the consumer flake, which will then evaluate the input flake's packages only once.

devour-flake currently detects the following flake outputs:

Type Output Key
Standard flake outputs packages, apps, checks, devShells
NixOS nixosConfigurations.*
nix-darwin darwinConfigurations.*
home-manager legacyPackages.${system}.homeConfigurations.*

Usage

To build all of the nammayatri flake outputs for example:

nix build github:srid/devour-flake \
  -L --no-link --print-out-paths \
  --override-input flake github:nammayatri/nammayatri

Pipe this to | cachix push <name> to push all flake outputs to cachix!

Nix app

Add this repo as a non-flake input:

{
  inputs = {
    devour-flake.url = "github:srid/devour-flake";
    devour-flake.flake = false;
  };
}

Then, add an overlay entry to your nixpkgs:

{
  devour-flake = self.callPackage inputs.devour-flake { };
}

Use pkgs.devour-flake to get a convenient executable that will devour the given flake and spit out the out paths. You can then use this in CI to build all outputs of a flake.

nix-build-all

Note

See also: nixci, an improved version of nix-build-all.

For a CI-friendly command that builds all flake outputs, in addition to checking for flake.lock consistency, use:

{ pkgs, ... }:

pkgs.writeShellApplication {
  name = "nix-build-all";
  runtimeInputs = [
    pkgs.nix
    pkgs.devour-flake
  ];
  text = ''
    # Make sure that flake.lock is sync
    nix flake lock --no-update-lock-file

    # Do a full nix build (all outputs)
    # This uses https://github.com/srid/devour-flake
    devour-flake . "$@"
  '';
}

Who uses it