Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(nix): add support for running external services through services-flake (#6377)
Kashif95f2e0b8c51b
diff --git a/.gitignore b/.gitignoreindex 1aa3faf2c1..1209263db3 100644--- a/.gitignore+++ b/.gitignore@@ -263,4 +263,9 @@ result*node_modules/# cypress credentials-creds.json\ No newline at end of file+creds.json++/.direnv++# Nix services data+/data\ No newline at end of filediff --git a/docs/try_local_system.md b/docs/try_local_system.mdindex a9c5e81138..07756463e7 100644--- a/docs/try_local_system.md+++ b/docs/try_local_system.md@@ -15,6 +15,10 @@ Check the Table Of Contents to jump to the relevant section.- [Run hyperswitch using Docker Compose](#run-hyperswitch-using-docker-compose)- [Running additional services](#running-additional-services)- [Set up a development environment using Docker Compose](#set-up-a-development-environment-using-docker-compose)+- [Set up a Nix development environment](#set-up-a-nix-development-environment)+ - [Install Nix](#install-nix)+ - [Using external services through Nix](#using-external-services-through-nix)+ - [Develop in a Nix environment (coming soon)](#develop-in-a-nix-environment-coming-soon)- [Set up a Rust environment and other dependencies](#set-up-a-rust-environment-and-other-dependencies)- [Set up dependencies on Ubuntu-based systems](#set-up-dependencies-on-ubuntu-based-systems)- [Set up dependencies on Windows (Ubuntu on WSL2)](#set-up-dependencies-on-windows-ubuntu-on-wsl2)@@ -166,6 +170,43 @@ Once the services have been confirmed to be up and running, you can proceed withIf the command returned a `200 OK` status code, proceed with[trying out our APIs](#try-out-our-apis).+## Set up a Nix development environment++A Nix development environment simplifies the setup of required project dependencies. This is available for MacOS, Linux and WSL2 users.++### Install nix++We recommend that you install Nix using [the DetSys nix-installer][detsys-nixos-installer], which automatically enables flakes.++As an **optional** next step, if you are interested in using Nix to manage your dotfiles and local packages, you can setup [nixos-unified-template][nixos-unified-template-repo].++### Using external services through Nix++Once Nix is installed, you can use it to manage external services via `flakes`. More services will be added soon.++- Run below command in hyperswitch directory++ ```shell+ nix run .#ext-services+ ```++This will start the following services using `process-compose`+- PostgreSQL+ - Creates database and an user to be used by the application+- Redis++### Develop in a Nix environment (coming soon)++Nix development environment ensures all the required project dependencies, including both the tools and services are readily available, eliminating the need for manual setup.++Run below command in hyperswitch directory++ ```shell+ nix develop+ ```++**NOTE:** This is a work in progress, and only a selected commands are available at the moment. Look in `flake.nix` (hyperswitch-shell) for a full list of packages.+## Set up a Rust environment and other dependenciesIf you are using `nix`, please skip the setup dependencies step and jump to@@ -681,3 +722,5 @@ To explore more of our APIs, please check the remaining folders in the[refunds-create]: https://www.postman.com/hyperswitch/workspace/hyperswitch-development/request/25176162-4d1315c6-ac61-4411-8f7d-15d4e4e736a1[refunds-retrieve]: https://www.postman.com/hyperswitch/workspace/hyperswitch-development/request/25176162-137d6260-24f7-4752-9e69-26b61b83df0d[connector-specific-details]: https://docs.google.com/spreadsheets/d/e/2PACX-1vQWHLza9m5iO4Ol-tEBx22_Nnq8Mb3ISCWI53nrinIGLK8eHYmHGnvXFXUXEut8AFyGyI9DipsYaBLG/pubhtml?gid=748960791&single=true+[detsys-nixos-installer]: https://nixos.asia/en/install+[nixos-unified-template-repo]: https://github.com/juspay/nixos-unified-template#on-non-nixosdiff --git a/flake.lock b/flake.lockindex 6f95510847..6bdae43576 100644--- a/flake.lock+++ b/flake.lock@@ -107,11 +107,11 @@},"nixpkgs_2": {"locked": {- "lastModified": 1676569297,- "narHash": "sha256-2n4C4H3/U+3YbDrQB6xIw7AaLdFISCCFwOkcETAigqU=",+ "lastModified": 1728888510,+ "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=","owner": "NixOS","repo": "nixpkgs",- "rev": "ac1f5b72a9e95873d1de0233fddcb56f99884b37",+ "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c","type": "github"},"original": {@@ -137,12 +137,29 @@"type": "github"}},+ "process-compose-flake": {+ "locked": {+ "lastModified": 1728868941,+ "narHash": "sha256-yEMzxZfy+EE9gSqn++SyZeAVHXYupFT8Wyf99Z/CXXU=",+ "owner": "Platonic-Systems",+ "repo": "process-compose-flake",+ "rev": "29301aec92d73c9b075fcfd06a6fb18665bfe6b5",+ "type": "github"+ },+ "original": {+ "owner": "Platonic-Systems",+ "repo": "process-compose-flake",+ "type": "github"+ }+ },"root": {"inputs": {"cargo2nix": "cargo2nix","flake-parts": "flake-parts","nixpkgs": "nixpkgs_2",- "rust-overlay": "rust-overlay_2"+ "process-compose-flake": "process-compose-flake",+ "rust-overlay": "rust-overlay_2",+ "services-flake": "services-flake"}},"rust-overlay": {@@ -187,6 +204,21 @@"repo": "rust-overlay","type": "github"}+ },+ "services-flake": {+ "locked": {+ "lastModified": 1728811751,+ "narHash": "sha256-IrwycNtt6jxJGCi+QJ8Bbzt9flg0vNeGLAR0KBbj4a8=",+ "owner": "juspay",+ "repo": "services-flake",+ "rev": "e9f663036f3b1b1a12b0f136628ef93a8be92443",+ "type": "github"+ },+ "original": {+ "owner": "juspay",+ "repo": "services-flake",+ "type": "github"+ }}},"root": "root",diff --git a/flake.nix b/flake.nixindex ad3de7e660..9516d0c81a 100644--- a/flake.nix+++ b/flake.nix@@ -8,10 +8,14 @@# TODO: Move away from these to https://github.com/juspay/rust-flakecargo2nix.url = "github:cargo2nix/cargo2nix/release-0.11.0";rust-overlay.url = "github:oxalica/rust-overlay";++ process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";+ services-flake.url = "github:juspay/services-flake";};outputs = inputs:inputs.flake-parts.lib.mkFlake { inherit inputs; } {+ imports = [ inputs.process-compose-flake.flakeModule ];systems = inputs.nixpkgs.lib.systems.flakeExposed;perSystem = { self', pkgs, lib, system, ... }:let@@ -27,10 +31,10 @@devShells.default = pkgs.mkShell {name = "hyperswitch-shell";packages = with pkgs; [+ just+ nixdopensslpkg-config- exa- fdrust-bin.stable.${rustVersion}.default] ++ lib.optionals stdenv.isDarwin [# arch might have issue finding these libs.@@ -38,6 +42,36 @@frameworks.Foundation];};++ /* For running external services+ - Redis+ - Postgres+ */+ process-compose."ext-services" =+ let+ developmentToml = lib.importTOML ./config/development.toml;+ databaseName = developmentToml.master_database.dbname;+ databaseUser = developmentToml.master_database.username;+ databasePass = developmentToml.master_database.password;+ in+ {+ imports = [ inputs.services-flake.processComposeModules.default ];+ services.redis."r1".enable = true;+ /* Postgres+ - Create an user and grant all privileges+ - Create a database+ */+ services.postgres."p1" = {+ enable = true;+ initialScript = {+ before = "CREATE USER ${databaseUser} WITH PASSWORD '${databasePass}' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;";+ after = "GRANT ALL PRIVILEGES ON DATABASE ${databaseName} to ${databaseUser};";+ };+ initialDatabases = [+ { name = databaseName; }+ ];+ };+ };};};}