···
# the lindera-unidic v0.32.2 crate uses [1] an outdated unidic-mecab fork [2] and builds it in pure rust
# [1] https://github.com/lindera/lindera/blob/v0.32.2/lindera-unidic/build.rs#L5-L11
# [2] https://github.com/lindera/unidic-mecab
26
-
lindera-unidic-src = fetchurl {
27
-
url = "https://dlwqk3ibdg1xh.cloudfront.net/unidic-mecab-2.1.2.tar.gz";
28
-
hash = "sha256-JKx1/k5E2XO1XmWEfDX6Suwtt6QaB7ScoSUUbbn8EYk=";
26
+
# To find these urls:
27
+
# rg -A5 download_urls $(nix-build . -A pagefind.cargoDeps --no-out-link)/lindera-*/build.rs
29
+
unidic-mecab = fetchurl {
30
+
passthru.vendorDir = "lindera-unidic-*";
31
+
url = "https://Lindera.dev/unidic-mecab-2.1.2.tar.gz";
32
+
hash = "sha256-JKx1/k5E2XO1XmWEfDX6Suwtt6QaB7ScoSUUbbn8EYk=";
34
+
mecab-ko-dic = fetchurl {
35
+
passthru.vendorDir = "lindera-ko-dic-*";
36
+
url = "https://Lindera.dev/mecab-ko-dic-2.1.1-20180720.tar.gz";
37
+
hash = "sha256-cCztIcYWfp2a68Z0q17lSvWNREOXXylA030FZ8AgWRo=";
40
+
passthru.vendorDir = "lindera-ipadic-0.*";
41
+
url = "https://Lindera.dev/mecab-ipadic-2.7.0-20070801.tar.gz";
42
+
hash = "sha256-CZ5G6A1V58DWkGeDr/cTdI4a6Q9Gxe+W7BU7vwm/VVA=";
44
+
cc-cedict = fetchurl {
45
+
passthru.vendorDir = "lindera-cc-cedict-*";
46
+
url = "https://lindera.dev/CC-CEDICT-MeCab-0.1.0-20200409.tar.gz";
47
+
hash = "sha256-7Tz54+yKgGR/DseD3Ana1DuMytLplPXqtv8TpB0JFsg=";
49
+
ipadic-neologd = fetchurl {
50
+
passthru.vendorDir = "lindera-ipadic-neologd-*";
51
+
url = "https://lindera.dev/mecab-ipadic-neologd-0.0.7-20200820.tar.gz";
52
+
hash = "sha256-1VwCwgSTKFixeQUFVCdqMzZKne/+FTgM56xT7etqjqI=";
33
-
rustPlatform.buildRustPackage rec {
58
+
rustPlatform.buildRustPackage (finalAttrs: {
38
-
owner = "cloudcannon";
40
-
tag = "v${version}";
41
-
hash = "sha256-NIEiXwuy8zuUDxPsD4Hiq3x4cOG3VM+slfNIBSJU2Mk=";
65
+
tag = "v${finalAttrs.version}";
66
+
hash = "sha256-+jArZueDqpJQKg3fKdJjeQQL+egyR6Zi6wqPMZoFgyk=";
44
-
cargoHash = "sha256-e1JSK8RnBPGcAmgxJZ7DaYhMMaUqO412S9YvaqXll3E=";
69
+
cargoPatches = [ ./cargo-lock.patch ];
70
+
cargoHash = "sha256-zbo8NkB9umpNDvkhKXpOdt8hJn+d+nrTXMaUghmIPrg=";
72
+
env.cargoDeps_web = rustPlatform.fetchCargoVendor {
73
+
name = "cargo-deps-web-${finalAttrs.version}";
74
+
inherit (finalAttrs) src;
75
+
sourceRoot = "${finalAttrs.src.name}/pagefind_web";
76
+
hash = "sha256-DaipINtwePA03YdbSzh6EjH4Q13P3CB9lwcmTOR54dM=";
env.npmDeps_web_js = fetchNpmDeps {
47
-
name = "npm-deps-web-js";
48
-
src = "${src}/pagefind_web_js";
49
-
hash = "sha256-1gdVBCxxLEGFihIxoSSgxw/tMyVgwe7HFG/JjEfYVnQ=";
79
+
name = "pagefind-npm-deps-web-js-${finalAttrs.version}";
80
+
inherit (finalAttrs) src;
81
+
sourceRoot = "${finalAttrs.src.name}/pagefind_web_js";
82
+
hash = "sha256-whpmjNKdiMxNfg7fRIWUPdyRWqsEphhqvQfiM65GYDs=";
env.npmDeps_ui_default = fetchNpmDeps {
52
-
name = "npm-deps-ui-default";
53
-
src = "${src}/pagefind_ui/default";
85
+
name = "pagefind-npm-deps-ui-default-${finalAttrs.version}";
86
+
inherit (finalAttrs) src;
87
+
sourceRoot = "${finalAttrs.src.name}/pagefind_ui/default";
hash = "sha256-voCs49JneWYE1W9U7aB6G13ypH6JqathVDeF58V57U8=";
env.npmDeps_ui_modular = fetchNpmDeps {
57
-
name = "npm-deps-ui-modular";
58
-
src = "${src}/pagefind_ui/modular";
59
-
hash = "sha256-O0RqZUsRFtByxMQdwNGNcN38Rh+sDqqNo9YlBcrnsF4=";
91
+
name = "pagefind-npm-deps-ui-modular-${finalAttrs.version}";
92
+
inherit (finalAttrs) src;
93
+
sourceRoot = "${finalAttrs.src.name}/pagefind_ui/modular";
94
+
hash = "sha256-4d85V2X1doq3G8okgYSXOMuQDoAXCgtAtegFEPr+Wno=";
61
-
env.cargoDeps_web = rustPlatform.fetchCargoVendor {
62
-
name = "cargo-deps-web";
63
-
src = "${src}/pagefind_web/";
64
-
hash = "sha256-xFVMWX3q3za1w8v58Eysk6vclPd4qpCuQMjMcwwHoh0=";
96
+
env.npmDeps_playground = fetchNpmDeps {
97
+
name = "pagefind-npm-deps-playground-${finalAttrs.version}";
98
+
inherit (finalAttrs) src;
99
+
sourceRoot = "${finalAttrs.src.name}/pagefind_playground";
100
+
hash = "sha256-npo8MV6AAuQ/mGC9iu3bR7pjGoI7NgxuIeh+H3oz7Y8=";
67
-
env.GIT_VERSION = version;
103
+
env.GIT_VERSION = finalAttrs.version;
# Set the correct version, e.g. for `pagefind --version`
node .backstage/version.cjs
109
+
# Tricky way to run the cargo setup a second time
112
+
cargoDeps=$cargoDeps_web cargoSetupPostUnpackHook
113
+
cargoDeps=$cargoDeps_web cargoSetupPostPatchHook
# Tricky way to run npmConfigHook multiple times
local postPatchHooks=() # written to by npmConfigHook
···
npmRoot=pagefind_web_js npmDeps=$npmDeps_web_js npmConfigHook
npmRoot=pagefind_ui/default npmDeps=$npmDeps_ui_default npmConfigHook
npmRoot=pagefind_ui/modular npmDeps=$npmDeps_ui_modular npmConfigHook
83
-
cargoDeps=$cargoDeps_web cargoSetupPostUnpackHook
84
-
cargoDeps=$cargoDeps_web cargoSetupPostPatchHook
123
+
npmRoot=pagefind_playground npmDeps=$npmDeps_playground npmConfigHook
87
-
# patch a build-time dependency download
126
+
# patch build-time dependency downloads
89
-
patch -d $cargoDepsCopy/lindera-assets-*/ -p1 < ${./lindera-assets-support-file-paths.patch}
128
+
# add support for file:// urls
129
+
patch -d $cargoDepsCopy/lindera-dictionary-*/ -p1 < ${./lindera-dictionary-support-file-paths.patch}
91
-
substituteInPlace $cargoDepsCopy/lindera-unidic-*/build.rs --replace-fail \
92
-
"${lindera-unidic-src.url}" \
93
-
"file://${lindera-unidic-src}"
132
+
${lib.pipe finalAttrs.passthru.lindera-srcs [
133
+
(lib.mapAttrsToList (
135
+
# compgen is only in bashInteractive
136
+
declare -a expanded_glob=($cargoDepsCopy/${src.vendorDir}/build.rs)
137
+
if [[ "''${#expanded_glob[@]}" -eq 0 ]]; then
138
+
echo >&2 "ERROR: '$cargoDepsCopy/${src.vendorDir}/build.rs' not found! (pagefind.passthru.lindera-srcs.${key})"
140
+
elif [[ "''${#expanded_glob[@]}" -gt 1 ]]; then
141
+
echo >&2 "ERROR: '$cargoDepsCopy/${src.vendorDir}/build.rs' matches more than one file! (pagefind.passthru.lindera-srcs.${key})"
142
+
printf >&2 "match: %s\n" "''${expanded_glob[@]}"
145
+
echo "patching $cargoDepsCopy/${src.vendorDir}/build.rs..."
146
+
substituteInPlace $cargoDepsCopy/${src.vendorDir}/build.rs --replace-fail "${src.url}" "file://${src}"
147
+
unset expanded_glob
154
+
# nightly-only feature
155
+
substituteInPlace pagefind_web/local_build.sh \
156
+
--replace-fail ' -Z build-std=panic_abort,std' "" \
157
+
--replace-fail ' -Z build-std-features=panic_immediate_abort' ""
__darwinAllowLocalNetworking = true;
···
117
-
echo entering pagefind_web_js...
180
+
echo Entering ./pagefind_web_js
123
-
echo entering pagefind_web...
186
+
echo Entering ./pagefind_web
129
-
echo entering pagefind_ui/default...
192
+
echo Entering ./pagefind_ui/default
135
-
echo entering pagefind_ui/modular...
198
+
echo Entering ./pagefind_ui/modular
204
+
echo Entering ./pagefind_playground
206
+
cd pagefind_playground
211
+
# always build extended
buildFeatures = [ "extended" ];
···
221
+
inherit lindera-srcs;
222
+
tests.non-extended = finalAttrs.finalPackage.overrideAttrs {
223
+
buildFeatures = [ ];
description = "Generate low-bandwidth search index for your static website";
homepage = "https://pagefind.app/";
230
+
changelog = "https://github.com/Pagefind/pagefind/releases/tag/v${finalAttrs.version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ pbsds ];
platforms = lib.platforms.unix;
mainProgram = "pagefind";