{
  lib,
  cmake,
  fetchFromGitHub,
  stdenv,
  testers,
  texinfo,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "quickjs-ng";
  version = "0.16.1";

  src = fetchFromGitHub {
    owner = "quickjs-ng";
    repo = "quickjs";
    tag = "v${finalAttrs.version}";
    hash = "sha256-qTBRR38axE6CtShUBaaLjytszKRzo/8eyARw9JRJBAA=";
  };

  outputs = [
    "out"
    "bin"
    "dev"
    "doc"
    "info"
  ];

  nativeBuildInputs = [
    cmake
    texinfo
  ];

  cmakeFlags = [
    (lib.cmakeBool "BUILD_SHARED_LIBS" true)
    (lib.cmakeBool "BUILD_STATIC_QJS_EXE" stdenv.hostPlatform.isStatic)
  ];

  strictDeps = true;

  postBuild = ''
    pushd ../docs
    makeinfo *texi
    popd
  '';

  postInstall = ''
    pushd ../docs
    install -Dm644 -t ''${!outputInfo}/share/info *info
    popd
  '';

  passthru.tests = {
    version = testers.testVersion {
      package = finalAttrs.finalPackage;
      command = "qjs --help || true";
    };
  };

  meta = {
    homepage = "https://github.com/quickjs-ng/quickjs";
    description = "Mighty JavaScript engine";
    license = lib.licenses.mit;
    mainProgram = "qjs";
    maintainers = [ ];
    platforms = lib.platforms.all;
  };
})
