{
  haskellPackages,
  lib,
  stdenv,
  ...
}: let
  ghcExeOptions = lib.concatStringsSep " " ghcFlags;
  ghcFlags = [
    "-O"
    "-Wall"
    "-Widentities"
    "-Widentities"
    "-Wincomplete-record-updates"
    "-Wincomplete-uni-patterns"
    "-Wmissing-export-lists"
    "-Wmissing-home-modules"
    "-Wpartial-fields"
    "-Wredundant-constraints"
    "-threaded"
    "-rtsopts"
    "-with-rtsopts=-N"
    # hs-glsl
    "-i./lib/hs-glsl/src"
    # src
    "-i./src"
    "-main-is Haskengl.Main"
  ];
  haddockOptions = lib.concatStringsSep " " haddockFlags;
  haddockFlags = [
    "--html"
    "--odir docs"
    "--optghc=-i./src"
    "--optghc=-i./lib/hs-glsl/src"
    "src/Haskengl/Main.hs"
  ];
  ghcPackages = p: [
    p.GLFW-b
    p.GLUtil
    p.linear
    p.OpenGL
    p.relude
  ];
in
  stdenv.mkDerivation {
    pname = "haskengl";
    version = "0.1.0";
    src = ./.;
    nativeBuildInputs = [
      (haskellPackages.ghcWithPackages ghcPackages)
    ];
    buildInputs = [
    ];
    configurePhase = ''
    '';
    buildPhase = ''
      ghc ${ghcExeOptions} ./src/Haskengl/Main.hs -o ./Main
      haddock ${haddockOptions}
    '';
    installPhase = ''
      mkdir -p $out/bin
      cp ./Main $out/bin/haskengl
      cp ./docs $out/docs -r
    '';

    meta = {
      homepage = "https://mtgmonkey.net";
      license = lib.licenses.wtfpl;
      mainProgram = "haskengl";
      platforms = ["x86_64-linux"];
    };
  }
