PostgREST / postgrest

REST API for any Postgres database
https://postgrest.org
MIT License
22.65k stars 1k forks source link

dev: should be possible to run `postgrest-style` without rebuilding postgrest and all dependencies #2350

Open robx opened 2 years ago

robx commented 2 years ago

E.g. if I change the hasql dependency via nix/overlays/haskell-packages.nix, I'd like to be able to reformat haskell-packages.nix using nix-shell --run postgrest-style without rebuilding hasql and postgrest. I see no good reason that these should have to be rebuilt, since they're not dependencies.

robx commented 2 years ago

(It might be that it's just that nix-shell --run postgrest-style is not the right way to invoke it -- in that case, I'd like to know how to do it better and for the README to be updated accordingly.)

steve-chavez commented 2 years ago

It might be that it's just that nix-shell --run postgrest-style is not the right way to invoke it

Hm, yeah I usually start the interactive shell with nix-shell and then start working there. In that case postgrest-style won't build the derivation again. Once you get out and in of the shell then the derivation will be built.

An alternative could be installing nixpkgs-fmt globally and run it the same as on postgrest-style:

nixpkgs-fmt .

https://github.com/PostgREST/postgrest/blob/d87b622d64d993a240be9a28b7e6f515a489c161/nix/tools/style.nix#L17-L34

wolfgangwalther commented 1 year ago

I think starting nix-shell and keeping it open while developing is the way to go. I do the same. However, I don't like bash, so I'm using https://github.com/haslersn/any-nix-shell to run zsh instead. This makes nix-shell really nice. The only thing I'm missing so far is auto completion, because that's provided for bash only, so far.

However I'd like to point out that there is another way, too, and that's installing postgrest-style on the host system with something like nix-env -iA style. You can then run postgrest-style from outside nix-shell. You'd only need to make sure to re-install, whenever the command is changed in the repo.

wolfgangwalther commented 1 year ago

As for the issue raised itself: It would still be good if we could only build all the tooling when running nix-shell, but not do the static build, yet. This should only happen after running a separate command, imho. Not sure how to do it, though.

robx commented 1 year ago

I ran into similar trouble today with postgrest-nixpkgs-upgrade, where I had run it a few days back to reach a state where some haskell packages wouldn't build, and couldn't run it again easily without fixing those (now irrelevant) issues first.

With the nix tool (and flakes enabled, not sure if necessary), it's possible to run the tools individually as follows:

$ nix shell -f . style -c postgrest-style
$ nix shell -f . nixpkgsTools -c postgrest-nixpkgs-upgrade

I suppose it's a bit too unwieldy to put in the documentation, but it works for me for now. Maybe at some point we want to add a flake.nix, at which point it would be straightforward to allow nix run postgrest-nixpkgs-upgrade etc.