{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:

let

  inherit (nixpkgs) pkgs;

  f = { mkDerivation, base, cairo, diagrams-cairo, diagrams-core
      , diagrams-gtk, diagrams-lib, gtk, hint, lens, optparse-applicative
      , protolude, stdenv
      }:
      mkDerivation {
        pname = "pixra";
        version = "0.1.0.0";
        src = ./.;
        isLibrary = false;
        isExecutable = true;
        executableHaskellDepends = [
          base cairo diagrams-cairo diagrams-core diagrams-gtk diagrams-lib
          gtk hint lens optparse-applicative protolude
        ];
        description = "A live editing environment for pictures";
        license = stdenv.lib.licenses.agpl3;
      };

  haskellPackages = if compiler == "default"
                       then pkgs.haskellPackages
                       else pkgs.haskell.packages.${compiler};

  variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

  drv = variant (haskellPackages.callPackage f {});

in

  if pkgs.lib.inNixShell then drv.env else drv
