nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 158 lines 4.0 kB view raw
1{ 2 lib, 3 stdenv, 4 rustPlatform, 5 fetchFromGitHub, 6 fetchNpmDeps, 7 fetchurl, 8 binaryen, 9 gzip, 10 nodejs, 11 npmHooks, 12 python3, 13 rustc, 14 versionCheckHook, 15 wasm-bindgen-cli_0_2_92, 16 wasm-pack, 17}: 18 19# TODO: package python bindings 20 21let 22 23 # the lindera-unidic v0.32.2 crate uses [1] an outdated unidic-mecab fork [2] and builds it in pure rust 24 # [1] https://github.com/lindera/lindera/blob/v0.32.2/lindera-unidic/build.rs#L5-L11 25 # [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="; 29 }; 30 31in 32 33rustPlatform.buildRustPackage rec { 34 pname = "pagefind"; 35 version = "1.3.0"; 36 37 src = fetchFromGitHub { 38 owner = "cloudcannon"; 39 repo = "pagefind"; 40 tag = "v${version}"; 41 hash = "sha256-NIEiXwuy8zuUDxPsD4Hiq3x4cOG3VM+slfNIBSJU2Mk="; 42 }; 43 44 cargoHash = "sha256-e1JSK8RnBPGcAmgxJZ7DaYhMMaUqO412S9YvaqXll3E="; 45 46 env.npmDeps_web_js = fetchNpmDeps { 47 name = "npm-deps-web-js"; 48 src = "${src}/pagefind_web_js"; 49 hash = "sha256-1gdVBCxxLEGFihIxoSSgxw/tMyVgwe7HFG/JjEfYVnQ="; 50 }; 51 env.npmDeps_ui_default = fetchNpmDeps { 52 name = "npm-deps-ui-default"; 53 src = "${src}/pagefind_ui/default"; 54 hash = "sha256-voCs49JneWYE1W9U7aB6G13ypH6JqathVDeF58V57U8="; 55 }; 56 env.npmDeps_ui_modular = fetchNpmDeps { 57 name = "npm-deps-ui-modular"; 58 src = "${src}/pagefind_ui/modular"; 59 hash = "sha256-O0RqZUsRFtByxMQdwNGNcN38Rh+sDqqNo9YlBcrnsF4="; 60 }; 61 env.cargoDeps_web = rustPlatform.fetchCargoVendor { 62 name = "cargo-deps-web"; 63 src = "${src}/pagefind_web/"; 64 hash = "sha256-xFVMWX3q3za1w8v58Eysk6vclPd4qpCuQMjMcwwHoh0="; 65 }; 66 67 env.GIT_VERSION = version; 68 69 postPatch = '' 70 # Set the correct version, e.g. for `pagefind --version` 71 node .backstage/version.cjs 72 73 # Tricky way to run npmConfigHook multiple times 74 ( 75 local postPatchHooks=() # written to by npmConfigHook 76 source ${npmHooks.npmConfigHook}/nix-support/setup-hook 77 npmRoot=pagefind_web_js npmDeps=$npmDeps_web_js npmConfigHook 78 npmRoot=pagefind_ui/default npmDeps=$npmDeps_ui_default npmConfigHook 79 npmRoot=pagefind_ui/modular npmDeps=$npmDeps_ui_modular npmConfigHook 80 ) 81 ( 82 cd pagefind_web 83 cargoDeps=$cargoDeps_web cargoSetupPostUnpackHook 84 cargoDeps=$cargoDeps_web cargoSetupPostPatchHook 85 ) 86 87 # patch a build-time dependency download 88 ( 89 patch -d $cargoDepsCopy/lindera-assets-*/ -p1 < ${./lindera-assets-support-file-paths.patch} 90 91 substituteInPlace $cargoDepsCopy/lindera-unidic-*/build.rs --replace-fail \ 92 "${lindera-unidic-src.url}" \ 93 "file://${lindera-unidic-src}" 94 ) 95 ''; 96 97 __darwinAllowLocalNetworking = true; 98 99 nativeBuildInputs = [ 100 binaryen 101 gzip 102 nodejs 103 rustc 104 rustc.llvmPackages.lld 105 wasm-bindgen-cli_0_2_92 106 wasm-pack 107 ] 108 ++ lib.optionals stdenv.buildPlatform.isDarwin [ 109 python3 110 ]; 111 112 # build wasm and js assets 113 # based on "test-and-build" in https://github.com/CloudCannon/pagefind/blob/main/.github/workflows/release.yml 114 preBuild = '' 115 export HOME=$(mktemp -d) 116 117 echo entering pagefind_web_js... 118 ( 119 cd pagefind_web_js 120 npm run build-coupled 121 ) 122 123 echo entering pagefind_web... 124 ( 125 cd pagefind_web 126 bash ./local_build.sh 127 ) 128 129 echo entering pagefind_ui/default... 130 ( 131 cd pagefind_ui/default 132 npm run build 133 ) 134 135 echo entering pagefind_ui/modular... 136 ( 137 cd pagefind_ui/modular 138 npm run build 139 ) 140 ''; 141 142 buildFeatures = [ "extended" ]; 143 144 doInstallCheck = true; 145 146 nativeInstallCheckInputs = [ 147 versionCheckHook 148 ]; 149 150 meta = { 151 description = "Generate low-bandwidth search index for your static website"; 152 homepage = "https://pagefind.app/"; 153 license = lib.licenses.mit; 154 maintainers = with lib.maintainers; [ pbsds ]; 155 platforms = lib.platforms.unix; 156 mainProgram = "pagefind"; 157 }; 158}