move devShell hook into seperate file
This commit is contained in:
parent
6cbc11c672
commit
0c617acc81
28
build/devShellHook.sh
Normal file
28
build/devShellHook.sh
Normal file
|
@ -0,0 +1,28 @@
|
|||
set -e
|
||||
|
||||
log() {
|
||||
printf '\e[1m\e[38;5;87m==>\e[0m\e[1m %s.\e[0m\n' "$*"
|
||||
}
|
||||
|
||||
log "Checking for existing postgres directory"
|
||||
[ -d ./matabas-db ] || {
|
||||
log "Non-existent, creating postgres directory (./matabas-db)"
|
||||
pg_ctl initdb --pgdata=./matabas-db
|
||||
}
|
||||
|
||||
[ -f matabas-db/matabas.log ] && {
|
||||
log "Moving logs from last session into log archive (./matabas-db/matabas.log.old)"
|
||||
cat matabas-db/matabas.log >> matabas-db/matabas.log.old
|
||||
rm -f matabas-db/matabas.log
|
||||
}
|
||||
|
||||
log "Starting postgres"
|
||||
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp"
|
||||
trap 'log "Stopping postgres" && pg_ctl stop --pgdata=./matabas-db' EXIT
|
||||
|
||||
log "Creating database"
|
||||
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Database already exists, not overwriting"
|
||||
|
||||
log "Environment ready!"
|
||||
|
||||
set +e
|
31
flake.nix
31
flake.nix
|
@ -17,36 +17,7 @@
|
|||
};
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = [ packages.default packages.postgres ];
|
||||
shellHook = ''
|
||||
set -e
|
||||
|
||||
log() {
|
||||
printf '\e[1m\e[38;5;87m==>\e[0m\e[1m %s.\e[0m\n' "$*"
|
||||
}
|
||||
|
||||
log "Checking for existing postgres directory"
|
||||
[ -d ./matabas-db ] || {
|
||||
log "Non-existent, creating postgres directory (./matabas-db)"
|
||||
pg_ctl initdb --pgdata=./matabas-db
|
||||
}
|
||||
|
||||
[ -f matabas-db/matabas.log ] && {
|
||||
log "Moving logs from last session into log archive (./matabas-db/matabas.log.old)"
|
||||
cat matabas-db/matabas.log >> matabas-db/matabas.log.old
|
||||
rm -f matabas-db/matabas.log
|
||||
}
|
||||
|
||||
log "Starting postgres"
|
||||
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp"
|
||||
trap 'log "Stopping postgres" && pg_ctl stop --pgdata=./matabas-db' EXIT
|
||||
|
||||
log "Creating database"
|
||||
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Database already exists, not overwriting"
|
||||
|
||||
log "Environment ready!"
|
||||
|
||||
set +e
|
||||
'';
|
||||
shellHook = builtins.readFile ./build/devShellHook.sh ;
|
||||
};
|
||||
}
|
||||
) // {
|
||||
|
|
Loading…
Reference in New Issue
Block a user