29 lang = builtins.substring 0 2 pname;
30 requires-protobuf = pname == "fr_dep_news_trf" || pname == "uk_core_news_trf";
33 inherit pname version;
37 url = "https://github.com/explosion/spacy-models/releases/download/${pname}-${version}/${pname}-${version}.tar.gz";
41 propagatedBuildInputs =
43 ++ lib.optionals (lib.hasSuffix "_trf" pname) [ spacy-transformers ]
44 ++ lib.optionals (lang == "ru") [ pymorphy3 ]
45 ++ lib.optionals (lang == "uk") [
49 ++ lib.optionals (lang == "zh") [ spacy-pkuseg ]
50 ++ lib.optionals (pname == "fr_dep_news_trf") [ sentencepiece ];
52 postPatch = lib.optionalString requires-protobuf ''
53 substituteInPlace meta.json \
54 --replace "protobuf<3.21.0" "protobuf"
57 nativeBuildInputs = [ setuptools ] ++ lib.optionals requires-protobuf [ protobuf ];
59 pythonImportsCheck = [ pname ];
61 passthru.updateScript = writeScript "update-spacy-models" ''
72 IFS=. read -r major minor patch <<<"${spacy.version}"
73 spacyVersion="$(echo "$major.$minor.0")"
75 pushd pkgs/development/python-modules/spacy/ || exit
77 jq -r '.[] | .pname' models.json | while IFS= read -r pname; do
78 if [ "$(jq --arg pname "$pname" -r '.[] | select(.pname == $pname) | .version' models.json)" == "$spacyVersion" ]; then
82 newHash="$(nix-prefetch-url "https://github.com/explosion/spacy-models/releases/download/$pname-$spacyVersion/$pname-$spacyVersion.tar.gz")"
83 jq --arg newHash "$newHash" --arg pname "$pname" --arg spacyVersion "$spacyVersion" \
84 '[(.[] | select(.pname != $pname)), (.[] | select(.pname == $pname) | .sha256 = $newHash | .version = $spacyVersion)] | sort_by(.pname)' \
85 models.json | sponge models.json
92 description = "Models for the spaCy NLP library";
93 homepage = "https://github.com/explosion/spacy-models";
94 license = lib.licenses.${license};
99 models: lib.listToAttrs (map (m: lib.nameValuePair m.pname (buildModelPackage m)) models);
101 makeModelSet (lib.importJSON ./models.json)