How to run Hydra from its flake?

The official instructions for installing and running Hydra just turn on the NixOS service that is bundled with nixpkgs:

However, this results in a version from last August, so not only pretty old, but also not well suited to hacking on.

The Hydra repo contains a flake file, but it is super, super non-obvious how to actually deploy the bleeding edge flake version of Hydra, since it seems you need ~3 pieces to all be in sync together: the NixOS module, the hydra-supplying overlay, and the services config itself. Stumbling mostly in the dark, I made it to the following setup, with a flake.nix like so:

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nix.url = "github:NixOS/nix/2.7.0";
    hydra.url = "github:NixOS/hydra/master";
  outputs = { self, nix, nixpkgs, hydra }: {
    nixosConfigurations.<hostname> = let
      system = "x86_64-linux";
    in nixpkgs.lib.nixosSystem {
      inherit system;
      modules = [
        ({ ... }: { nixpkgs.overlays = [ hydra.overlay ]; })

And then the important/relevant part of the configuration.nix:

{ config, pkgs, lib, ... }:
  services.hydra = {
    enable = true;
    hydraURL = "";
    notificationSender = "hydra@localhost";
    buildMachinesFiles = [];
    useSubstitutes = true;
    package = pkgs.hydra;

It weirded me out that I needed to apply the overlay and that it wasn’t enough to just specify the module and package. It was also strange to me that even after applying the overlay, it was still necessary to specify package = pkgs.hydra in the service config (without that, it would error out trying to build what was clearly the much older source that’s currently in nixpkgs.

Finally, even after I seemingly had all of that stuff working, I was running into a conflict with my bog-standard nix-serve configuration, which when enabled would give:

error: attribute 'platforms' missing

       at /nix/store/h96rpxzp4q192r3fnwzclg3rmdg4nlqk-source/pkgs/tools/package-management/nix-serve/default.nix:50:17:

           49|     license = licenses.lgpl21;
           50|     platforms = nix.meta.platforms;
             |                 ^
           51|   };
(use '--show-trace' to show detailed location information)

So partly I’m sharing all this for any future travelers wondering how to do a NixOS/Hydra system flake setup, and partly I’m sharing for a sanity check on whether there are any obvious problems or redundancies with the above, and partly because I’d like to resolve the issue with nix-serve.


1 Like

Not sure if it’s the best way, but I did this for my server: Enable hydra again · jonringer/server-configuration@a8faeae · GitHub

Thank you for posting this example. I was mystified at how to introduce the flake version of Hydra into my NixOS setup but I followed your example and it seems to have worked great.