diff --git a/default.nix b/default.nix index be3cb7382..e18d5010e 100644 --- a/default.nix +++ b/default.nix @@ -122,6 +122,9 @@ rec { cabalTools = pkgs.callPackage nix/tools/cabalTools.nix { inherit devCabalOptions postgrest; }; + withTools = + pkgs.callPackage nix/tools/withTools.nix { inherit cabalTools devCabalOptions postgresqlVersions postgrest; }; + # Development tools. devTools = pkgs.callPackage nix/tools/devTools.nix { inherit tests style devCabalOptions hsie withTools; }; @@ -154,9 +157,6 @@ rec { inherit (pkgs.haskell.packages."${compiler}") hpc-codecov; inherit (pkgs.haskell.packages."${compiler}") weeder; }; - - withTools = - pkgs.callPackage nix/tools/withTools.nix { inherit devCabalOptions postgresqlVersions postgrest; }; } // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux rec { # Static executable. inherit postgrestStatic; diff --git a/nix/README.md b/nix/README.md index 2f67d90b7..a043302fd 100644 --- a/nix/README.md +++ b/nix/README.md @@ -207,6 +207,9 @@ postgrest-loadtest-against master # You can simulate latency client/postgrest and postgrest/database PGRST_DELAY=5ms PGDELAY=5ms postgrest-loadtest +# You can build postgrest directly with cabal for faster iteration +PGRST_BUILD_CABAL=1 postgrest-loadtest + # Produce a markdown report to be used on CI postgrest-loadtest-report ``` diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix index 4f030661e..7557d650c 100644 --- a/nix/tools/cabalTools.nix +++ b/nix/tools/cabalTools.nix @@ -37,7 +37,7 @@ let checkedShellScript { name = "postgrest-run"; - docs = "Run PostgREST after buidling it interactively with cabal-install"; + docs = "Run PostgREST after building it interactively with cabal-install"; args = [ "ARG_LEFTOVERS([PostgREST arguments])" ]; inRootDir = true; withEnv = postgrest.env; diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index c7dceb49b..eba52d606 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -1,6 +1,7 @@ { bash-completion , buildToolbox , cabal-install +, cabalTools , checkedShellScript , curl , devCabalOptions @@ -333,16 +334,23 @@ let export PGRST_SERVER_UNIX_SOCKET="$tmpdir"/postgrest.socket rm -f result - echo -n "Building postgrest... " - nix-build -A postgrestPackage > "$tmpdir"/build.log 2>&1 || { - echo "failed, output:" - cat "$tmpdir"/build.log - exit 1 - } + if [ -z "''${PGRST_BUILD_CABAL:-}" ]; then + echo -n "Building postgrest (nix)... " + nix-build -A postgrestPackage > "$tmpdir"/build.log 2>&1 || { + echo "failed, output:" + cat "$tmpdir"/build.log + exit 1 + } + PGRST_CMD=./result/bin/postgrest + else + echo -n "Building postgrest (cabal)... " + postgrest-build + PGRST_CMD=postgrest-run + fi echo "done." echo -n "Starting postgrest... " - ./result/bin/postgrest ${legacyConfig} > "$tmpdir"/run.log 2>&1 & + $PGRST_CMD ${legacyConfig} > "$tmpdir"/run.log 2>&1 & pid=$! # shellcheck disable=SC2317 cleanup() {