<commit_before>{ haskellPackages
, runCommand
, spec
, stdenv
, preConfigure ? ""
}:

let

  inherit (spec) name;
  inherit (stdenv) lib;

  getVersion = name:
  let
    versionFromGhc = lib.removeSuffix "\n" (builtins.readFile (
      runCommand "${name}-version" {} ''
        ${haskellPackages.ghc}/bin/ghc-pkg field ${name} version --simple-output > $out
      ''));
  in haskellPackages.${name}.version or versionFromGhc;

  dependenciesWithVersions = map (p: "${p} == ${getVersion p}");
  hpackDependencies = {
    dependencies = dependenciesWithVersions spec.dependencies;
    tests = lib.mapAttrs (name: value: {
      dependencies = dependenciesWithVersions value.dependencies;
    }) spec.tests;
  };
  hpack = lib.recursiveUpdate spec hpackDependencies;

  hpackFile = builtins.toFile "package.yaml" (builtins.toJSON hpack);
  cabalFile = runCommand "${name}.cabal" {} ''
    cp ${hpackFile} package.yaml
    ${haskellPackages.hpack}/bin/hpack
    mv ${name}.cabal $out
  '';

  # Symlinking won't work because GitLab CI doesn't resolve symlinks when
  # creating artifacts
  copyCabalFile = ''
    cp --force ${cabalFile} ${name}.cabal
  '';

in haskellPackages.mkDerivation {

  pname = name;
  isExecutable = lib.hasAttr "executables" spec;
  isLibrary = lib.hasAttr "library" spec;
  license = lib.licenses.mpl20;
  src = ./.;
  version = spec.version or "0.0.0";

  executableHaskellDepends = map (d: haskellPackages.${d}) spec.dependencies;
  testHaskellDepends = map (d:
    haskellPackages.${d}
  ) (lib.concatLists (lib.mapAttrsToList (_: t: t.dependencies) spec.tests));

  preConfigure = ''
    ${preConfigure}
    ${copyCabalFile}
  '';

  shellHook = copyCabalFile;
}
<commit_msg>hpack needs the source when generating the cabal file<commit_after>{ haskellPackages
, runCommand
, spec
, stdenv
, preConfigure ? ""
}:

let

  inherit (spec) name;
  inherit (stdenv) lib;

  getVersion = name:
  let
    versionFromGhc = lib.removeSuffix "\n" (builtins.readFile (
      runCommand "${name}-version" {} ''
        ${haskellPackages.ghc}/bin/ghc-pkg field ${name} version --simple-output > $out
      ''));
  in haskellPackages.${name}.version or versionFromGhc;

  dependenciesWithVersions = map (p: "${p} == ${getVersion p}");
  hpackDependencies = {
    dependencies = dependenciesWithVersions spec.dependencies;
    tests = lib.mapAttrs (name: value: {
      dependencies = dependenciesWithVersions value.dependencies;
    }) spec.tests;
  };
  hpack = lib.recursiveUpdate spec hpackDependencies;
  hpackFile = builtins.toFile "package.yaml" (builtins.toJSON hpack);

  cabalFile = runCommand "${name}.cabal" {} ''

    # hpack needs the source to glob e.g. data-files
    cp --recursive --no-preserve=mode ${src} src

    cp ${hpackFile} src/package.yaml
    (cd src && ${haskellPackages.hpack}/bin/hpack)
    mv src/${name}.cabal $out
  '';

  # Symlinking won't work because GitLab CI doesn't resolve symlinks when
  # creating artifacts
  copyCabalFile = ''
    cp --force ${cabalFile} ${name}.cabal
  '';

  src = runCommand "${name}-src" {} ''
    cp --recursive --no-preserve=mode ${./.} $out
    (cd $out && ${preConfigure})
  '';

in haskellPackages.mkDerivation {

  inherit src;
  pname = name;
  isExecutable = lib.hasAttr "executables" spec;
  isLibrary = lib.hasAttr "library" spec;
  license = lib.licenses.mpl20;
  version = spec.version or "0.0.0";

  executableHaskellDepends = map (d: haskellPackages.${d}) spec.dependencies;
  testHaskellDepends = map (d:
    haskellPackages.${d}
  ) (lib.concatLists (lib.mapAttrsToList (_: t: t.dependencies) spec.tests));

  preConfigure = ''
    ${copyCabalFile}
  '';

  shellHook = copyCabalFile;
}

{'fraction_non_alphanumeric': 0.1409177301113223, 'fraction_numerical': 0.0027151778441487917, 'mean_word_length': 3.6223337515683816, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0}}
{'dir': 'git-commits-cleaned', 'id': '1911897', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1250, 'n_words': 281}