<commit_before>{ stdenv, erlang, rebar3, openssl, libyaml, fetchurl }:

{ name, version, sha256
, hexPkg ? name
, buildInputs ? [], erlangDeps ? []
, postPatch ? ""
, compilePorts ? false
, ... }@attrs:

with stdenv.lib;

stdenv.mkDerivation (attrs // {
  name = "${name}-${version}";

  buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];

  postPatch = ''
    rm -f rebar rebar3
    if [ -e "src/${name}.app.src" ]; then
      sed -i -e 's/{ *vsn *,[^}]*}/{vsn, "${version}"}/' "src/${name}.app.src"
    fi

    # TODO: figure out how to provide 'pc' plugin hermetically
    ${if compilePorts then ''
    echo "{plugins, [pc]}.
    {provider_hooks,
    [{post,
     [{compile, {pc, compile}},
      {clean, {pc, clean}}]}]}." >> rebar.config
    '' else ''''}

    ${postPatch}
  '';

  unpackCmd = ''
    tar -xf $curSrc contents.tar.gz
    mkdir contents
    tar -C contents -xzf contents.tar.gz
  '';

  configurePhase = let
    getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps);
    recursiveDeps = uniqList {
       inputList = flatten (map getDeps erlangDeps);
    };
  in ''
    runHook preConfigure
    mkdir -p _build/default/lib/
    ${concatMapStrings (dep: ''
      header "linking erlang dependency ${dep}"
      ln -s "${dep}" "_build/default/lib/${dep.packageName}"
      stopNest
    '') recursiveDeps}
    runHook postConfigure
  '';

  # TODO: figure out how to provide rebar3 a static registry snapshot to make
  # this hermetic
  buildPhase = ''
    runHook preBuild
    HOME=. rebar3 update
    HOME=. rebar3 compile
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall
    mkdir "$out"
    for reldir in src ebin priv include; do<commit_msg>Simplify patch and move pc compile call into buildPhase<commit_after>{ stdenv, erlang, rebar3, openssl, libyaml, fetchurl }:

{ name, version, sha256
, hexPkg ? name
, buildInputs ? [], erlangDeps ? []
, postPatch ? ""
, compilePorts ? false
, ... }@attrs:

with stdenv.lib;

stdenv.mkDerivation (attrs // {
  name = "${name}-${version}";

  buildInputs = buildInputs ++ [ erlang rebar3 openssl libyaml ];

  postPatch = ''
    rm -f rebar rebar3
    if [ -e "src/${name}.app.src" ]; then
      sed -i -e 's/{ *vsn *,[^}]*}/{vsn, "${version}"}/' "src/${name}.app.src"
    fi

    # TODO: figure out how to provide 'pc' plugin hermetically
    ${if compilePorts then ''
    echo "{plugins, [pc]}." >> rebar.config
    '' else ''''}

    ${postPatch}
  '';

  unpackCmd = ''
    tar -xf $curSrc contents.tar.gz
    mkdir contents
    tar -C contents -xzf contents.tar.gz
  '';

  configurePhase = let
    getDeps = drv: [drv] ++ (map getDeps drv.erlangDeps);
    recursiveDeps = uniqList {
       inputList = flatten (map getDeps erlangDeps);
    };
  in ''
    runHook preConfigure
    mkdir -p _build/default/lib/
    ${concatMapStrings (dep: ''
      header "linking erlang dependency ${dep}"
      ln -s "${dep}" "_build/default/lib/${dep.packageName}"
      stopNest
    '') recursiveDeps}
    runHook postConfigure
  '';

  # TODO: figure out how to provide rebar3 a static registry snapshot to make
  # this hermetic
  buildPhase = ''
    runHook preBuild
    HOME=. rebar3 do update, compile
    HOME=. rebar3 pc compile
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall
    mkdir "$out"
    for reldir in src ebin priv include; do
{'fraction_non_alphanumeric': 0.14681357951161406, 'fraction_numerical': 0.005360333531864205, 'mean_word_length': 2.7997737556561084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': 0}}
{'dir': 'git-commits-cleaned', 'id': '2970545', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1156, 'n_words': 324}