Merge pull request #238805 from networkException/chromium-dictionary-formats

hunspellDictsChromium: init at 115.0.5790.170

authored by

Emily and committed by
GitHub
bdba2e21 98c1ed53

+149
+70
pkgs/development/libraries/hunspell/dictionaries-chromium.nix
··· 1 + { lib, stdenv, fetchgit }: 2 + 3 + let 4 + mkDictFromChromium = { shortName, dictFileName, shortDescription }: 5 + stdenv.mkDerivation { 6 + pname = "hunspell-dict-${shortName}-chromium"; 7 + version = "115.0.5790.170"; 8 + 9 + src = fetchgit { 10 + url = "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries"; 11 + rev = "41cdffd71c9948f63c7ad36e1fb0ff519aa7a37e"; 12 + hash = "sha256-67mvpJRFFa9eMfyqFMURlbxOaTJBICnk+gl0b0mEHl8="; 13 + }; 14 + 15 + dontBuild = true; 16 + 17 + installPhase = '' 18 + cp ${dictFileName} $out 19 + ''; 20 + 21 + passthru = { 22 + # As chromium needs the exact filename in ~/.config/chromium/Dictionaries, 23 + # this value needs to be known to tools using the package if they want to 24 + # link the file correctly. 25 + inherit dictFileName; 26 + 27 + updateScript = ./update-chromium-dictionaries.py; 28 + }; 29 + 30 + meta = { 31 + homepage = "https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries/"; 32 + description = "Chromium compatible hunspell dictionary for ${shortDescription}"; 33 + longDescription = '' 34 + Humspell directories in Chromium's custom bdic format 35 + 36 + See https://www.chromium.org/developers/how-tos/editing-the-spell-checking-dictionaries/ 37 + ''; 38 + license = with lib.licenses; [ gpl2 lgpl21 mpl11 lgpl3 ]; 39 + maintainers = with lib.maintainers; [ networkexception ]; 40 + platforms = lib.platforms.all; 41 + }; 42 + }; 43 + in 44 + rec { 45 + 46 + /* ENGLISH */ 47 + 48 + en_US = en-us; 49 + en-us = mkDictFromChromium { 50 + shortName = "en-us"; 51 + dictFileName = "en-US-10-1.bdic"; 52 + shortDescription = "English (United States)"; 53 + }; 54 + 55 + en_GB = en-us; 56 + en-gb = mkDictFromChromium { 57 + shortName = "en-gb"; 58 + dictFileName = "en-GB-10-1.bdic"; 59 + shortDescription = "English (United Kingdom)"; 60 + }; 61 + 62 + /* GERMAN */ 63 + 64 + de_DE = de-de; 65 + de-de = mkDictFromChromium { 66 + shortName = "de-de"; 67 + dictFileName = "de-DE-3-0.bdic"; 68 + shortDescription = "German (Germany)"; 69 + }; 70 + }
+77
pkgs/development/libraries/hunspell/update-chromium-dictionaries.py
··· 1 + #! /usr/bin/env nix-shell 2 + #! nix-shell -i python3 -p python3 nix nix-prefetch-git 3 + 4 + import base64 5 + import fileinput 6 + import json 7 + import os 8 + import re 9 + import subprocess 10 + import sys 11 + 12 + from urllib.request import urlopen, Request 13 + 14 + 15 + DICTIONARIES_CHROMIUM_NIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'dictionaries-chromium.nix') 16 + 17 + 18 + def get_latest_chromium_stable_release(): 19 + RELEASES_URL = 'https://versionhistory.googleapis.com/v1/chrome/platforms/linux/channels/stable/versions/all/releases' 20 + print(f'GET {RELEASES_URL}') 21 + with urlopen(RELEASES_URL) as resp: 22 + return json.load(resp)['releases'][0] 23 + 24 + 25 + def get_file_revision(revision, file_path): 26 + """Fetches the requested Git revision of the given Chromium file.""" 27 + url = f'https://chromium.googlesource.com/chromium/src/+/refs/tags/{revision}/{file_path}?format=TEXT' 28 + with urlopen(url) as http_response: 29 + resp = http_response.read() 30 + return base64.b64decode(resp) 31 + 32 + 33 + def nix_prefetch_git(url, rev): 34 + """Prefetches the requested Git revision of the given repository URL.""" 35 + print(f'nix-prefetch-git {url} {rev}') 36 + out = subprocess.check_output(['nix-prefetch-git', '--quiet', '--url', url, '--rev', rev]) 37 + return json.loads(out) 38 + 39 + 40 + def get_current_revision(): 41 + with open(DICTIONARIES_CHROMIUM_NIX) as f: 42 + for line in f: 43 + rev = re.search(r'^ rev = "(.*)";', line) 44 + if rev: 45 + return rev.group(1) 46 + sys.exit(1) 47 + 48 + 49 + print('Getting latest chromium version...') 50 + chromium_release = get_latest_chromium_stable_release() 51 + chromium_version = chromium_release['version'] 52 + print(f'chromium version: {chromium_version}') 53 + 54 + print('Getting corresponding hunspell_dictionaries commit...') 55 + deps = get_file_revision(chromium_version, 'DEPS') 56 + hunspell_dictionaries_pattern = r"^\s*Var\('chromium_git'\)\s*\+\s*'\/chromium\/deps\/hunspell_dictionaries\.git'\s*\+\s*'@'\s*\+\s*'(\w*)',$" 57 + hunspell_dictionaries_commit = re.search(hunspell_dictionaries_pattern, deps.decode(), re.MULTILINE).group(1) 58 + print(f'hunspell_dictionaries commit: {hunspell_dictionaries_commit}') 59 + 60 + current_commit = get_current_revision() 61 + if current_commit == hunspell_dictionaries_commit: 62 + print('Commit is already packaged, no update needed.') 63 + sys.exit(0) 64 + 65 + print('Commit has changed compared to the current package, updating...') 66 + 67 + print('Getting hash of hunspell_dictionaries revision...') 68 + hunspell_dictionaries_git = nix_prefetch_git("https://chromium.googlesource.com/chromium/deps/hunspell_dictionaries", hunspell_dictionaries_commit) 69 + hunspell_dictionaries_hash = hunspell_dictionaries_git['hash'] 70 + print(f'hunspell_dictionaries commit hash: {hunspell_dictionaries_hash}') 71 + 72 + with fileinput.FileInput(DICTIONARIES_CHROMIUM_NIX, inplace=True) as file: 73 + for line in file: 74 + result = re.sub(r'^ version = ".+";', f' version = "{chromium_version}";', line) 75 + result = re.sub(r'^ rev = ".*";', f' rev = "{hunspell_dictionaries_commit}";', result) 76 + result = re.sub(r'^ hash = ".+";', f' hash = "{hunspell_dictionaries_hash}";', result) 77 + print(result, end='')
+2
pkgs/top-level/all-packages.nix
··· 21857 21857 21858 21858 hunspellDicts = recurseIntoAttrs (callPackages ../development/libraries/hunspell/dictionaries.nix {}); 21859 21859 21860 + hunspellDictsChromium = recurseIntoAttrs (callPackages ../development/libraries/hunspell/dictionaries-chromium.nix {}); 21861 + 21860 21862 hunspellWithDicts = dicts: callPackage ../development/libraries/hunspell/wrapper.nix { inherit dicts; }; 21861 21863 21862 21864 hwloc = callPackage ../development/libraries/hwloc { };