Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions source/continuous-integration-setup/hydra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,48 @@ Hydra

.. source https://github.com/tbenst/nix-data-hydra/pull/2/files#diff-3367727976c111f36e7d3210944788ba

You'll need to deploy all build machines with a `post build hook <https://nixos.org/manual/nix/stable/advanced-topics/post-build-hook.html>`_.
There are two options for pushing data to cachix after builds: Configure Hydra with a static or dynamic [`RunCommand`](https://github.com/NixOS/hydra/blob/master/doc/manual/src/plugins/RunCommand.md) script, or configure a global `post-build-hook` in Nix.

Either way, you need to create binary cache on https://app.cachix.org and generate a auth token and/or signing key. Then, 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"
}
]
}


RunCommand
----------

Add the following to your hydra configuration (assuming Hydra is configured with the NixOS module):

.. code:: nix

services.hydra.extraConfig = ''
<runcommand>
job = home:mybuild:*
command = ${pkgs.writeShellApplication {
name = "upload-to-cachix";
runtimeInputs = [pkgs.jq pkgs.cachix];
text = ''
set -xeu
jq -r '.outputs[].path' "$HYDRA_JSON" | xargs cachix --config ${config.age.secrets.hydra-ci.path} push mycache

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to specify here how to create the config, and mention it's advised to use some secrets manager like age.

'';
}}/bin/upload-to-cachix
</runcommand>
''

1. Create new binary cache on https://app.cachix.org and generate a signing key
This script runs after every Hydra build job.

2. Assuming Hydra is deployed with NixOS, here's a NixOS module to configure Cachix:
post-build-hook
---------------

You'll need to deploy all build machines with a `post build hook <https://nixos.org/manual/nix/stable/advanced-topics/post-build-hook.html>`_.

Assuming Hydra is deployed with NixOS, here's a NixOS module to configure Cachix:

.. code:: nix

Expand Down Expand Up @@ -35,14 +72,3 @@ You'll need to deploy all build machines with a `post build hook <https://nixos.
'';
}

3. 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"
}
]
}

4. Replace ``mycache`` in above files with name of your new binary cache