# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0

{ pkgs, depot, ... }:
let
  version = "hpd-0.5.0";
  newSrc = pkgs.fetchhg {
    url = "https://mirror.octobus.net/heptapod/heptapod-runner";
    rev = "5843be69a387";
    sha256 = "sha256:15iyz7rgi6rb4nf1rjd96lsgdxn2l1ivzh05my7c9zpzvl7cnw25";
  };
in
{
  heptapod-runner = pkgs.buildGoModule rec {
    pname = "heptapod-runner";
    inherit version;

    commonPackagePath = "gitlab.com/gitlab-org/gitlab-runner/common";
    ldflags = [
      "-X ${commonPackagePath}.NAME=heptapod-runner"
      "-X ${commonPackagePath}.VERSION=${version}"
      "-X ${commonPackagePath}.REVISION=v${version}"
    ];

    src = newSrc;
    vendorSha256 = null;

    patches = [ ./fix-shell-path.patch ];

    doCheck = false;
  };
  heptapod-runner-mercurial = pkgs.symlinkJoin {
    name = pkgs.mercurial.name;
    paths = [ pkgs.mercurial ];
    postBuild = ''
      mkdir -p "$out/etc/mercurial"
      cp "${newSrc}/dockerfiles/runner-helper/runner.hgrc" "$out/etc/mercurial/hgrc"
    '';
  };
}