<commit_before># Install not only the Hoogle library and executable, but also a local Hoogle
# database which provides "Source" links to all specified 'packages' -- or the
# current Haskell Platform if no custom package set is provided.

{ lib, stdenv, buildPackages, haskellPackages
, writeText
}:

# This argument is a function which selects a list of Haskell packages from any
# passed Haskell package set.
#
# Example:
#   (hpkgs: [ hpkgs.mtl hpkgs.lens ])
selectPackages:

let
  inherit (haskellPackages) ghc hoogle;
  packages = selectPackages haskellPackages;

  wrapper = ./hoogle-local-wrapper.sh;
  isGhcjs = ghc.isGhcjs or false;
  opts = lib.optionalString;
  haddockExe =
    if !isGhcjs
    then "haddock"
    else "haddock-ghcjs";
  ghcDocLibDir =
    if !isGhcjs
    then ghc.doc + "/share/doc/ghc*/html/libraries"
    else ghc     + "/doc/lib";
  # On GHCJS, use a stripped down version of GHC's prologue.txt
  prologue =
    if !isGhcjs
    then "${ghcDocLibDir}/prologue.txt"
    else writeText "ghcjs-prologue.txt" ''
      This index includes documentation for many Haskell modules.
    '';

  # TODO: closePropagation is deprecated; replace
  docPackages = lib.closePropagation
    # we grab the doc outputs
    (map (lib.getOutput "doc") packages);

in
buildPackages.stdenv.mkDerivation {
  name = "hoogle-with-packages";
  buildInputs = [ghc hoogle];

  # compiling databases takes less time than copying the results
  # between machines.
  preferLocalBuild = true;
  # Plus, you need a complete database for each possible combination
  # of dependencies, caching them does not make sense.
  allowSubstitutes = false;

  inherit docPackages;

  passAsFile = ["buildCommand"];

  buildCommand = ''
    ${let # Filter out nulls here to work around https://github.com/NixOS/nixpkgs/issues/82245
          # If we don't then grabbing `p.name` here will fail.<commit_msg>haskellPackages.hoogleLocal: allow substitutes again<commit_after># Install not only the Hoogle library and executable, but also a local Hoogle
# database which provides "Source" links to all specified 'packages' -- or the
# current Haskell Platform if no custom package set is provided.

{ lib, stdenv, buildPackages, haskellPackages
, writeText
}:

# This argument is a function which selects a list of Haskell packages from any
# passed Haskell package set.
#
# Example:
#   (hpkgs: [ hpkgs.mtl hpkgs.lens ])
selectPackages:

let
  inherit (haskellPackages) ghc hoogle;
  packages = selectPackages haskellPackages;

  wrapper = ./hoogle-local-wrapper.sh;
  isGhcjs = ghc.isGhcjs or false;
  opts = lib.optionalString;
  haddockExe =
    if !isGhcjs
    then "haddock"
    else "haddock-ghcjs";
  ghcDocLibDir =
    if !isGhcjs
    then ghc.doc + "/share/doc/ghc*/html/libraries"
    else ghc     + "/doc/lib";
  # On GHCJS, use a stripped down version of GHC's prologue.txt
  prologue =
    if !isGhcjs
    then "${ghcDocLibDir}/prologue.txt"
    else writeText "ghcjs-prologue.txt" ''
      This index includes documentation for many Haskell modules.
    '';

  # TODO: closePropagation is deprecated; replace
  docPackages = lib.closePropagation
    # we grab the doc outputs
    (map (lib.getOutput "doc") packages);

in
buildPackages.stdenv.mkDerivation {
  name = "hoogle-with-packages";
  buildInputs = [ghc hoogle];

  # compiling databases takes less time than copying the results
  # between machines.
  preferLocalBuild = true;

  # we still allow substitutes because a database is relatively small and if it
  # is already built downloading is probably faster.  The substitution will only
  # trigger for users who have already cached the database on a substituter and
  # thus probably intend to substitute it.
  allowSubstitutes = true;

  inherit docPackages;

  passAsFile = ["buildCommand"];

  buildCommand = ''
    ${let # Filter out nulls here to work around https://github.com/NixOS/nixpkgs/issues/82245
          # If we don't then grabbing `p.name` here will fail.
{'fraction_non_alphanumeric': 0.0856999246041719, 'fraction_numerical': 0.0025131942699170647, 'mean_word_length': 3.5905420991926182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2001248', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1238, 'n_words': 427}