{
  lib,
  stdenv,
  fetchFromGitHub,
  ncurses,
  openssl,
  pcre2,
  zlib,

  lua5_4,
  python3,
  icu,

  enableLua ? true,
  enablePython ? true,
  enableWidechar ? true,
}:

stdenv.mkDerivation rec {
  pname = "tinyfugue";
  version = "5.2.2";

  src = fetchFromGitHub {
    owner = "ingwarsw";
    repo = "tinyfugue";
    rev = version;
    hash = "sha256-nHgu0XJ2Nd0JYrs3o/NLZ9gq1D4ubdPyowQLyhOzDDA=";
  };

  buildInputs = [
    ncurses
    openssl
    pcre2
    zlib
  ]
  ++ lib.optional enableLua lua5_4
  ++ lib.optional enablePython python3
  ++ lib.optional enableWidechar icu;

  env.NIX_CFLAGS_COMPILE = "-D_DEFAULT_SOURCE";

  configureFlags = [
    "--enable-termcap=ncurses"
  ]
  ++ lib.optional enableLua "--enable-lua"
  ++ lib.optional enablePython "--enable-python"
  ++ lib.optional (!enableWidechar) "--disable-widechar";

  installPhase = ''
    make install
  '';

  meta = {
    description = "TinyFugue - Rebirth";
    homepage = "https://github.com/ingwarsw/tinyfugue";
    changelog = "https://github.com/ingwarsw/tinyfugue/blob/${src.rev}/CHANGES";
    license = lib.licenses.gpl2Only;
    mainProgram = "tf";
    platforms = lib.platforms.all;
  };
}
