From 5382e74a25799db24331cacbe02e6abb354f9ecd Mon Sep 17 00:00:00 2001 From: xenia Date: Tue, 8 Aug 2023 17:24:46 +0200 Subject: [PATCH] Postgres, initialize in mkShell --- flake.nix | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 73ca80f..36ef148 100644 --- a/flake.nix +++ b/flake.nix @@ -11,11 +11,25 @@ let pkgs = nixpkgs.legacyPackages.${system}; in rec { packages = rec { - hello = pkgs.hello; - default = hello; + postgres = pkgs.postgresql_15_jit; + + default = pkgs.hello; }; devShells.default = pkgs.mkShell { - packages = [ packages.default ]; + packages = [ packages.default packages.postgres ]; + shellHook = '' + set -e + [ -d ./matabas-db ] || pg_ctl initdb --pgdata=./matabas-db + mkdir -p ./matabas-db/socket + + [ -f matabas-db/matabas.log ] && mv -f matabas-db/matabas.log{,.old} + pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137" + trap 'pg_ctl stop --pgdata=./matabas-db' EXIT + + createdb -p 2137 matabas || : 3 + + set +e + ''; }; } ) // {