{
  lib,
  stdenv,
  fetchFromGitHub,
  autoreconfHook,
  flex,
  fcgi,
  libxml2,
  postgresql,
}:

stdenv.mkDerivation rec {
  pname = "tinyows";
  version = "1.2.0";

  src = fetchFromGitHub {
    owner = "MapServer";
    repo = "tinyows";
    rev = "v${version}";
    hash = "sha256-6s+zKR2rLb1f9NaS9i6Gky2sOD1NdBzNe1GTP20+RTE=";
  };

  buildInputs = [
    fcgi
    libxml2
    (postgresql.withPackages (ps: with ps; [ postgis ]))
  ];

  nativeBuildInputs = [
    autoreconfHook
    flex
  ];

  installPhase = ''
    runHook preInstall
    make install
    install -D -m 0755 tinyows $out/bin/tinyows
    runHook postInstall
  '';

  meta = with lib; {
    description = "Source code of the TinyOWS project. Please submit pull requests to the 'main' branch";
    homepage = "https://github.com/MapServer/tinyows";
    changelog = "https://github.com/MapServer/tinyows/blob/${src.rev}/NEWS";
    license = licenses.mit;
    mainProgram = "tinyows";
    platforms = platforms.all;
  };
}