{ perl, fetchgit, fetchurl, stdenvNoCC, lib, ... }:

with perl.pkgs;

let
  ClassMeasure = buildPerlModule {
    pname = "Class-Measure";
    version = "0.09";
    src = fetchurl {
      url = "mirror://cpan/authors/id/B/BL/BLUEFEET/Class-Measure-0.09.tar.gz";
      sha256 =
        "ee272ee35d05ab6fe94f2ac170943ff29c1a0f9a7362faa44ad92d2521e88ba5";
    };
    buildInputs = [ ModuleBuildTiny Test2Suite ];
    propagatedBuildInputs = [ SubExporter ];
    meta = {
      homepage = "https://github.com/bluefeet/Class-Measure";
      description = "Create, compare, and convert units of measurement";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  MojoliciousPluginAuthentication = buildPerlPackage {
    pname = "Mojolicious-Plugin-Authentication";
    version = "1.39";
    src = fetchurl {
      url =
        "mirror://cpan/authors/id/J/JJ/JJATRIA/Mojolicious-Plugin-Authentication-1.39.tar.gz";
      sha256 = "sha256-n5nL31ysqj+j+WG+6U3pcibRd6NqFee6MDrnnRModNE=";
    };
    propagatedBuildInputs = [ Mojolicious ];
    meta = {
      homepage =
        "https://github.com/benvanstaveren/Mojolicious-Plugin-Authentication";
      description = "A plugin to make authentication a bit easier";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  GISDistance = buildPerlModule {
    pname = "GIS-Distance";
    version = "0.19";
    src = fetchurl {
      url = "mirror://cpan/authors/id/B/BL/BLUEFEET/GIS-Distance-0.19.tar.gz";
      sha256 =
        "f855d05d47f2fd2001824f8bccf131ab4ea21f2b945d202ccb163b7ba8587db3";
    };
    buildInputs = [ ModuleBuildTiny Test2Suite ];
    propagatedBuildInputs =
      [ ClassMeasure ConstFast namespaceclean strictures ];
    meta = {
      homepage = "https://github.com/bluefeet/GIS-Distance";
      description = "Calculate geographic distances";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  GISDistanceFast = buildPerlModule {
    pname = "GIS-Distance-Fast";
    version = "0.15";
    src = fetchurl {
      url =
        "mirror://cpan/authors/id/B/BL/BLUEFEET/GIS-Distance-Fast-0.15.tar.gz";
      sha256 =
        "d4d0ebe6fc92812528dd6f9ab86a1e3745dbe99448acd4911cc25a266b8ccd6a";
    };
    buildInputs = [ ModuleBuildTiny Test2Suite ];
    propagatedBuildInputs = [ GISDistance namespaceclean strictures ];
    meta = {
      homepage = "https://github.com/bluefeet/GIS-Distance-Fast";
      description = "C implementation of GIS::Distance formulas";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  TravelStatusDEDeutscheBahn = buildPerlModule {
    pname = "Travel-Status-DE-DeutscheBahn";
    version = "4.09";
    src = fetchurl {
      url =
        "mirror://cpan/authors/id/D/DE/DERF/Travel-Status-DE-DeutscheBahn-4.09.tar.gz";
      sha256 =
        "7ea92038912ab0e07ad73bc83e0b43be7bbfdc906f831ac06fd206747a49e28c";
    };
    buildInputs = [ FileSlurp TestCompile TestPod ];
    propagatedBuildInputs = [
      ClassAccessor
      DateTime
      DateTimeFormatStrptime
      JSON
      LWP
      LWPProtocolhttps
      ListMoreUtils
    ];
    meta = {
      description = "Interface to the online arrival/departure";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  TravelStatusDEDBWagenreihung = buildPerlModule {
    pname = "Travel-Status-DE-DBWagenreihung";
    version = "0.08";
    src = fetchurl {
      url =
        "mirror://cpan/authors/id/D/DE/DERF/Travel-Status-DE-DBWagenreihung-0.08.tar.gz";
      sha256 =
        "87f5d7dd01ac8fd46f630aee929ea37b79a65ecdf89fb927575ff7139265d61b";
    };
    buildInputs = [ TestCompile TestPod ];
    propagatedBuildInputs = [ ClassAccessor JSON LWP TravelStatusDEIRIS ];
    meta = {
      description = "Interface to Deutsche Bahn Wagon Order API";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  TravelStatusDEIRIS = buildPerlModule {
    pname = "Travel-Status-DE-IRIS";
    version = "1.82";
    src = fetchurl {
      url =
        "mirror://cpan/authors/id/D/DE/DERF/Travel-Status-DE-IRIS-1.82.tar.gz";
      sha256 =
        "92875b556cec42ac0e65fab94dbe9299eba09be958ab0d794b2a616f7e937c18";
    };
    buildInputs =
      [ FileSlurp JSON TestCompile TestFatal TestNumberDelta TestPod TextCSV ];
    propagatedBuildInputs = [
      ClassAccessor
      DateTime
      DateTimeFormatStrptime
      GISDistance
      LWP
      LWPProtocolhttps
      ListCompare
      ListMoreUtils
      ListUtilsBy
      TextLevenshteinXS
      XMLLibXML
    ];
    meta = {
      description = "Interface to IRIS based web departure monitors";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  Cache = buildPerlModule {
    pname = "Cache";
    version = "2.11";
    src = fetchurl {
      url = "mirror://cpan/authors/id/S/SH/SHLOMIF/Cache-2.11.tar.gz";
      sha256 =
        "e1d2d89677981166abc5bb6e5ecc6471f001f13eb56d5be9544d8047dc08a592";
    };
    doCheck = false;
    propagatedBuildInputs = [ FileNFSLock Heap IOString TimeDate ];
    meta = {
      description = "Provide a generic Cache mechanism";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
  Heap = buildPerlPackage {
    pname = "Heap";
    version = "0.80";
    src = fetchurl {
      url = "mirror://cpan/authors/id/J/JM/JMM/Heap-0.80.tar.gz";
      sha256 =
        "ccda29f3c93176ad0fdfff4dd6f5e4ac90b370cba4b028386b7343bf64139bde";
    };
    meta = { };
  };
  CAMPDF = buildPerlPackage {
    pname = "CAM-PDF";
    version = "1.60";
    src = fetchurl {
      url = "mirror://cpan/authors/id/C/CD/CDOLAN/CAM-PDF-1.60.tar.gz";
      sha256 =
        "e76afc7f38a624924a77c5c988c36c9e388bfa7716e75cd397fef8e1b42ebb89";
    };
    propagatedBuildInputs = [ CryptRC4 TextPDF ];
    meta = {
      description = "PDF manipulation library";
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };

  perlWithPackages = perl.withPackages (_: [
    Cache
    CacheCache
    CAMPDF
    CryptEksblowfish
    DateTime
    DateTimeFormatStrptime
    EmailSender
    GISDistance
    GISDistanceFast
    ListUtilsBy
    MIMEtools
    Mojolicious
    MojoliciousPluginAuthentication
    MojoPg
    TravelStatusDEDeutscheBahn
    TravelStatusDEDBWagenreihung
    TravelStatusDEIRIS
    UUIDTiny
    TextCSV
    JSON
    JSONXS
    XMLLibXML
    DBFile
    FileSlurp
    TextLevenshteinXS
    TextMarkdown
  ]);

  # Note: set location of config via $MOJO_CONFIG when running index.pl
  travelynx = stdenvNoCC.mkDerivation {
    pname = "travelynx";
    version = "2.4.1";
    src = fetchgit {
      url = "https://github.com/derf/travelynx";
      rev = "2.4.1";
      sha256 = "sha256-sLrA61XYBfZFTSmveRLNCHyXKLv1IpzGy5imKrc5rVw=";
    };
    buildPhase = ''
      substituteInPlace index.pl \
        --replace "/usr/bin/env perl" ${perlWithPackages.outPath}/bin/perl
      chmod +x index.pl
    '';
    installPhase = ''
      mkdir -p $out
      cp -r * $out
    '';
  };

in travelynx