{ stdenvNoCC
, lib
, fetchurl
, jdk8
, makeWrapper
}:

let
  jdk = jdk8;
in
stdenvNoCC.mkDerivation rec {
  pname = "rundeck";
  version = "3.4.9-20211221";

  src = fetchurl {
    url = "https://packagecloud.io/pagerduty/rundeck/packages/java/org.rundeck/rundeck-${version}.war/artifacts/rundeck-${version}.war/download";
    hash = "sha256-HwXPDmjAIc825ZFxteTOfimQmK2DdhAHA0H4UYisgFw=";
  };
  dontUnpack = true;

  nativeBuildInputs = [ makeWrapper ];
  buildInputs = [ jdk ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/share $out/bin
    install -D $src $out/share/rundeck.war

    makeWrapper ${jdk}/bin/java \
      $out/bin/rundeckd --add-flags "-jar $out/share/rundeck.war"

    runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://rundeck.com";
    description = "Runbook automation";
    platforms = platforms.unix;
    license = licenses.asl20;
  };
}