<commit_before>{lib, stdenv, fetchurl, aspell, which, writeScript}:

with lib;

/* HOWTO:

   * Add some of these to your profile or systemPackages.

     ~~~~
     environment.systemPackages = [
       aspell
       aspellDicts.en
       aspellDicts.en-computers
       aspellDicts.en-science
     ];
     ~~~~

   * Rebuild and switch to the new profile.
   * Add something like

     ~~~~
     master en_US
     extra-dicts en-computers.rws
     add-extra-dicts en_US-science.rws
     ~~~~

     to `/etc/aspell.conf` or `~/.aspell.conf`.
   * Check that `aspell -a` starts without errors.
   * (optional) Check your config with `aspell dump config | grep -vE '^(#|$)'`.
   * Enjoy.

*/

let

  /* Function to compile an Aspell dictionary.  Fortunately, they all
     build in the exact same way. */
  buildDict =
    {shortName, fullName, ...}@args:

    stdenv.mkDerivation ({
      name = "aspell-dict-${shortName}";

      buildInputs = [aspell which];

      dontAddPrefix = true;

      preBuild = "makeFlagsArray=(dictdir=$out/lib/aspell datadir=$out/lib/aspell)";

      meta = {
        description = "Aspell dictionary for ${fullName}";
        platforms = stdenv.lib.platforms.all;
      } // (args.meta or {});
    } // removeAttrs args [ "meta" ]);


  buildOfficialDict =
    {language, version, filename, fullName, sha256, ...}@args:
    let buildArgs = {
      name = "aspell-dict-${language}";

      shortName = "${language}-${version}";

      src = fetchurl {
        url = "mirror://gnu/aspell/dict/${language}/${filename}-${language}-${version}.tar.bz2";
        inherit sha256;
      };

      /* Remove any instances of u-deva.cmap and u-deva.cset since
         they are included in the main aspell package and can
         cause conflicts otherwise. */
      postInstall = ''
        rm -f $out/lib/aspell/u-deva.{cmap,cset}
      '';

      passthru.updateScript = writeScript "update-aspellDict-${language}" ''
        #!/usr/bin/env nix-shell
        #!nix-shell -i bash -p nix curl gnused common-updater-scripts
        set -eu -o pipefail

        # List tarballs in the dictionary's subdirectory via FTP.
        #
        # Catalan dictionary has an exception where an earlier version
        # compares as newer because the versioning scheme has changed.
        versions=$(
            echo '[';
            curl -sl ftp://ftp.gnu.org/gnu/aspell/dict/${language}/ | \
                sed -r "s/^${filename}-${language}-(.+)\.tar\.bz2$/\"\1\"/;t;d" | \<commit_msg>aspell: remove override of name in buildOfficialDict<commit_after>{lib, stdenv, fetchurl, aspell, which, writeScript}:

with lib;

/* HOWTO:

   * Add some of these to your profile or systemPackages.

     ~~~~
     environment.systemPackages = [
       aspell
       aspellDicts.en
       aspellDicts.en-computers
       aspellDicts.en-science
     ];
     ~~~~

   * Rebuild and switch to the new profile.
   * Add something like

     ~~~~
     master en_US
     extra-dicts en-computers.rws
     add-extra-dicts en_US-science.rws
     ~~~~

     to `/etc/aspell.conf` or `~/.aspell.conf`.
   * Check that `aspell -a` starts without errors.
   * (optional) Check your config with `aspell dump config | grep -vE '^(#|$)'`.
   * Enjoy.

*/

let

  /* Function to compile an Aspell dictionary.  Fortunately, they all
     build in the exact same way. */
  buildDict =
    {shortName, fullName, ...}@args:

    stdenv.mkDerivation ({
      name = "aspell-dict-${shortName}";

      buildInputs = [aspell which];

      dontAddPrefix = true;

      preBuild = "makeFlagsArray=(dictdir=$out/lib/aspell datadir=$out/lib/aspell)";

      meta = {
        description = "Aspell dictionary for ${fullName}";
        platforms = stdenv.lib.platforms.all;
      } // (args.meta or {});
    } // removeAttrs args [ "meta" ]);


  buildOfficialDict =
    {language, version, filename, fullName, sha256, ...}@args:
    let buildArgs = {
      shortName = "${language}-${version}";

      src = fetchurl {
        url = "mirror://gnu/aspell/dict/${language}/${filename}-${language}-${version}.tar.bz2";
        inherit sha256;
      };

      /* Remove any instances of u-deva.cmap and u-deva.cset since
         they are included in the main aspell package and can
         cause conflicts otherwise. */
      postInstall = ''
        rm -f $out/lib/aspell/u-deva.{cmap,cset}
      '';

      passthru.updateScript = writeScript "update-aspellDict-${language}" ''
        #!/usr/bin/env nix-shell
        #!nix-shell -i bash -p nix curl gnused common-updater-scripts
        set -eu -o pipefail

        # List tarballs in the dictionary's subdirectory via FTP.
        #
        # Catalan dictionary has an exception where an earlier version
        # compares as newer because the versioning scheme has changed.
        versions=$(
            echo '[';
            curl -sl ftp://ftp.gnu.org/gnu/aspell/dict/${language}/ | \
                sed -r "s/^${filename}-${language}-(.+)\.tar\.bz2$/\"\1\"/;t;d" | \
{'fraction_non_alphanumeric': 0.1396, 'fraction_numerical': 0.0036, 'mean_word_length': 2.2243713733075436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2489139', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1571, 'n_words': 404}