{ final, prev, sources, ... }:
let
  deps = with final.perlPackages; [NetDNS NetServer IOMultiplex NetAddrIP NetCIDRLite DigestMD5 TimeHiRes Storable];
in {
  postfwd = prev.stdenv.mkDerivation rec {
    inherit (sources.postfwd) pname version src;

    nativeBuildInputs = with prev; [ makeWrapper ];
    propagatedBuildInputs = [final.perlPackages.perl] ++ deps;

    buildPhase = ''
      runHook preBuild

      substituteInPlace sbin/postfwd3 \
        --replace "/usr/bin/perl -T" "/usr/bin/perl"

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      mkdir -p $out/bin
      cp -t $out/bin sbin/postfwd3

      wrapProgram $out/bin/postfwd3 \
        --prefix PERL5LIB : ${final.perlPackages.makePerlPath deps}

      runHook postInstall
    '';
  };
}