19 buildModelPackage = { pname, version, sha256, license }:
22 lang = builtins.substring 0 2 pname;
23 requires-protobuf = pname == "fr_dep_news_trf" || pname == "uk_core_news_trf";
26 inherit pname version;
30 url = "https://github.com/explosion/spacy-models/releases/download/${pname}-${version}/${pname}-${version}.tar.gz";
34 propagatedBuildInputs = [ spacy ]
35 ++ lib.optionals (lib.hasSuffix "_trf" pname) [ spacy-transformers ]
36 ++ lib.optionals (lang == "ru") [ pymorphy3 ]
37 ++ lib.optionals (lang == "uk") [ pymorphy3 pymorphy3-dicts-uk ]
38 ++ lib.optionals (lang == "zh") [ spacy-pkuseg ]
39 ++ lib.optionals (pname == "fr_dep_news_trf") [ sentencepiece ];
41 postPatch = lib.optionalString requires-protobuf ''
42 substituteInPlace meta.json \
43 --replace "protobuf<3.21.0" "protobuf"
48 ] ++ lib.optionals requires-protobuf [
52 pythonImportsCheck = [ pname ];
54 passthru.updateScript = writeScript "update-spacy-models" ''
57 PATH=${lib.makeBinPath [ jq nix moreutils ]}
59 IFS=. read -r major minor patch <<<"${spacy.version}"
60 spacyVersion="$(echo "$major.$minor.0")"
62 pushd pkgs/development/python-modules/spacy/ || exit
64 jq -r '.[] | .pname' models.json | while IFS= read -r pname; do
65 if [ "$(jq --arg pname "$pname" -r '.[] | select(.pname == $pname) | .version' models.json)" == "$spacyVersion" ]; then
69 newHash="$(nix-prefetch-url "https://github.com/explosion/spacy-models/releases/download/$pname-$spacyVersion/$pname-$spacyVersion.tar.gz")"
70 jq --arg newHash "$newHash" --arg pname "$pname" --arg spacyVersion "$spacyVersion" \
71 '[(.[] | select(.pname != $pname)), (.[] | select(.pname == $pname) | .sha256 = $newHash | .version = $spacyVersion)] | sort_by(.pname)' \
72 models.json | sponge models.json
79 description = "Models for the spaCy NLP library";
80 homepage = "https://github.com/explosion/spacy-models";
81 license = licenses.${license};
85 makeModelSet = models: with lib; listToAttrs (map (m: nameValuePair m.pname (buildModelPackage m)) models);
88 makeModelSet (lib.importJSON ./models.json)