21 wasm-bindgen-92 = wasm-bindgen-cli.override {
23 hash = "sha256-1VwY8vQy7soKEgbki4LD+v259751kKxSxmo/gqE6yV0=";
24 cargoHash = "sha256-aACJ+lYNEU8FFBs158G1/JG8sc6Rq080PeKCMnwdpH0=";
27 # the lindera-unidic v0.32.2 crate uses [1] an outdated unidic-mecab fork [2] and builds it in pure rust
28 # [1] https://github.com/lindera/lindera/blob/v0.32.2/lindera-unidic/build.rs#L5-L11
29 # [2] https://github.com/lindera/unidic-mecab
30 lindera-unidic-src = fetchurl {
31 url = "https://dlwqk3ibdg1xh.cloudfront.net/unidic-mecab-2.1.2.tar.gz";
32 hash = "sha256-JKx1/k5E2XO1XmWEfDX6Suwtt6QaB7ScoSUUbbn8EYk=";
37 rustPlatform.buildRustPackage rec {
41 src = fetchFromGitHub {
42 owner = "cloudcannon";
44 rev = "refs/tags/v${version}";
45 hash = "sha256-4NfosDp5Wwz2lnqaFNcaIbWpjWiaQ4WCL6TcKEkfPck=";
48 cargoHash = "sha256-hnT9w3j8/YuN00x0LBPr75BKGWSnIYUNFTWIgtghJP4";
50 env.npmDeps_web_js = fetchNpmDeps {
51 name = "npm-deps-web-js";
52 src = "${src}/pagefind_web_js";
53 hash = "sha256-1gdVBCxxLEGFihIxoSSgxw/tMyVgwe7HFG/JjEfYVnQ=";
55 env.npmDeps_ui_default = fetchNpmDeps {
56 name = "npm-deps-ui-default";
57 src = "${src}/pagefind_ui/default";
58 hash = "sha256-voCs49JneWYE1W9U7aB6G13ypH6JqathVDeF58V57U8=";
60 env.npmDeps_ui_modular = fetchNpmDeps {
61 name = "npm-deps-ui-modular";
62 src = "${src}/pagefind_ui/modular";
63 hash = "sha256-O0RqZUsRFtByxMQdwNGNcN38Rh+sDqqNo9YlBcrnsF4=";
65 env.cargoDeps_web = rustPlatform.fetchCargoTarball {
66 name = "cargo-deps-web";
67 src = "${src}/pagefind_web/";
68 hash = "sha256-vDkVXyDePKgYTYE5ZTLLfOHwPYfgaqP9p5/fKCQQi0g=";
72 # Tricky way to run npmConfigHook multiple times
74 local postPatchHooks=() # written to by npmConfigHook
75 source ${npmHooks.npmConfigHook}/nix-support/setup-hook
76 npmRoot=pagefind_web_js npmDeps=$npmDeps_web_js npmConfigHook
77 npmRoot=pagefind_ui/default npmDeps=$npmDeps_ui_default npmConfigHook
78 npmRoot=pagefind_ui/modular npmDeps=$npmDeps_ui_modular npmConfigHook
82 cargoDeps=$cargoDeps_web cargoSetupPostUnpackHook
83 cargoDeps=$cargoDeps_web cargoSetupPostPatchHook
86 # patch a build-time dependency download
88 cd $cargoDepsCopy/lindera-unidic
89 oldHash=$(sha256sum build.rs | cut -d " " -f 1)
91 # serve lindera-unidic on localhost vacant port
93 if stdenv.buildPlatform.isDarwin then
94 ''$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')''
98 mkdir .lindera-http-plz
99 ln -s ${lindera-unidic-src} .lindera-http-plz/unidic-mecab-2.1.2.tar.gz
100 httplz --port "$httplz_port" -- .lindera-http-plz/ &
101 echo $! >$TMPDIR/.httplz_pid
103 # file:// does not work
104 substituteInPlace build.rs --replace-fail \
105 "https://dlwqk3ibdg1xh.cloudfront.net/unidic-mecab-2.1.2.tar.gz" \
106 "http://localhost:$httplz_port/unidic-mecab-2.1.2.tar.gz"
108 newHash=$(sha256sum build.rs | cut -d " " -f 1)
109 substituteInPlace .cargo-checksum.json --replace-fail $oldHash $newHash
113 __darwinAllowLocalNetworking = true;
121 rustc.llvmPackages.lld
126 ++ lib.optionals stdenv.buildPlatform.isDarwin [
130 # build wasm and js assets
131 # based on "test-and-build" in https://github.com/CloudCannon/pagefind/blob/main/.github/workflows/release.yml
133 export HOME=$(mktemp -d)
135 echo entering pagefind_web_js...
138 npm run build-coupled
141 echo entering pagefind_web...
144 bash ./local_build.sh
147 echo entering pagefind_ui/default...
149 cd pagefind_ui/default
153 echo entering pagefind_ui/modular...
155 cd pagefind_ui/modular
160 # the file is also fetched during checkPhase
162 kill ${lib.optionalString stdenv.hostPlatform.isDarwin "-9"} $(cat $TMPDIR/.httplz_pid)
165 buildFeatures = [ "extended" ];
168 description = "Generate low-bandwidth search index for your static website";
169 homepage = "https://pagefind.app/";
170 license = lib.licenses.mit;
171 maintainers = with lib.maintainers; [ pbsds ];
172 platforms = lib.platforms.unix;
173 mainProgram = "pagefind";