Hydra

You’ll need to deploy all build machines with a post build hook.

  1. Create new binary cache on https://app.cachix.org and generate a signing key

  2. Assuming Hydra is deployed with NixOS, here’s a NixOS module to configure Cachix:

{ pkgs, config }:

let
  upload_to_cachix = pkgs.writeScriptBin "upload-to-cachix" ''
    #!/bin/sh
    set -eu
    set -f # disable globbing

    # skip push if the declarative job spec
    OUT_END=$(echo ''${OUT_PATHS: -10})
    if [ "$OUT_END" == "-spec.json" ]; then
    exit 0
    fi

    export HOME=/root
    exec ${pkgs.cachix}/bin/cachix -c /etc/cachix/cachix.dhall push mycache $OUT_PATHS > /tmp/hydra_cachix 2>&1
  '';
in {
  nix.extraOptions = ''
    builders-use-substitutes = true
    post-build-hook = ${upload_to_cachix}/bin/upload-to-cachix
  '';
}
  1. Make sure to create a secret file /etc/cachix/cachix.dhall on all machines with the following contents:

    { authToken = "XXX" -- this one is needed only for private caches
    , binaryCaches =
        [ { name = "mycache"
          , secretKey = "XXX-SIGNING_KEY"
          }
        ]
    }
    
  2. Replace mycache in above files with name of your new binary cache