From NixOS Wiki
Jump to: navigation, search

NixOS comes with a module to run buildkite agents:

  services.buildkite-agents.builder = {
    enable = true;
    # store a token provided in the  buildkite webinterface in the `Agents` tab under `Agents token`
    tokenPath = "/path/to/token";
    privateSshKeyPath = "/path/to/ssh/key";
  # tools needed for basic nix-build
  runtimePackages = [

Further NixOS options

Using buildkite for public repository

Since buildkite executes code there are some additional security measures to take care of in order to run buildkite on your own infrastructure.

It is recommend to run the buildkit-agent in a sandbox. In the following example, we use the confinement option to run in a chroot where only the nix store is mounted. The nix daemon socket is than bind mounted into the chroot. Make sure that you don't add secrets to your nix store!

{ pkgs, config, ... }:
  # Replace the suffix `<name>` by the name used in `services.buildkite-agents.<name> `<name> = {
    confinement.enable = true;
    confinement.packages =<name>.runtimePackages;
    serviceConfig = {
      BindReadOnlyPaths = [<name>.tokenPath<name>.privateSshKeyPath
        # channels are dynamic paths in the nix store, therefore we need to bind mount the whole thing
      BindPaths = [<name>.dataDir

Since pull requests can modify the build instructions it is recommend to move .buildkite/pipeline.yml from the repository itself and only provide it via the web interface. Also consider using restrict-eval options to prevent leaking the buildkite's ssh key and api token, since those are still mounted into the chroot.

See also