Setting up a local Postgres dev database on NixOS
Contents
I recently had to setup a local database for testing purposes. The last time I did that was on Mac OS. On that platform the awesome Postgres.app is available that sets up a dev database in seconds. (Seriously, if you are a developer on Mac you should check that out.)
On Linux — and in my case NixOS – the process is more involved unfortunately. You can't (as far as I know) just put something into your dev environment shell.nix
file and expect everything to work.
Here are my steps:
Install Postgres
You can do this userwide via nix-env -i postgresql
, but in my case I wanted it to only apply to one project so I put it in that project's shell.nix
.
|
|
Setup the database
Next you have to setup the database:
|
|
Conclusion
In the end that wasn't too hard, but having to look up cryptic errors like FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
only to find out that you have to do some local filesystem and setup shenanigans isn't the nix experience. I'd like to just go: "Hey nix, give my a postgres database please." And maybe that exists, but the Postgres on Nix documentation is sparse and I was not able to find a better way.
Author Ben Bals
LastMod 2019-07-23