diff --git a/lib/licenses.nix b/lib/licenses.nix index 830cb95aff94..ee136c7337c1 100644 --- a/lib/licenses.nix +++ b/lib/licenses.nix @@ -306,6 +306,11 @@ lib.mapAttrs (n: v: v // { shortName = n; }) { fullName = "GNU Free Documentation License v1.1 only"; }; + fdl11Plus = spdx { + spdxId = "GFDL-1.1-or-later"; + fullName = "GNU Free Documentation License v1.1 or later"; + }; + fdl12Only = spdx { spdxId = "GFDL-1.2-only"; fullName = "GNU Free Documentation License v1.2 only"; diff --git a/pkgs/servers/dict/dictd-db.nix b/pkgs/servers/dict/dictd-db.nix index 584c35bf7f83..da73a94c2aa0 100644 --- a/pkgs/servers/dict/dictd-db.nix +++ b/pkgs/servers/dict/dictd-db.nix @@ -91,5 +91,5 @@ in rec { locale = "en_UK"; }; wordnet = callPackage ./dictd-wordnet.nix {}; - wiktionary = callPackage ./dictd-wiktionary.nix {}; + wiktionary = callPackage ./wiktionary {}; } diff --git a/pkgs/servers/dict/dictd-wiktionary.nix b/pkgs/servers/dict/dictd-wiktionary.nix deleted file mode 100644 index f591064a3c13..000000000000 --- a/pkgs/servers/dict/dictd-wiktionary.nix +++ /dev/null @@ -1,31 +0,0 @@ -{lib, stdenv, fetchurl, python, dict, glibcLocales, writeScript}: - -stdenv.mkDerivation rec { - version = "20161001"; - pname = "dict-db-wiktionary"; - data = fetchurl { - url = "http://dumps.wikimedia.org/enwiktionary/${version}/enwiktionary-${version}-pages-articles.xml.bz2"; - sha256 = "0g3k7kxp2nzg0v56i4cz253af3aqvhn1lwkys2fnam51cn3yqm7m"; - }; - - convert = ./wiktionary2dict.py; - buildInputs = [python dict glibcLocales]; - - builder = writeScript "wiktionary-builder.sh" '' - source $stdenv/setup - - mkdir -p $out/share/dictd/ - cd $out/share/dictd - - python -O ${convert} ${data} - dictzip wiktionary-en.dict - echo en_US.UTF-8 > locale - ''; - - meta = { - description = "DICT version of English Wiktionary"; - homepage = "http://en.wiktionary.org/"; - maintainers = [ ]; - platforms = lib.platforms.all; - }; -} diff --git a/pkgs/servers/dict/wiktionary/builder.sh b/pkgs/servers/dict/wiktionary/builder.sh new file mode 100644 index 000000000000..65652ad4bdbf --- /dev/null +++ b/pkgs/servers/dict/wiktionary/builder.sh @@ -0,0 +1,8 @@ +source $stdenv/setup + +mkdir -p $out/share/dictd/ +cd $out/share/dictd + +python -O "$convert" "$src" +dictzip wiktionary-en.dict +echo en_US.UTF-8 > locale diff --git a/pkgs/servers/dict/wiktionary/default.nix b/pkgs/servers/dict/wiktionary/default.nix new file mode 100644 index 000000000000..cd0c9c6c24bc --- /dev/null +++ b/pkgs/servers/dict/wiktionary/default.nix @@ -0,0 +1,25 @@ +{ lib, stdenv, fetchurl, python, dict, glibcLocales }: + +stdenv.mkDerivation rec { + version = "20210201"; + pname = "dict-db-wiktionary"; + + src = fetchurl { + url = "https://dumps.wikimedia.org/enwiktionary/${version}/enwiktionary-${version}-pages-articles.xml.bz2"; + sha256 = "0dc34cbadsg0f6lhfcyx0np7zjnlg6837piqhlvnn0b45xnzn0cs"; + }; + + convert = ./wiktionary2dict.py; + buildInputs = [ python dict glibcLocales ]; + builder = ./builder.sh; + + passthru.updateScript = ./update.sh; + + meta = with lib; { + description = "DICT version of English Wiktionary"; + homepage = "http://en.wiktionary.org/"; + maintainers = with maintainers; [ qyliss ]; + platforms = platforms.all; + license = with licenses; [ cc-by-sa-30 fdl11Plus ]; + }; +} diff --git a/pkgs/servers/dict/wiktionary/latest_version.py b/pkgs/servers/dict/wiktionary/latest_version.py new file mode 100644 index 000000000000..2833a1e05b03 --- /dev/null +++ b/pkgs/servers/dict/wiktionary/latest_version.py @@ -0,0 +1,42 @@ +import subprocess + +from html.parser import HTMLParser +from os.path import abspath, dirname +from urllib.request import urlopen + +class WiktionaryLatestVersionParser(HTMLParser): + def __init__(self, current_version, *args, **kwargs): + self.latest_version = current_version + super().__init__(*args, **kwargs) + + + def handle_starttag(self, tag, attrs): + if tag != 'a': + return + + href = dict(attrs)['href'][0:-1] + if href == 'latest': + return + + self.latest_version = max(self.latest_version, href) + + +def nix_prefetch_url(url, algo='sha256'): + """Prefetches the content of the given URL.""" + print(f'nix-prefetch-url {url}') + out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url]) + return out.decode('utf-8').rstrip() + + +current_version = subprocess.check_output([ + 'nix', 'eval', '--raw', + '-f', dirname(abspath(__file__)) + '/../../../..', + 'dictdDBs.wiktionary.version', +]).decode('utf-8') + +parser = WiktionaryLatestVersionParser(current_version) + +with urlopen('https://dumps.wikimedia.org/enwiktionary/') as resp: + parser.feed(resp.read().decode('utf-8')) + +print(parser.latest_version) diff --git a/pkgs/servers/dict/wiktionary/update.sh b/pkgs/servers/dict/wiktionary/update.sh new file mode 100755 index 000000000000..ff5e0fc3551a --- /dev/null +++ b/pkgs/servers/dict/wiktionary/update.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p common-updater-scripts python3 + +set -ueo pipefail + +version="$(python "$(dirname "${BASH_SOURCE[0]}")"/latest_version.py)" +update-source-version dictdDBs.wiktionary "$version" diff --git a/pkgs/servers/dict/wiktionary2dict.py b/pkgs/servers/dict/wiktionary/wiktionary2dict.py similarity index 100% rename from pkgs/servers/dict/wiktionary2dict.py rename to pkgs/servers/dict/wiktionary/wiktionary2dict.py