Merge pull request #34798 from oxij/pkgs/aspell-dicts

aspellDicts: add more dictionaries and some documentation

authored by Michael Raskin and committed by GitHub cfa3e7e6 7d264272

+140 -10
+140 -10
pkgs/development/libraries/aspell/dictionaries.nix
··· 1 - {stdenv, fetchurl, aspell, which}: 1 + {lib, stdenv, fetchurl, aspell, which}: 2 + 3 + with lib; 4 + 5 + /* HOWTO: 6 + 7 + * Add some of these to your profile or systemPackages. 8 + 9 + ~~~~ 10 + environment.systemPackages = [ 11 + aspell 12 + aspellDicts.en 13 + aspellDicts.en-computers 14 + aspellDicts.en-science 15 + ]; 16 + ~~~~ 17 + 18 + * Rebuild and switch to the new profile. 19 + * Add something like 20 + 21 + ~~~~ 22 + master en_US 23 + extra-dicts en-computers.rws 24 + add-extra-dicts en_US-science.rws 25 + ~~~~ 26 + 27 + to `/etc/aspell.conf` or `~/.aspell.conf`. 28 + * Check that `aspell -a` starts without errors. 29 + * (optional) Check your config with `aspell dump config | grep -vE '^(#|$)'`. 30 + * Enjoy. 31 + 32 + */ 2 33 3 34 let 4 35 5 36 /* Function to compile an Aspell dictionary. Fortunately, they all 6 37 build in the exact same way. */ 7 38 buildDict = 8 - {shortName, fullName, src, postInstall ? ""}: 39 + {shortName, fullName, ...}@args: 9 40 10 - stdenv.mkDerivation { 41 + stdenv.mkDerivation ({ 11 42 name = "aspell-dict-${shortName}"; 12 - 13 - inherit src; 14 43 15 44 buildInputs = [aspell which]; 16 45 ··· 18 47 19 48 preBuild = "makeFlagsArray=(dictdir=$out/lib/aspell datadir=$out/lib/aspell)"; 20 49 21 - inherit postInstall; 22 - 23 50 meta = { 24 51 description = "Aspell dictionary for ${fullName}"; 25 52 platforms = stdenv.lib.platforms.all; 26 - }; 27 - }; 53 + } // (args.meta or {}); 54 + } // removeAttrs args [ "meta" ]); 55 + 56 + /* Function to compile txt dict files into Aspell dictionaries. */ 57 + buildTxtDict = 58 + {langInputs ? [], ...}@args: 59 + buildDict ({ 60 + propagatedUserEnvPackages = langInputs; 61 + 62 + preBuild = '' 63 + # Aspell can't handle multiple data-dirs 64 + # Copy everything we might possibly need 65 + ${concatMapStringsSep "\n" (p: '' 66 + cp -a ${p}/lib/aspell/* . 67 + '') ([ aspell ] ++ langInputs)} 68 + export ASPELL_CONF="data-dir $(pwd)" 69 + 70 + aspell-create() { 71 + target=$1 72 + shift 73 + echo building $target 74 + aspell create "$@" master ./$target.rws 75 + } 28 76 29 - in { 77 + words-only() { 78 + awk -F'\t' '{print $1}' | sort | uniq 79 + } 80 + 81 + # drop comments 82 + aspell-affix() { 83 + words-only \ 84 + | grep -v '#' \ 85 + | aspell-create "$@" 86 + } 87 + 88 + # Hack: drop comments and words with affixes 89 + aspell-plain() { 90 + words-only \ 91 + | grep -v '#' \ 92 + | grep -v '/' \ 93 + | aspell-create "$@" 94 + } 95 + 96 + aspell-install() { 97 + install -d $out/lib/aspell 98 + for a in "$@"; do 99 + echo installing $a 100 + install -t $out/lib/aspell $a.rws 101 + done 102 + } 103 + ''; 104 + 105 + phases = [ "preBuild" "buildPhase" "installPhase" ]; 106 + } // args); 107 + 108 + in rec { 109 + 110 + ### Languages 30 111 31 112 ca = buildDict { 32 113 shortName = "ca-2.1.5-1"; ··· 228 309 url = mirror://gnu/aspell/dict/uk/aspell6-uk-1.4.0-0.tar.bz2; 229 310 sha256 = "137i4njvnslab6l4s291s11xijr5jsy75lbdph32f9y183lagy9m"; 230 311 }; 312 + }; 313 + 314 + ### Jargons 315 + 316 + en-computers = buildTxtDict rec { 317 + shortName = "en-computers"; 318 + fullName = "English Computer Jargon"; 319 + 320 + src = fetchurl { 321 + url = https://mrsatterly.com/computer.dic; 322 + sha256 = "1vzk7cdvcm9r1c6mgxpabrdcpvghdv9mjmnf6iq5wllcif5nsw2b"; 323 + }; 324 + 325 + langInputs = [ en ]; 326 + 327 + buildPhase = "cat $src | aspell-affix en-computers --dont-validate-words --lang=en"; 328 + installPhase = "aspell-install en-computers"; 329 + 330 + meta = { 331 + homepage = https://mrsatterly.com/spelling.html; 332 + }; 333 + }; 334 + 335 + en-science = buildTxtDict rec { 336 + shortName = "en-science"; 337 + fullName = "English Scientific Jargon"; 338 + 339 + src1 = fetchurl { 340 + url = http://jpetrie.net/wp-content/uploads/custom_scientific_US.txt; 341 + sha256 = "1psqm094zl4prk2f8h18jv0d471hxykzd1zdnrlx7gzrzy6pz5r3"; 342 + }; 343 + 344 + src2 = fetchurl { 345 + url = http://jpetrie.net/wp-content/uploads/custom_scientific_UK.txt; 346 + sha256 = "17ss1sdr3k70zbyx2z9xf74345slrp41gbkpih8axrmg4x92fgm1"; 347 + }; 348 + 349 + langInputs = [ en ]; 350 + 351 + buildPhase = '' 352 + cat $src1 | aspell-plain en_US-science --dont-validate-words --lang=en 353 + cat $src2 | aspell-plain en_GB-science --dont-validate-words --lang=en 354 + ''; 355 + installPhase = "aspell-install en_US-science en_GB-science"; 356 + 357 + meta = { 358 + homepage = http://www.jpetrie.net/scientific-word-list-for-spell-checkersspelling-dictionaries/; 359 + }; 360 + 231 361 }; 232 362 233 363 }