{ pkgs, ... }:

let
  bl465c = pkgs.fetchurl {
    url = "https://downloads.hpe.com/pub/softlib2/software1/sc-linux-fw-sys/p361457557/v150912/RPMS/i386/firmware-system-a19-2018.03.14-1.1.i386.rpm";
    hash = "sha256:0h3i5jbqc40sxysq20l3ky0vxbn28avhm6fh6bv3bmar4lx1azcm";
  };
in
pkgs.runCommandNoCC "hp-rom" {
  inherit bl465c;

  nativeBuildInputs = [
    pkgs.libarchive
  ];
} ''
  mkdir $out
  mkdir $out/share $out/bin

  mkdir tmp
  pushd tmp
  bsdtar xvf $bl465c
  mv ./usr/lib/i386-linux-gnu/firmware-system-a19-2018.03.14-1.1 $out/share/bl465c
  substituteInPlace $out/share/bl465c/hpsetup \
    --replace "InitLog()" "InitLog() { :; }; InitLogOLD()" \
    --replace "EndLog()" "EndLog() { :; }; EndLogOLD()" \
    --replace 'EXEDIR=$(dirname $0)' "EXEDIR=$out/share/bl465c"
  patchShebangs $out/share/bl465c/hpsetup
  ln -s ../share/bl465c/hpsetup $out/bin/bl465c-rompaq
  popd
''