<commit_before>{ pkgs ? import <nixpkgs> { }, compiler ? "ghc882"
, forShell ? pkgs.lib.inNixShell, hoogle ? forShell }:

let

  compiler' = if compiler != null then
    compiler
  else
    "ghc" + pkgs.lib.concatStrings
    (pkgs.lib.splitVersion pkgs.haskellPackages.ghc.version);

  targets = {
    vulkan = ./.;
    VulkanMemoryAllocator = ./VulkanMemoryAllocator;
    generate-new = ./generate-new;
  };

  # Any overrides we require to the specified haskell package set
  haskellPackages = with pkgs.haskell.lib;
    pkgs.haskell.packages.${compiler'}.override {
      overrides = self: super:
        (pkgs.lib.mapAttrs (n: v: makeDrv n v) targets) // {
          #
          # Examples
          #
          sdl2 = overrideSrc super.sdl2 {
            src = pkgs.fetchFromGitHub {
              owner = "haskell-game";
              repo = "sdl2";
              rev = "d10b2ae86ce3db58c5c011cbec6eccf69c2fd2f1";
              sha256 = "1qfjfrzc9yjg8ibgr0a7fly6fnd1f2yv731n7h1wjgz9vaa3q6wg";
            };
          };
          bytes = self.bytes_0_17;

          #
          # Generate
          #
          algebraic-graphs = dontCheck super.algebraic-graphs;
          first-class-families = doJailbreak super.first-class-families;
          inline-c = self.inline-c_0_9_0_0;
          polysemy-plugin = self.callCabal2nix "" ((pkgs.fetchFromGitHub {
            owner = "polysemy-research";
            repo = "polysemy";
            rev = "72dc96fbd13dba6d8e9767253b7298e00a781bee";
            sha256 = "09b1n71gjmhf4ggx2wlywxm11jl3qbmhnlmmchj8pyy3hczl6hb5";
          } + "/polysemy-plugin")) { };
          polysemy = self.callCabal2nix "" ((pkgs.fetchFromGitHub {
            owner = "polysemy-research";
            repo = "polysemy";
            rev = "72dc96fbd13dba6d8e9767253b7298e00a781bee";
            sha256 = "09b1n71gjmhf4ggx2wlywxm11jl3qbmhnlmmchj8pyy3hczl6hb5";
          })) { };
          polysemy-zoo = dontCheck (self.callCabal2nix ""
            ((pkgs.fetchFromGitHub {
              owner = "polysemy-research";
              repo = "polysemy-zoo";
              rev = "57c6012e196db7fe1ce7551f1f762cbddc71f095";
              sha256 = "18smd2c66gdn9585sdkn60ykvdvkbvkxrnnl9zix687dca6h9jw0";
            })) { });
          compact = doJailbreak super.compact;
          pandoc = appendPatch super.pandoc
            ./generate-new/patches/pandoc-haddock-tables.patch;
          language-c = appendPatches super.language-c [
            ./generate-new/patches/language-c-custom-state.patch
            ./generate-new/patches/language-c-align.patch
            ./generate-new/patches/language-c-show-type.patch
          ];
        } // pkgs.lib.optionalAttrs hoogle {
          ghc = super.ghc // { withPackages = super.ghc.withHoogle; };
          ghcWithPackages = p:
            self.ghc.withPackages
            (f: p f ++ (if forShell then [ f.process ] else [ ]));
        };
    };

  buildSet = pkgs.lib.foldl (ps: p: ps // { ${p.pname} = p; }) { } packages;
  packages = map (t: haskellPackages.${t}) (builtins.attrNames targets);
  tools = with pkgs; [ pkgconfig asciidoctor python3 doxygen glslang vulkan-validation-layers ];

  # Generate a haskell derivation using the cabal2nix tool on `package.yaml`
  makeDrv = name: src:
    let
      drv =
        haskellPackages.callCabal2nixWithOptions "" src "--flag=build-examples"
        ({ } // pkgs.lib.optionalAttrs (name == "vulkan") {
          vulkan = pkgs.vulkan-loader;
        } // pkgs.lib.optionalAttrs
          (name == "VulkanMemoryAllocator" && forShell) {
            # For the shell we don't want to have the compile the local dependency
            # for VMA
            vulkan = null;
          });
    in if name == "vulkan" then
      pkgs.haskell.lib.addExtraLibrary drv pkgs.vulkan-headers
    else
      drv;

  addHoogleDatabase = drv:
    if hoogle then
      drv.overrideAttrs (attrs: {
        shellHook = attrs.shellHook + ''<commit_msg>Move glslang to build tools in nix expression<commit_after>{ pkgs ? import <nixpkgs> { }, compiler ? "ghc882"
, forShell ? pkgs.lib.inNixShell, hoogle ? forShell }:

let

  compiler' = if compiler != null then
    compiler
  else
    "ghc" + pkgs.lib.concatStrings
    (pkgs.lib.splitVersion pkgs.haskellPackages.ghc.version);

  targets = {
    vulkan = ./.;
    VulkanMemoryAllocator = ./VulkanMemoryAllocator;
    generate-new = ./generate-new;
  };

  # Any overrides we require to the specified haskell package set
  haskellPackages = with pkgs.haskell.lib;
    pkgs.haskell.packages.${compiler'}.override {
      overrides = self: super:
        (pkgs.lib.mapAttrs (n: v: makeDrv n v) targets) // {
          #
          # Examples
          #
          sdl2 = overrideSrc super.sdl2 {
            src = pkgs.fetchFromGitHub {
              owner = "haskell-game";
              repo = "sdl2";
              rev = "d10b2ae86ce3db58c5c011cbec6eccf69c2fd2f1";
              sha256 = "1qfjfrzc9yjg8ibgr0a7fly6fnd1f2yv731n7h1wjgz9vaa3q6wg";
            };
          };
          bytes = self.bytes_0_17;

          #
          # Generate
          #
          algebraic-graphs = dontCheck super.algebraic-graphs;
          first-class-families = doJailbreak super.first-class-families;
          inline-c = self.inline-c_0_9_0_0;
          polysemy-plugin = self.callCabal2nix "" ((pkgs.fetchFromGitHub {
            owner = "polysemy-research";
            repo = "polysemy";
            rev = "72dc96fbd13dba6d8e9767253b7298e00a781bee";
            sha256 = "09b1n71gjmhf4ggx2wlywxm11jl3qbmhnlmmchj8pyy3hczl6hb5";
          } + "/polysemy-plugin")) { };
          polysemy = self.callCabal2nix "" ((pkgs.fetchFromGitHub {
            owner = "polysemy-research";
            repo = "polysemy";
            rev = "72dc96fbd13dba6d8e9767253b7298e00a781bee";
            sha256 = "09b1n71gjmhf4ggx2wlywxm11jl3qbmhnlmmchj8pyy3hczl6hb5";
          })) { };
          polysemy-zoo = dontCheck (self.callCabal2nix ""
            ((pkgs.fetchFromGitHub {
              owner = "polysemy-research";
              repo = "polysemy-zoo";
              rev = "57c6012e196db7fe1ce7551f1f762cbddc71f095";
              sha256 = "18smd2c66gdn9585sdkn60ykvdvkbvkxrnnl9zix687dca6h9jw0";
            })) { });
          compact = doJailbreak super.compact;
          pandoc = appendPatch super.pandoc
            ./generate-new/patches/pandoc-haddock-tables.patch;
          language-c = appendPatches super.language-c [
            ./generate-new/patches/language-c-custom-state.patch
            ./generate-new/patches/language-c-align.patch
            ./generate-new/patches/language-c-show-type.patch
          ];
        } // pkgs.lib.optionalAttrs hoogle {
          ghc = super.ghc // { withPackages = super.ghc.withHoogle; };
          ghcWithPackages = p:
            self.ghc.withPackages
            (f: p f ++ (if forShell then [ f.process ] else [ ]));
        };
    };

  buildSet = pkgs.lib.foldl (ps: p: ps // { ${p.pname} = p; }) { } packages;
  packages = map (t: haskellPackages.${t}) (builtins.attrNames targets);
  tools = with pkgs; [
    pkgconfig
    asciidoctor
    python3
    doxygen
    vulkan-validation-layers
  ];

  # Generate a haskell derivation using the cabal2nix tool on `package.yaml`
  makeDrv = name: src:
    let
      drv =
        haskellPackages.callCabal2nixWithOptions "" src "--flag=build-examples"
        ({ } // pkgs.lib.optionalAttrs (name == "vulkan") {
          vulkan = pkgs.vulkan-loader;
        } // pkgs.lib.optionalAttrs
          (name == "VulkanMemoryAllocator" && forShell) {
            # For the shell we don't want to have the compile the local dependency
            # for VMA
            vulkan = null;
          });
    in if name == "vulkan" then
      with pkgs.haskell.lib;
      addExtraLibrary (addBuildTool drv pkgs.glslang) pkgs.vulkan-headers
    else
      drv;

  addHoogleDatabase = drv:
    if hoogle then
      drv.overrideAttrs (attrs: {
        shellHook = attrs.shellHook + ''
{'fraction_non_alphanumeric': 0.11095856215676485, 'fraction_numerical': 0.045681477783325014, 'mean_word_length': 2.064244741873805, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 2}}
{'dir': 'git-commits-cleaned', 'id': '1005922', 'n_tokens_mistral': 3049, 'n_tokens_neox': 2778, 'n_words': 466}