diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..908bdd1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1793110635, + "narHash": "sha256-dhoW6VgFWlaodSY5jrBn+CF2FLmaUvDVgM7+C7T2+NM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "31ecbaca1bdefa45dffc409f0250bd8039ea0010", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e127e23 --- /dev/null +++ b/flake.nix @@ -0,0 +1,72 @@ +{ + description = "typesense-python development shell"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + in + { + devShells = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + + # Starts a local server configured like the one in CI, which the test suite expects. + typesense-dev = pkgs.writeShellApplication { + name = "typesense-dev"; + runtimeInputs = [ pkgs.typesense ]; + text = '' + root="''${TYPESENSE_DEV_DIR:-$PWD/.typesense}" + mkdir -p "$root/data" "$root/analytics" + exec typesense-server \ + --api-key=xyz \ + --data-dir="$root/data" \ + --enable-search-analytics=true \ + --analytics-dir="$root/analytics" \ + --analytics-flush-interval=60 \ + --analytics-minute-rate-limit=50 \ + --enable-cors \ + "$@" + ''; + }; + + mkShell = + python: + pkgs.mkShell { + packages = [ + python + pkgs.uv + pkgs.typesense + typesense-dev + ]; + + env = { + # Keep uv on the interpreter from this shell instead of fetching its own. + UV_PYTHON = python.interpreter; + UV_PYTHON_DOWNLOADS = "never"; + }; + + shellHook = '' + unset PYTHONPATH + ''; + }; + in + { + default = mkShell pkgs.python313; + py311 = mkShell pkgs.python311; + py312 = mkShell pkgs.python312; + py313 = mkShell pkgs.python313; + } + ); + }; +}