diff options
author | oddlama <oddlama@oddlama.org> | 2023-07-19 00:29:30 +0200 |
---|---|---|
committer | oddlama <oddlama@oddlama.org> | 2023-07-22 16:38:13 +0200 |
commit | 234dd85da0ff4e1bb263adfe035157a0570b1a2e (patch) | |
tree | 4998d4e9c1046c10c4304bb95f7f410cc8ccc1fa /pkgs/servers/search | |
parent | 1211e44d5b89641d47cedbec89dd2210a0a1aca8 (diff) |
nixos/typesense: init at 0.24.1
Diffstat (limited to 'pkgs/servers/search')
-rw-r--r-- | pkgs/servers/search/typesense/default.nix | 64 | ||||
-rw-r--r-- | pkgs/servers/search/typesense/sources.json | 17 | ||||
-rwxr-xr-x | pkgs/servers/search/typesense/update.sh | 42 |
3 files changed, 123 insertions, 0 deletions
diff --git a/pkgs/servers/search/typesense/default.nix b/pkgs/servers/search/typesense/default.nix new file mode 100644 index 0000000000000..b78c5d0838479 --- /dev/null +++ b/pkgs/servers/search/typesense/default.nix @@ -0,0 +1,64 @@ +{ lib +, stdenv +, fetchurl +, autoPatchelfHook +, nixosTests +}: +let + inherit (stdenv.hostPlatform) system; + throwSystem = throw "Unsupported system: ${system}"; + + sources = lib.importJSON ./sources.json; + platform = sources.platforms.${system} or throwSystem; + inherit (sources) version; + inherit (platform) arch hash; +in +stdenv.mkDerivation { + pname = "typesense"; + inherit version; + src = fetchurl { + url = "https://dl.typesense.org/releases/${version}/typesense-server-${version}-${arch}.tar.gz"; + inherit hash; + }; + + nativeBuildInputs = [ + autoPatchelfHook + ]; + + # The tar.gz contains no subdirectory + sourceRoot = "."; + + installPhase = '' + mkdir -p $out/bin + cp $sourceRoot/typesense-server $out/bin + ''; + + passthru = { + tests = { inherit (nixosTests) typesense; }; + updateScript = ./update.sh; + }; + + meta = with lib; { + homepage = "https://typesense.org"; + description = "Typesense is a fast, typo-tolerant search engine for building delightful search experiences."; + license = licenses.gpl3; + # There has been an attempt at building this from source, which were deemed + # unfeasible at the time of writing this (July 2023) for the following reasons. + # - Pre 0.25 would have been possible, but typesense has switched to bazel for 0.25+, + # so the build would break immediately next version + # - The new bazel build has many issues, only some of which were fixable: + # - preBuild requires export LANG="C.UTF-8", since onxxruntime contains a + # unicode file path that is handled incorrectly and otherwise leads to a build failure + # - bazel downloads extensions to the build systems at build time which have + # invalid shebangs that need to be fixed by patching rules_foreign_cc through + # bazel (so a patch in nix that adds a patch to the bazel WORKSPACE) + # - WORKSPACE has to be patched to use system cmake and ninja instead of downloaded toolchains + # - The cmake dependencies that are pulled in via bazel at build time will + # try to download stuff via cmake again, which is not possible in the sandbox. + # This is where I stopped trying for now. + # XXX: retry once typesense has officially released their bazel based build. + sourceProvenance = with sourceTypes; [ binaryNativeCode ]; + platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; + maintainers = with maintainers; [ oddlama ]; + }; +} diff --git a/pkgs/servers/search/typesense/sources.json b/pkgs/servers/search/typesense/sources.json new file mode 100644 index 0000000000000..a4f44552504f3 --- /dev/null +++ b/pkgs/servers/search/typesense/sources.json @@ -0,0 +1,17 @@ +{ + "version": "0.24.1", + "platforms": { + "aarch64-linux": { + "arch": "linux-arm64", + "hash": "sha256-TI/bjGqyEZpGDq1F9MBaDypm5XDTlsw9OGd3lIn7JCI=" + }, + "x86_64-linux": { + "arch": "linux-amd64", + "hash": "sha256-bmvje439QYivV96fjnEXblYJnSk8C916OwVeK2n/QR8=" + }, + "x86_64-darwin": { + "arch": "darwin-amd64", + "hash": "sha256-24odPFqHWQoGXXXDLxvMDjCRu81Y+I5QOdK/KLdeH5o=" + } + } +} diff --git a/pkgs/servers/search/typesense/update.sh b/pkgs/servers/search/typesense/update.sh new file mode 100755 index 0000000000000..c6d733181cd39 --- /dev/null +++ b/pkgs/servers/search/typesense/update.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl jq nix-prefetch common-updater-scripts nix coreutils +# shellcheck shell=bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" + +old_version=$(jq -r ".version" sources.json || echo -n "0.0.1") +version=$(curl -s "https://api.github.com/repos/typesense/typesense/releases/latest" | jq -r ".tag_name") +version="${version#v}" + +if [[ "$old_version" == "$version" ]]; then + echo "Already up to date!" + exit 0 +fi + +declare -A platforms=( + [aarch64-linux]="linux-arm64" + [x86_64-darwin]="darwin-amd64" + [x86_64-linux]="linux-amd64" +) + +sources_tmp="$(mktemp)" +cat <<EOF > "$sources_tmp" +{ + "version": "$version", + "platforms": {} +} +EOF + +for platform in "${!platforms[@]}"; do + arch="${platforms[$platform]}" + url="https://dl.typesense.org/releases/${version}/typesense-server-${version}-${arch}.tar.gz" + sha256hash="$(nix-prefetch-url --type sha256 "$url")" + hash="$(nix hash to-sri --type sha256 "$sha256hash")" + echo "$(jq --arg arch "$arch" \ + --arg platform "$platform" \ + --arg hash "$hash" \ + '.platforms += {($platform): {arch: $arch, hash: $hash}}' \ + "$sources_tmp")" > "$sources_tmp" +done + +cp "$sources_tmp" sources.json |