From 744d3b4abb0109b4d86806f968ff8e154b30e847 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Mon, 18 Mar 2024 15:02:50 -0500 Subject: [PATCH 1/3] nix: add example on how to use a local library --- nix/README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/nix/README.md b/nix/README.md index c0fab204ea..94804b1fd5 100644 --- a/nix/README.md +++ b/nix/README.md @@ -302,6 +302,55 @@ ghci> decodeMediaType "application/json" MTApplicationJSON ``` +## Working with locally modified Haskell packages + +Sometimes, we need to modify Haskell libraries in order to debug them or enhance them. +For example, if you want to debug the [`hasql-pool`](https://hackage.haskell.org/package/hasql-pool) +library: + +First, copy the package to the repo root. We'll use GitHub in this example. + +```bash +$ git clone --depth=1 --branch=0.10.1 https://github.com/nikita-volkov/hasql-pool.git +$ rm -rf ./hasql-pool/.git +``` + +Then, pin the local package to the [`haskell-packages.nix`](./overlays/haskell-packages.nix) file. + +```nix + overrides = + # ... + rec { + + # Different subpath may be needed if the cabal file is not in the library's base directory + hasql-pool = lib.dontCheck + (prev.callCabal2nixWithOptions "hasql-pool" ../../hasql-pool "--subpath=." {} ); + + }; +``` + +Next, both [`cabal.project`](/cabal.project) and [`stack.yaml`](/stack.yaml) need to be updated +with the local library: + +```cabal +-- cabal.project +packages: + ./hasql-pool/hasql-pool.cabal +``` + +```yaml +# stack.yaml +extra-deps: + - ./hasql-pool/hasql-pool.cabal +``` + +Lastly, run `nix-shell` to build the local package. You don't need to exit and +enter the Nix shell every time you modify the library's code, re-executing +`postgrest-run` should be enough. + +This is done for development purposes only. Local libraries must not be left +in production ready code. + ## Tour The following is not required for working on PostgREST with Nix, but it will From 249527bfaacc8a78a0ffd8375bf0c13988b45b6c Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Mon, 25 Mar 2024 19:24:40 -0500 Subject: [PATCH 2/3] add note to the overlay file --- nix/overlays/haskell-packages.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nix/overlays/haskell-packages.nix b/nix/overlays/haskell-packages.nix index 77c9a29ca5..6bc3265602 100644 --- a/nix/overlays/haskell-packages.nix +++ b/nix/overlays/haskell-packages.nix @@ -34,6 +34,11 @@ let # - If the library fails its test suite (usually when it runs IO tests), wrap the expression with `lib.dontCheck ()` # - is usually "." # - When adding a new library version here, postgrest.cabal and stack.yaml must also be updated + # + # Note: + # - This should NOT be the first place to start managing dependencies. Check package.cabal and stack.yaml first. + # - To modify and try packages locally, see "Working with locally modified Haskell packages" in the Nix README. + # configurator-pg = From 8948455a47ca87cd0e00c781b3f3f07fbb9716f0 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Tue, 26 Mar 2024 11:05:32 -0500 Subject: [PATCH 3/3] Update nix/overlays/haskell-packages.nix Co-authored-by: Wolfgang Walther --- nix/overlays/haskell-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/overlays/haskell-packages.nix b/nix/overlays/haskell-packages.nix index 6bc3265602..f21de41ac7 100644 --- a/nix/overlays/haskell-packages.nix +++ b/nix/overlays/haskell-packages.nix @@ -36,7 +36,7 @@ let # - When adding a new library version here, postgrest.cabal and stack.yaml must also be updated # # Note: - # - This should NOT be the first place to start managing dependencies. Check package.cabal and stack.yaml first. + # - This should NOT be the first place to start managing dependencies. Check postgrest.cabal. # - To modify and try packages locally, see "Working with locally modified Haskell packages" in the Nix README. #