|
| 1 | +{ |
| 2 | + inputs = { |
| 3 | + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; |
| 4 | + rust.url = "github:oxalica/rust-overlay"; |
| 5 | + foundry.url = "github:shazow/foundry.nix/stable"; |
| 6 | + process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; |
| 7 | + services-flake.url = "github:juspay/services-flake"; |
| 8 | + flake-parts.url = "github:hercules-ci/flake-parts"; |
| 9 | + }; |
| 10 | + |
| 11 | + outputs = inputs@{ flake-parts, process-compose-flake, services-flake, nixpkgs, rust, foundry, ... }: |
| 12 | + flake-parts.lib.mkFlake { inherit inputs; } { |
| 13 | + imports = [ process-compose-flake.flakeModule ]; |
| 14 | + systems = [ |
| 15 | + "x86_64-linux" # 64-bit Intel/AMD Linux |
| 16 | + "aarch64-linux" # 64-bit ARM Linux |
| 17 | + "x86_64-darwin" # 64-bit Intel macOS |
| 18 | + "aarch64-darwin" # 64-bit ARM macOS |
| 19 | + ]; |
| 20 | + |
| 21 | + perSystem = { config, self', inputs', pkgs, system, ... }: |
| 22 | + let |
| 23 | + overlays = [ |
| 24 | + (import rust) |
| 25 | + (self: super: { |
| 26 | + rust-toolchain = super.rust-bin.stable.latest.default; |
| 27 | + }) |
| 28 | + foundry.overlay |
| 29 | + ]; |
| 30 | + |
| 31 | + pkgsWithOverlays = import nixpkgs { |
| 32 | + inherit overlays system; |
| 33 | + }; |
| 34 | + in { |
| 35 | + devShells.default = pkgsWithOverlays.mkShell { |
| 36 | + packages = (with pkgsWithOverlays; [ |
| 37 | + # Includes cargo, clippy, cargo-fmt, rustdoc, rustfmt, and other tools. |
| 38 | + rust-toolchain |
| 39 | + foundry-bin |
| 40 | + solc |
| 41 | + bun |
| 42 | + protobuf |
| 43 | + uv |
| 44 | + cmake |
| 45 | + corepack |
| 46 | + nodejs |
| 47 | + postgresql |
| 48 | + ]); |
| 49 | + }; |
| 50 | + |
| 51 | + process-compose = let |
| 52 | + inherit (services-flake.lib) multiService; |
| 53 | + ipfs = multiService ./nix/ipfs.nix; |
| 54 | + anvil = multiService ./nix/anvil.nix; |
| 55 | + |
| 56 | + # Helper function to create postgres configuration with graph-specific defaults |
| 57 | + mkPostgresConfig = { name, port, user, password, database, dataDir }: { |
| 58 | + enable = true; |
| 59 | + inherit port dataDir; |
| 60 | + initialScript = { |
| 61 | + before = '' |
| 62 | + CREATE USER \"${user}\" WITH PASSWORD '${password}' SUPERUSER; |
| 63 | + ''; |
| 64 | + }; |
| 65 | + initialDatabases = [ |
| 66 | + { |
| 67 | + inherit name; |
| 68 | + schemas = [ (pkgsWithOverlays.writeText "init-${name}.sql" '' |
| 69 | + CREATE EXTENSION IF NOT EXISTS pg_trgm; |
| 70 | + CREATE EXTENSION IF NOT EXISTS btree_gist; |
| 71 | + CREATE EXTENSION IF NOT EXISTS postgres_fdw; |
| 72 | + CREATE EXTENSION IF NOT EXISTS pg_stat_statements; |
| 73 | + GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw TO "${user}"; |
| 74 | + ALTER DATABASE "${database}" OWNER TO "${user}"; |
| 75 | + '') ]; |
| 76 | + } |
| 77 | + ]; |
| 78 | + settings = { |
| 79 | + shared_preload_libraries = "pg_stat_statements"; |
| 80 | + log_statement = "all"; |
| 81 | + default_text_search_config = "pg_catalog.english"; |
| 82 | + max_connections = 200; |
| 83 | + }; |
| 84 | + }; |
| 85 | + in { |
| 86 | + # Unit tests configuration |
| 87 | + unit-tests = { |
| 88 | + imports = [ |
| 89 | + services-flake.processComposeModules.default |
| 90 | + ipfs |
| 91 | + anvil |
| 92 | + ]; |
| 93 | + |
| 94 | + services.postgres."postgres-unit" = mkPostgresConfig { |
| 95 | + name = "graph-test"; |
| 96 | + port = 5432; |
| 97 | + dataDir = "./.data/unit/postgres"; |
| 98 | + user = "graph"; |
| 99 | + password = "graph"; |
| 100 | + database = "graph-test"; |
| 101 | + }; |
| 102 | + |
| 103 | + services.ipfs."ipfs-unit" = { |
| 104 | + enable = true; |
| 105 | + dataDir = "./.data/unit/ipfs"; |
| 106 | + apiPort = 5001; |
| 107 | + gatewayPort = 8080; |
| 108 | + swarmPort = 4001; |
| 109 | + }; |
| 110 | + }; |
| 111 | + |
| 112 | + # Integration tests configuration |
| 113 | + integration-tests = { |
| 114 | + imports = [ |
| 115 | + services-flake.processComposeModules.default |
| 116 | + ipfs |
| 117 | + anvil |
| 118 | + ]; |
| 119 | + |
| 120 | + services.postgres."postgres-integration" = mkPostgresConfig { |
| 121 | + name = "graph-node"; |
| 122 | + port = 3011; |
| 123 | + dataDir = "./.data/integration/postgres"; |
| 124 | + user = "graph-node"; |
| 125 | + password = "let-me-in"; |
| 126 | + database = "graph-node"; |
| 127 | + }; |
| 128 | + |
| 129 | + services.ipfs."ipfs-integration" = { |
| 130 | + enable = true; |
| 131 | + dataDir = "./.data/integration/ipfs"; |
| 132 | + apiPort = 3001; |
| 133 | + gatewayPort = 3002; |
| 134 | + swarmPort = 4001; |
| 135 | + }; |
| 136 | + |
| 137 | + services.anvil."anvil-integration" = { |
| 138 | + enable = true; |
| 139 | + package = pkgsWithOverlays.foundry-bin; |
| 140 | + port = 3021; |
| 141 | + host = "127.0.0.1"; |
| 142 | + gasLimit = "100000000000"; |
| 143 | + baseFee = 1; |
| 144 | + blockTime = 2; |
| 145 | + timestamp = 1743944919; |
| 146 | + mnemonic = "test test test test test test test test test test test junk"; |
| 147 | + accounts = 10; |
| 148 | + }; |
| 149 | + }; |
| 150 | + }; |
| 151 | + }; |
| 152 | + }; |
| 153 | +} |
0 commit comments